Add deprecated function and apply.

This commit is contained in:
Carlton Gibson 2015-09-15 11:04:51 +02:00
parent 8cae462b3a
commit 8ac78daf18
2 changed files with 24 additions and 10 deletions

View File

@ -6,12 +6,31 @@ versions of Django/Python, and compatibility wrappers around optional packages.
# flake8: noqa
from __future__ import unicode_literals
import warnings
import django
from django.conf import settings
from django.db import connection, transaction
from django.utils import six
from django.views.generic import View
from rest_framework import VERSION
def deprecated(since, message):
current_version = [int(i) for i in VERSION.split('.')]
assert current_version[0] == since[0], "Deprecated code must be removed before major version change. Current: {0} vs Deprecated Since: {1}".format(current_version[0], since[0])
minor_version_difference = current_version[1] - since[1]
assert minor_version_difference in [1,2], "Deprecated code must be removed within two minor versions"
warning_type = PendingDeprecationWarning if minor_version_difference == 1 else DeprecationWarning
warnings.warn(message, warning_type)
try:
import importlib # Available in Python 3.1+
except ImportError:

View File

@ -5,7 +5,6 @@ be used for paginated responses.
"""
from __future__ import unicode_literals
import warnings
from base64 import b64decode, b64encode
from collections import namedtuple
@ -16,7 +15,7 @@ from django.utils import six
from django.utils.six.moves.urllib import parse as urlparse
from django.utils.translation import ugettext_lazy as _
from rest_framework.compat import OrderedDict
from rest_framework.compat import OrderedDict, deprecated
from rest_framework.exceptions import NotFound
from rest_framework.response import Response
from rest_framework.settings import api_settings
@ -216,12 +215,10 @@ class PageNumberPagination(BasePagination):
value = getattr(api_settings, settings_key, None)
if value is not None:
setattr(self, attr_name, value)
warnings.warn(
"The `%s` settings key is deprecated. "
deprecated((3,0,0), "The `%s` settings key is deprecated. "
"Use the `%s` attribute on the pagination class instead." % (
settings_key, attr_name
),
DeprecationWarning,
)
)
for (view_attr, attr_name) in (
@ -233,12 +230,10 @@ class PageNumberPagination(BasePagination):
value = getattr(view, view_attr, None)
if value is not None:
setattr(self, attr_name, value)
warnings.warn(
"The `%s` view attribute is deprecated. "
deprecated((3,0,0), "The `%s` view attribute is deprecated. "
"Use the `%s` attribute on the pagination class instead." % (
view_attr, attr_name
),
DeprecationWarning,
)
)
def paginate_queryset(self, queryset, request, view=None):