Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Removed unused imports, pep8 fixes, typo fixes
  • Loading branch information
maryokhin committed Dec 4, 2014
commit d9930181ee157f51e2fcea33a3af5ea397647324
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Some tips on good issue reporting:
* When describing issues try to phrase your ticket in terms of the *behavior* you think needs changing rather than the *code* you think need changing.
* Search the issue list first for related items, and make sure you're running the latest version of REST framework before reporting an issue.
* If reporting a bug, then try to include a pull request with a failing test case. This will help us quickly identify if there is a valid issue, and make sure that it gets fixed more quickly if there is one.
* Feature requests will often be closed with a recommendation that they be implemented outside of the core REST framework library. Keeping new feature requests implemented as third party libraries allows us to keep down the maintainence overhead of REST framework, so that the focus can be on continued stability, bugfixes, and great documentation.
* Feature requests will often be closed with a recommendation that they be implemented outside of the core REST framework library. Keeping new feature requests implemented as third party libraries allows us to keep down the maintenance overhead of REST framework, so that the focus can be on continued stability, bugfixes, and great documentation.
* Closing an issue doesn't necessarily mean the end of a discussion. If you believe your issue has been closed incorrectly, explain why and we'll consider if it needs to be reopened.

## Triaging issues
Expand Down Expand Up @@ -82,7 +82,7 @@ GitHub's documentation for working on pull requests is [available here][pull-req

Always run the tests before submitting pull requests, and ideally run `tox` in order to check that your modifications are compatible with both Python 2 and Python 3, and that they run properly on all supported versions of Django.

Once you've made a pull request take a look at the travis build status in the GitHub interface and make sure the tests are runnning as you'd expect.
Once you've made a pull request take a look at the travis build status in the GitHub interface and make sure the tests are running as you'd expect.

![Travis status][travis-status]

Expand Down
2 changes: 1 addition & 1 deletion rest_framework/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def authenticate(self, request):
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

Expand Down
2 changes: 1 addition & 1 deletion rest_framework/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def has_object_permission(self, request, view, obj):
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
Expand Down
2 changes: 1 addition & 1 deletion rest_framework/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_attribute(self, instance):
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*
Expand Down
4 changes: 3 additions & 1 deletion rest_framework/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ def get_template_names(self, response, view):
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}
Expand Down
33 changes: 15 additions & 18 deletions rest_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
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,
Expand All @@ -33,9 +29,7 @@
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:
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -245,7 +240,7 @@ def fields(self):
"""
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'):
Expand Down Expand Up @@ -343,7 +338,7 @@ def run_validation(self, data=empty):
# 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)
})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -636,7 +631,7 @@ def create(self, validated_data):
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__)
Expand Down Expand Up @@ -684,7 +679,7 @@ def update(self, instance, validated_data):
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__)
Expand Down Expand Up @@ -824,7 +819,7 @@ def get_fields(self):
# 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):
Expand Down Expand Up @@ -907,7 +902,7 @@ def get_fields(self):
)

# 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]
Expand Down Expand Up @@ -1001,6 +996,7 @@ class NestedSerializer(ModelSerializer):
class Meta:
model = relation_info.related
depth = nested_depth

return NestedSerializer


Expand All @@ -1027,4 +1023,5 @@ class NestedSerializer(HyperlinkedModelSerializer):
class Meta:
model = relation_info.related
depth = nested_depth

return NestedSerializer
2 changes: 1 addition & 1 deletion rest_framework/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
'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': (),
Expand Down
2 changes: 1 addition & 1 deletion rest_framework/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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
Expand Down
6 changes: 3 additions & 3 deletions rest_framework/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def as_view(cls, actions=None, **initkwargs):
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

Expand Down Expand Up @@ -98,12 +98,12 @@ def view(request, *args, **kwargs):
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

Expand Down
5 changes: 5 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@

sys.path.append(os.path.dirname(__file__))


def exit_on_failure(ret, message=None):
if ret:
sys.exit(ret)


def flake8_main(args):
print('Running flake8 code linting')
ret = subprocess.call(['flake8'] + args)
print('flake8 failed' if ret else 'flake8 passed')
return ret


def split_class_and_function(string):
class_string, function_string = string.split('.', 1)
return "%s and %s" % (class_string, function_string)


def is_function(string):
# `True` if it looks like a test function is included in the string.
return string.startswith('test_') or '.test_' in string


def is_class(string):
# `True` if first character is uppercase - assume it's a class name.
return string[0] == string[0].upper()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multitable_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Meta:


# Tests
class IneritedModelSerializationTests(TestCase):
class InheritedModelSerializationTests(TestCase):

def test_multitable_inherited_model_fields_as_expected(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def post(self, request):
if request.POST.get('example') is not None:
return Response(status=status.HTTP_200_OK)

return Response(status=status.INTERNAL_SERVER_ERROR)
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)

urlpatterns = patterns(
'',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_unique_together_is_required(self):
def test_ignore_excluded_fields(self):
"""
When model fields are not included in a serializer, then uniqueness
validtors should not be added for that field.
validators should not be added for that field.
"""
class ExcludedFieldSerializer(serializers.ModelSerializer):
class Meta:
Expand Down