diff options
| -rw-r--r-- | .travis.yml | 6 | ||||
| -rw-r--r-- | docs/topics/release-notes.md | 6 | ||||
| -rw-r--r-- | rest_framework/__init__.py | 2 | ||||
| -rw-r--r-- | rest_framework/authentication.py | 2 | ||||
| -rw-r--r-- | rest_framework/pagination.py | 9 | ||||
| -rw-r--r-- | rest_framework/views.py | 10 | ||||
| -rw-r--r-- | tests/test_pagination.py | 19 | ||||
| -rw-r--r-- | tox.ini | 8 |
8 files changed, 46 insertions, 16 deletions
diff --git a/.travis.yml b/.travis.yml index ececf3e9..e768e146 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ python: - "3.4" env: - - DJANGO="https://www.djangoproject.com/download/1.7c2/tarball/" + - DJANGO="django==1.7" - DJANGO="django==1.6.5" - DJANGO="django==1.5.8" - DJANGO="django==1.4.13" @@ -25,7 +25,7 @@ install: - "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install django-oauth2-provider==0.2.4; fi" - "if [[ ${DJANGO::11} == 'django==1.3' ]]; then pip install django-filter==0.5.4; fi" - "if [[ ${DJANGO::11} != 'django==1.3' ]]; then pip install django-filter==0.7; fi" - - "if [[ ${DJANGO} == 'https://www.djangoproject.com/download/1.7c2/tarball/' ]]; then pip install -e git+https://github.com/linovia/django-guardian.git@feature/django_1_7#egg=django-guardian-1.2.0; fi" + - "if [[ ${DJANGO} == 'django==1.7' ]]; then pip install -e git+https://github.com/linovia/django-guardian.git@feature/django_1_7#egg=django-guardian-1.2.0; fi" - export PYTHONPATH=. script: @@ -34,7 +34,7 @@ script: matrix: exclude: - python: "2.6" - env: DJANGO="https://www.djangoproject.com/download/1.7c2/tarball/" + env: DJANGO="django==1.7" - python: "3.2" env: DJANGO="django==1.4.13" - python: "3.3" diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md index f0e9f210..d758ae6a 100644 --- a/docs/topics/release-notes.md +++ b/docs/topics/release-notes.md @@ -40,6 +40,12 @@ You can determine your currently installed version using `pip freeze`: ## 2.4.x series +### 2.4.2 + +**Date**: 3rd September 2014 + +* Bugfix: Fix broken pagination for 2.4.x series. + ### 2.4.1 **Date**: 1st September 2014 diff --git a/rest_framework/__init__.py b/rest_framework/__init__.py index 7c187639..8d82a4b9 100644 --- a/rest_framework/__init__.py +++ b/rest_framework/__init__.py @@ -8,7 +8,7 @@ ______ _____ _____ _____ __ """ __title__ = 'Django REST framework' -__version__ = '2.4.1' +__version__ = '2.4.2' __author__ = 'Tom Christie' __license__ = 'BSD 2-Clause' __copyright__ = 'Copyright 2011-2014 Tom Christie' diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 5721a869..f3fec05e 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -344,7 +344,7 @@ class OAuth2Authentication(BaseAuthentication): user = token.user if not user.is_active: - msg = 'User inactive or deleted: %s' % user.username + msg = 'User inactive or deleted: %s' % user.get_username() raise exceptions.AuthenticationFailed(msg) return (user, token) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index d51ea929..1f5749f1 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -43,8 +43,9 @@ class DefaultObjectSerializer(serializers.Field): as the default. """ - def __init__(self, source=None, context=None): - # Note: Swallow context kwarg - only required for eg. ModelSerializer. + def __init__(self, source=None, many=None, context=None): + # Note: Swallow context and many kwargs - only required for + # eg. ModelSerializer. super(DefaultObjectSerializer, self).__init__(source=source) @@ -82,7 +83,9 @@ class BasePaginationSerializer(serializers.Serializer): else: context_kwarg = {} - self.fields[results_field] = object_serializer(source='object_list', **context_kwarg) + self.fields[results_field] = object_serializer(source='object_list', + many=True, + **context_kwarg) class PaginationSerializer(BasePaginationSerializer): diff --git a/rest_framework/views.py b/rest_framework/views.py index 23df3443..38346ab7 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -103,7 +103,9 @@ class APIView(View): """ view = super(APIView, cls).as_view(**initkwargs) view.cls = cls - return view + # Note: session based authentication is explicitly CSRF validated, + # all other authentication is CSRF exempt. + return csrf_exempt(view) @property def allowed_methods(self): @@ -371,9 +373,9 @@ class APIView(View): response.exception = True return response - # Note: session based authentication is explicitly CSRF validated, - # all other authentication is CSRF exempt. - @csrf_exempt + # Note: Views are made CSRF exempt from within `as_view` as to prevent + # accidental removal of this exemption in cases where `dispatch` needs to + # be overridden. def dispatch(self, request, *args, **kwargs): """ `.dispatch()` is pretty much the same as Django's regular dispatch, diff --git a/tests/test_pagination.py b/tests/test_pagination.py index 80c33e2e..e1c2528b 100644 --- a/tests/test_pagination.py +++ b/tests/test_pagination.py @@ -412,6 +412,15 @@ class CustomPaginationSerializer(pagination.BasePaginationSerializer): results_field = 'objects' +class CustomFooSerializer(serializers.Serializer): + foo = serializers.CharField() + + +class CustomFooPaginationSerializer(pagination.PaginationSerializer): + class Meta: + object_serializer_class = CustomFooSerializer + + class TestCustomPaginationSerializer(TestCase): def setUp(self): objects = ['john', 'paul', 'george', 'ringo'] @@ -434,6 +443,16 @@ class TestCustomPaginationSerializer(TestCase): } self.assertEqual(serializer.data, expected) + def test_custom_pagination_serializer_with_custom_object_serializer(self): + objects = [ + {'foo': 'bar'}, + {'foo': 'spam'} + ] + paginator = Paginator(objects, 1) + page = paginator.page(1) + serializer = CustomFooPaginationSerializer(page) + serializer.data + class NonIntegerPage(object): @@ -18,7 +18,7 @@ commands = ./runtests.py --lintonly [testenv:py3.4-django1.7] basepython = python3.4 -deps = https://www.djangoproject.com/download/1.7c2/tarball/ +deps = Django==1.7 django-filter==0.7 defusedxml==0.3 Pillow==2.3.0 @@ -26,7 +26,7 @@ deps = https://www.djangoproject.com/download/1.7c2/tarball/ [testenv:py3.3-django1.7] basepython = python3.3 -deps = https://www.djangoproject.com/download/1.7c2/tarball/ +deps = Django==1.7 django-filter==0.7 defusedxml==0.3 Pillow==2.3.0 @@ -34,7 +34,7 @@ deps = https://www.djangoproject.com/download/1.7c2/tarball/ [testenv:py3.2-django1.7] basepython = python3.2 -deps = https://www.djangoproject.com/download/1.7c2/tarball/ +deps = Django==1.7 django-filter==0.7 defusedxml==0.3 Pillow==2.3.0 @@ -42,7 +42,7 @@ deps = https://www.djangoproject.com/download/1.7c2/tarball/ [testenv:py2.7-django1.7] basepython = python2.7 -deps = https://www.djangoproject.com/download/1.7c2/tarball/ +deps = Django==1.7 django-filter==0.7 defusedxml==0.3 # django-oauth-plus==2.2.1 |
