Remove deprecated code

This commit is contained in:
Tom Christie 2013-06-27 20:29:52 +01:00
parent 1f6a59d76d
commit 3fcc01273c
6 changed files with 21 additions and 108 deletions

View File

@ -494,11 +494,14 @@ try:
if provider_version in ('0.2.3', '0.2.4'): if provider_version in ('0.2.3', '0.2.4'):
# 0.2.3 and 0.2.4 are supported version that do not support # 0.2.3 and 0.2.4 are supported version that do not support
# timezone aware datetimes # timezone aware datetimes
from datetime.datetime import now as provider_now import datetime
provider_now = datetime.datetime.now
else: else:
# Any other supported version does use timezone aware datetimes # Any other supported version does use timezone aware datetimes
from django.utils.timezone import now as provider_now from django.utils.timezone import now as provider_now
except ImportError: except ImportError:
import traceback
traceback.print_exc()
oauth2_provider = None oauth2_provider = None
oauth2_provider_models = None oauth2_provider_models = None
oauth2_provider_forms = None oauth2_provider_forms = None

View File

@ -224,13 +224,6 @@ class WritableField(Field):
validators=[], error_messages=None, widget=None, validators=[], error_messages=None, widget=None,
default=None, blank=None): default=None, blank=None):
# 'blank' is to be deprecated in favor of 'required'
if blank is not None:
warnings.warn('The `blank` keyword argument is deprecated. '
'Use the `required` keyword argument instead.',
DeprecationWarning, stacklevel=2)
required = not(blank)
super(WritableField, self).__init__(source=source, label=label, help_text=help_text) super(WritableField, self).__init__(source=source, label=label, help_text=help_text)
self.read_only = read_only self.read_only = read_only

View File

@ -2,13 +2,10 @@
Provides a set of pluggable permission policies. Provides a set of pluggable permission policies.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import inspect from rest_framework.compat import oauth2_provider_scope, oauth2_constants
import warnings
SAFE_METHODS = ['GET', 'HEAD', 'OPTIONS'] SAFE_METHODS = ['GET', 'HEAD', 'OPTIONS']
from rest_framework.compat import oauth2_provider_scope, oauth2_constants
class BasePermission(object): class BasePermission(object):
""" """
@ -25,13 +22,6 @@ class BasePermission(object):
""" """
Return `True` if permission is granted, `False` otherwise. Return `True` if permission is granted, `False` otherwise.
""" """
if len(inspect.getargspec(self.has_permission).args) == 4:
warnings.warn(
'The `obj` argument in `has_permission` is deprecated. '
'Use `has_object_permission()` instead for object permissions.',
DeprecationWarning, stacklevel=2
)
return self.has_permission(request, view, obj)
return True return True

View File

@ -40,14 +40,6 @@ class RelatedField(WritableField):
many = False many = False
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# 'null' is to be deprecated in favor of 'required'
if 'null' in kwargs:
warnings.warn('The `null` keyword argument is deprecated. '
'Use the `required` keyword argument instead.',
DeprecationWarning, stacklevel=2)
kwargs['required'] = not kwargs.pop('null')
queryset = kwargs.pop('queryset', None) queryset = kwargs.pop('queryset', None)
self.many = kwargs.pop('many', self.many) self.many = kwargs.pop('many', self.many)
if self.many: if self.many:
@ -424,14 +416,11 @@ class HyperlinkedRelatedField(RelatedField):
request = self.context.get('request', None) request = self.context.get('request', None)
format = self.format or self.context.get('format', None) format = self.format or self.context.get('format', None)
if request is None: assert request is not None, (
msg = ( "`HyperlinkedRelatedField` requires the request in the serializer "
"Using `HyperlinkedRelatedField` without including the request " "context. Add `context={'request': request}` when instantiating "
"in the serializer context is deprecated. " "the serializer."
"Add `context={'request': request}` when instantiating " )
"the serializer."
)
warnings.warn(msg, DeprecationWarning, stacklevel=4)
# If the object has not yet been saved then we cannot hyperlink to it. # If the object has not yet been saved then we cannot hyperlink to it.
if getattr(obj, 'pk', None) is None: if getattr(obj, 'pk', None) is None:
@ -530,11 +519,11 @@ class HyperlinkedIdentityField(Field):
format = self.context.get('format', None) format = self.context.get('format', None)
view_name = self.view_name view_name = self.view_name
if request is None: assert request is not None, (
warnings.warn("Using `HyperlinkedIdentityField` without including the " "`HyperlinkedIdentityField` requires the request in the serializer"
"request in the serializer context is deprecated. " " context. Add `context={'request': request}` when instantiating "
"Add `context={'request': request}` when instantiating the serializer.", "the serializer."
DeprecationWarning, stacklevel=4) )
# By default use whatever format is given for the current context # By default use whatever format is given for the current context
# unless the target is a different type to the source. # unless the target is a different type to the source.
@ -593,41 +582,3 @@ class HyperlinkedIdentityField(Field):
pass pass
raise NoReverseMatch() raise NoReverseMatch()
### Old-style many classes for backwards compat
class ManyRelatedField(RelatedField):
def __init__(self, *args, **kwargs):
warnings.warn('`ManyRelatedField()` is deprecated. '
'Use `RelatedField(many=True)` instead.',
DeprecationWarning, stacklevel=2)
kwargs['many'] = True
super(ManyRelatedField, self).__init__(*args, **kwargs)
class ManyPrimaryKeyRelatedField(PrimaryKeyRelatedField):
def __init__(self, *args, **kwargs):
warnings.warn('`ManyPrimaryKeyRelatedField()` is deprecated. '
'Use `PrimaryKeyRelatedField(many=True)` instead.',
DeprecationWarning, stacklevel=2)
kwargs['many'] = True
super(ManyPrimaryKeyRelatedField, self).__init__(*args, **kwargs)
class ManySlugRelatedField(SlugRelatedField):
def __init__(self, *args, **kwargs):
warnings.warn('`ManySlugRelatedField()` is deprecated. '
'Use `SlugRelatedField(many=True)` instead.',
DeprecationWarning, stacklevel=2)
kwargs['many'] = True
super(ManySlugRelatedField, self).__init__(*args, **kwargs)
class ManyHyperlinkedRelatedField(HyperlinkedRelatedField):
def __init__(self, *args, **kwargs):
warnings.warn('`ManyHyperlinkedRelatedField()` is deprecated. '
'Use `HyperlinkedRelatedField(many=True)` instead.',
DeprecationWarning, stacklevel=2)
kwargs['many'] = True
super(ManyHyperlinkedRelatedField, self).__init__(*args, **kwargs)

