diff options
| author | Tymur Maryokhin | 2014-12-05 00:29:28 +0100 | 
|---|---|---|
| committer | Tymur Maryokhin | 2014-12-05 00:29:28 +0100 | 
| commit | d9930181ee157f51e2fcea33a3af5ea397647324 (patch) | |
| tree | 06e65d1f2a34b70c912dfa3e696611ca0cc00a65 /rest_framework | |
| parent | 45dc44b2038f5533a472b015c45200b5d1ca6052 (diff) | |
| download | django-rest-framework-d9930181ee157f51e2fcea33a3af5ea397647324.tar.bz2 | |
Removed unused imports, pep8 fixes, typo fixes
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/authentication.py | 2 | ||||
| -rw-r--r-- | rest_framework/permissions.py | 2 | ||||
| -rw-r--r-- | rest_framework/relations.py | 2 | ||||
| -rw-r--r-- | rest_framework/renderers.py | 4 | ||||
| -rw-r--r-- | rest_framework/serializers.py | 33 | ||||
| -rw-r--r-- | rest_framework/settings.py | 2 | ||||
| -rw-r--r-- | rest_framework/validators.py | 2 | ||||
| -rw-r--r-- | rest_framework/viewsets.py | 6 | 
8 files changed, 26 insertions, 27 deletions
| diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 36d74dd9..4832ad33 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -267,7 +267,7 @@ class OAuthAuthentication(BaseAuthentication):      def authenticate_header(self, request):          """          If permission is denied, return a '401 Unauthorized' response, -        with an appropraite 'WWW-Authenticate' header. +        with an appropriate 'WWW-Authenticate' header.          """          return 'OAuth realm="%s"' % self.www_authenticate_realm diff --git a/rest_framework/permissions.py b/rest_framework/permissions.py index 29f60d6d..3f6f5961 100644 --- a/rest_framework/permissions.py +++ b/rest_framework/permissions.py @@ -184,7 +184,7 @@ class DjangoObjectPermissions(DjangoModelPermissions):          if not user.has_perms(perms, obj):              # If the user does not have permissions we need to determine if              # they have read permissions to see 403, or not, and simply see -            # a 404 reponse. +            # a 404 response.              if request.method in ('GET', 'OPTIONS', 'HEAD'):                  # Read permissions already checked and failed, no need diff --git a/rest_framework/relations.py b/rest_framework/relations.py index d0cd3154..178a8e2b 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -142,7 +142,7 @@ class PrimaryKeyRelatedField(RelatedField):      def get_iterable(self, instance, source_attrs):          # For consistency with `get_attribute` we're using `serializable_value()`          # here. Typically there won't be any difference, but some custom field -        # types might return a non-primative value for the pk otherwise. +        # types might return a non-primitive value for the pk otherwise.          #          # We could try to get smart with `values_list('pk', flat=True)`, which          # would be better in some case, but would actually end up with *more* diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 4ffd46e3..46126d91 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -282,7 +282,9 @@ class TemplateHTMLRenderer(BaseRenderer):              return view.get_template_names()          elif hasattr(view, 'template_name'):              return [view.template_name] -        raise ImproperlyConfigured('Returned a template response with no `template_name` attribute set on either the view or response') +        raise ImproperlyConfigured( +            'Returned a template response with no `template_name` attribute set on either the view or response' +        )      def get_exception_template(self, response):          template_names = [name % {'status_code': response.status_code} diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index af8aeb48..e1851ddd 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -10,17 +10,13 @@ python primitives.  2. The process of marshalling between python primitives and request and  response content is handled by parsers and renderers.  """ -from django.core.exceptions import ImproperlyConfigured -from django.core.exceptions import ValidationError as DjangoValidationError +import warnings +  from django.db import models  from django.db.models.fields import FieldDoesNotExist -from django.utils import six  from django.utils.translation import ugettext_lazy as _ -from rest_framework.compat import OrderedDict -from rest_framework.exceptions import ValidationError -from rest_framework.fields import empty, set_value, Field, SkipField -from rest_framework.settings import api_settings -from rest_framework.utils import html, model_meta, representation + +from rest_framework.utils import model_meta  from rest_framework.utils.field_mapping import (      get_url_kwargs, get_field_kwargs,      get_relation_kwargs, get_nested_relation_kwargs, @@ -33,9 +29,7 @@ from rest_framework.validators import (      UniqueForDateValidator, UniqueForMonthValidator, UniqueForYearValidator,      UniqueTogetherValidator  ) -import copy -import inspect -import warnings +  # Note: We do the following so that users of the framework can use this style:  # @@ -65,6 +59,7 @@ class BaseSerializer(Field):      The BaseSerializer class provides a minimal class which may be used      for writing custom serializer implementations.      """ +      def __init__(self, instance=None, data=None, **kwargs):          self.instance = instance          self._initial_data = data @@ -245,7 +240,7 @@ class Serializer(BaseSerializer):          """          A dictionary of {field_name: field_instance}.          """ -        # `fields` is evalutated lazily. We do this to ensure that we don't +        # `fields` is evaluated lazily. We do this to ensure that we don't          # have issues importing modules that use ModelSerializers as fields,          # even if Django's app-loading stage has not yet run.          if not hasattr(self, '_fields'): @@ -343,7 +338,7 @@ class Serializer(BaseSerializer):              # Normally you should raise `serializers.ValidationError`              # inside your codebase, but we handle Django's validation              # exception class as well for simpler compat. -            # Eg. Calling Model.clean() explictily inside Serializer.validate() +            # Eg. Calling Model.clean() explicitly inside Serializer.validate()              raise ValidationError({                  api_settings.NON_FIELD_ERRORS_KEY: list(exc.messages)              }) @@ -576,7 +571,7 @@ class ModelSerializer(Serializer):      The process of automatically determining a set of serializer fields      based on the model fields is reasonably complex, but you almost certainly -    don't need to dig into the implemention. +    don't need to dig into the implementation.      If the `ModelSerializer` class *doesn't* generate the set of fields that      you need you should either declare the extra/differing fields explicitly on @@ -636,7 +631,7 @@ class ModelSerializer(Serializer):              isinstance(field, BaseSerializer) and (key in validated_attrs)              for key, field in self.fields.items()          ), ( -            'The `.create()` method does not suport nested writable fields ' +            'The `.create()` method does not support nested writable fields '              'by default. Write an explicit `.create()` method for serializer '              '`%s.%s`, or set `read_only=True` on nested serializer fields.' %              (self.__class__.__module__, self.__class__.__name__) @@ -684,7 +679,7 @@ class ModelSerializer(Serializer):              isinstance(field, BaseSerializer) and (key in validated_attrs)              for key, field in self.fields.items()          ), ( -            'The `.update()` method does not suport nested writable fields ' +            'The `.update()` method does not support nested writable fields '              'by default. Write an explicit `.update()` method for serializer '              '`%s.%s`, or set `read_only=True` on nested serializer fields.' %              (self.__class__.__module__, self.__class__.__name__) @@ -824,7 +819,7 @@ class ModelSerializer(Serializer):          # applied, we can add the extra 'required=...' or 'default=...'          # arguments that are appropriate to these fields, or add a `HiddenField` for it.          for unique_constraint_name in unique_constraint_names: -            # Get the model field that is refered too. +            # Get the model field that is referred too.              unique_constraint_field = model._meta.get_field(unique_constraint_name)              if getattr(unique_constraint_field, 'auto_now_add', None): @@ -907,7 +902,7 @@ class ModelSerializer(Serializer):                  )              # Check that any fields declared on the class are -            # also explicity included in `Meta.fields`. +            # also explicitly included in `Meta.fields`.              missing_fields = set(declared_fields.keys()) - set(fields)              if missing_fields:                  missing_field = list(missing_fields)[0] @@ -1001,6 +996,7 @@ class ModelSerializer(Serializer):              class Meta:                  model = relation_info.related                  depth = nested_depth +          return NestedSerializer @@ -1027,4 +1023,5 @@ class HyperlinkedModelSerializer(ModelSerializer):              class Meta:                  model = relation_info.related                  depth = nested_depth +          return NestedSerializer diff --git a/rest_framework/settings.py b/rest_framework/settings.py index 1e8c27fc..79da23ca 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -47,7 +47,7 @@ DEFAULTS = {      'DEFAULT_CONTENT_NEGOTIATION_CLASS': 'rest_framework.negotiation.DefaultContentNegotiation',      'DEFAULT_METADATA_CLASS': 'rest_framework.metadata.SimpleMetadata', -    # Genric view behavior +    # Generic view behavior      'DEFAULT_MODEL_SERIALIZER_CLASS': 'rest_framework.serializers.ModelSerializer',      'DEFAULT_PAGINATION_SERIALIZER_CLASS': 'rest_framework.pagination.PaginationSerializer',      'DEFAULT_FILTER_BACKENDS': (), diff --git a/rest_framework/validators.py b/rest_framework/validators.py index 7ca4e6a9..63eb7b22 100644 --- a/rest_framework/validators.py +++ b/rest_framework/validators.py @@ -4,7 +4,7 @@ the using Django's `.full_clean()`.  This gives us better separation of concerns, allows us to use single-step  object creation, and makes it possible to switch between using the implicit -`ModelSerializer` class and an equivelent explicit `Serializer` class. +`ModelSerializer` class and an equivalent explicit `Serializer` class.  """  from django.utils.translation import ugettext_lazy as _  from rest_framework.exceptions import ValidationError diff --git a/rest_framework/viewsets.py b/rest_framework/viewsets.py index 70d14695..88c763da 100644 --- a/rest_framework/viewsets.py +++ b/rest_framework/viewsets.py @@ -44,7 +44,7 @@ class ViewSetMixin(object):          instantiated view, we need to totally reimplement `.as_view`,          and slightly modify the view function that is created and returned.          """ -        # The suffix initkwarg is reserved for identifing the viewset type +        # The suffix initkwarg is reserved for identifying the viewset type          # eg. 'List' or 'Instance'.          cls.suffix = None @@ -98,12 +98,12 @@ class ViewSetMixin(object):          view.suffix = initkwargs.get('suffix', None)          return csrf_exempt(view) -    def initialize_request(self, request, *args, **kargs): +    def initialize_request(self, request, *args, **kwargs):          """          Set the `.action` attribute on the view,          depending on the request method.          """ -        request = super(ViewSetMixin, self).initialize_request(request, *args, **kargs) +        request = super(ViewSetMixin, self).initialize_request(request, *args, **kwargs)          self.action = self.action_map.get(request.method.lower())          return request | 