View File

@ -15,7 +15,6 @@ import copy
import datetime import datetime
import types import types
from decimal import Decimal from decimal import Decimal
from django.core.paginator import Page
from django.db import models from django.db import models
from django.forms import widgets from django.forms import widgets
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
@ -141,7 +140,7 @@ class BaseSerializer(WritableField):
_dict_class = SortedDictWithMetadata _dict_class = SortedDictWithMetadata
def __init__(self, instance=None, data=None, files=None, def __init__(self, instance=None, data=None, files=None,
context=None, partial=False, many=None, context=None, partial=False, many=False,
allow_add_remove=False, **kwargs): allow_add_remove=False, **kwargs):
super(BaseSerializer, self).__init__(**kwargs) super(BaseSerializer, self).__init__(**kwargs)
self.opts = self._options_class(self.Meta) self.opts = self._options_class(self.Meta)
@ -348,12 +347,7 @@ class BaseSerializer(WritableField):
if value is None: if value is None:
return None return None
if self.many is not None: if self.many:
many = self.many
else:
many = hasattr(value, '__iter__') and not isinstance(value, (Page, dict, six.text_type))
if many:
return [self.to_native(item) for item in value] return [self.to_native(item) for item in value]
return self.to_native(value) return self.to_native(value)
@ -424,16 +418,7 @@ class BaseSerializer(WritableField):
if self._errors is None: if self._errors is None:
data, files = self.init_data, self.init_files data, files = self.init_data, self.init_files
if self.many is not None: if self.many:
many = self.many
else:
many = hasattr(data, '__iter__') and not isinstance(data, (Page, dict, six.text_type))
if many:
warnings.warn('Implict list/queryset serialization is deprecated. '
'Use the `many=True` flag when instantiating the serializer.',
DeprecationWarning, stacklevel=3)
if many:
ret = [] ret = []
errors = [] errors = []
update = self.object is not None update = self.object is not None
@ -486,16 +471,7 @@ class BaseSerializer(WritableField):
if self._data is None: if self._data is None:
obj = self.object obj = self.object
if self.many is not None: if self.many:
many = self.many
else:
many = hasattr(obj, '__iter__') and not isinstance(obj, (Page, dict))
if many:
warnings.warn('Implict list/queryset serialization is deprecated. '
'Use the `many=True` flag when instantiating the serializer.',
DeprecationWarning, stacklevel=2)
if many:
self._data = [self.to_native(item) for item in obj] self._data = [self.to_native(item) for item in obj]
else: else:
self._data = self.to_native(obj) self._data = self.to_native(obj)

View File

@ -1268,7 +1268,7 @@ class NestedSerializerContextTests(TestCase):
model = Album model = Album
fields = ("photo_set", "callable") fields = ("photo_set", "callable")
photo_set = PhotoSerializer(source="photo_set") photo_set = PhotoSerializer(source="photo_set", many=True)
callable = serializers.SerializerMethodField("_callable") callable = serializers.SerializerMethodField("_callable")
def _callable(self, instance): def _callable(self, instance):
@ -1280,7 +1280,7 @@ class NestedSerializerContextTests(TestCase):
albums = None albums = None
class AlbumCollectionSerializer(serializers.Serializer): class AlbumCollectionSerializer(serializers.Serializer):
albums = AlbumSerializer(source="albums") albums = AlbumSerializer(source="albums", many=True)
album1 = Album.objects.create(title="album 1") album1 = Album.objects.create(title="album 1")
album2 = Album.objects.create(title="album 2") album2 = Album.objects.create(title="album 2")