Skip to content

Commit 88609ba

Browse files
committed
Merge branch 'master' of github.com:tomchristie/django-rest-framework
2 parents 19c1976 + 981265f commit 88609ba

File tree

10 files changed

+38
-63
lines changed

10 files changed

+38
-63
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Full documentation for the project is available at [http://www.django-rest-frame
1010

1111
---
1212

13-
**Note**: We have now released Django REST framework 3.1. For older codebases you may want to refer to the version 2.4.4 [source code](https://github.com/tomchristie/django-rest-framework/tree/version-2.4.x), and [documentation](http://tomchristie.github.io/rest-framework-2-docs/).
13+
**Note**: We have now released Django REST framework 3.2. For older codebases you may want to refer to the version 2.4.4 [source code][2.4-code], and [documentation][2.4-docs].
1414

15-
For more details see the [3.1 release notes][3.1-announcement]
15+
For more details see the 3.2 [announcement][3.2-announcement] and [release notes][3.2-release-notes].
1616

1717
---
1818

@@ -182,4 +182,7 @@ Send a description of the issue via email to [rest-framework-security@googlegrou
182182

183183
[docs]: http://www.django-rest-framework.org/
184184
[security-mail]: mailto:[email protected]
185-
[3.1-announcement]: http://www.django-rest-framework.org/topics/3.1-announcement/
185+
[2.4-code]: https://github.com/tomchristie/django-rest-framework/tree/version-2.4.x
186+
[2.4-docs]: http://tomchristie.github.io/rest-framework-2-docs/
187+
[3.2-announcement]: http://www.django-rest-framework.org/topics/3.2-announcement/
188+
[3.2-release-notes]: http://www.django-rest-framework.org/topics/release-notes/#32x-series

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
---
1414

15-
**Note**: This is the documentation for the **version 3.1** of REST framework. Documentation for [version 2.4](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
15+
**Note**: This is the documentation for the **version 3.2** of REST framework. Documentation for [version 2.4](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
1616

17-
For more details see the [3.1 release notes][3.1-announcement].
17+
For more details see the 3.2 [announcement][3.2-announcement] and [release notes][release-notes].
1818

1919
---
2020

docs/topics/3.2-announcement.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ The upshot is this: If you have many to many fields in your models, then make su
7474

7575
### List fields and allow_null
7676

77-
When using `allow_null` with `ListField` or a nested `mant=True` serializer the previous behavior was to allow `null` values as items in the list. The behavior is now to allow `null` values instead of the list.
77+
When using `allow_null` with `ListField` or a nested `many=True` serializer the previous behavior was to allow `null` values as items in the list. The behavior is now to allow `null` values instead of the list.
7878

7979
For example, take the following field:
8080

rest_framework/authentication.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
import base64
77

8-
from django.contrib.auth import authenticate
8+
from django.contrib.auth import authenticate, get_user_model
99
from django.middleware.csrf import CsrfViewMiddleware
1010
from django.utils.translation import ugettext_lazy as _
1111

1212
from rest_framework import HTTP_HEADER_ENCODING, exceptions
1313
from rest_framework.authtoken.models import Token
14-
from rest_framework.compat import get_user_model
1514

1615

1716
def get_authorization_header(request):
@@ -89,9 +88,8 @@ def authenticate_credentials(self, userid, password):
8988
"""
9089
Authenticate the userid and password against username and password.
9190
"""
92-
username_field = getattr(get_user_model(), 'USERNAME_FIELD', 'username')
9391
credentials = {
94-
username_field: userid,
92+
get_user_model().USERNAME_FIELD: userid,
9593
'password': password
9694
}
9795
user = authenticate(**credentials)

rest_framework/compat.py

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
"""
22
The `compat` module provides support for backwards compatibility with older
3-
versions of django/python, and compatibility wrappers around optional packages.
3+
versions of Django/Python, and compatibility wrappers around optional packages.
44
"""
55

66
# flake8: noqa
77
from __future__ import unicode_literals
88

9-
import inspect
10-
119
import django
1210
from django.conf import settings
13-
from django.core.exceptions import ImproperlyConfigured
1411
from django.db import connection, transaction
15-
from django.forms import FilePathField as DjangoFilePathField
16-
from django.test.client import FakePayload
1712
from django.utils import six
18-
from django.utils.encoding import force_text
19-
from django.utils.six.moves.urllib.parse import urlparse as _urlparse
13+
from django.views.generic import View
2014

2115
try:
22-
import importlib
16+
import importlib # Available in Python 3.1+
2317
except ImportError:
24-
from django.utils import importlib
18+
from django.utils import importlib # Will be removed in Django 1.9
19+
2520

2621
def unicode_repr(instance):
2722
# Get the repr of an instance, but ensure it is a unicode string
@@ -65,30 +60,13 @@ def total_seconds(timedelta):
6560
from django.utils.datastructures import SortedDict as OrderedDict
6661

6762

68-
# HttpResponseBase only exists from 1.5 onwards
69-
try:
70-
from django.http.response import HttpResponseBase
71-
except ImportError:
72-
from django.http import HttpResponse as HttpResponseBase
73-
74-
7563
# contrib.postgres only supported from 1.8 onwards.
7664
try:
7765
from django.contrib.postgres import fields as postgres_fields
7866
except ImportError:
7967
postgres_fields = None
8068

8169

82-
# request only provides `resolver_match` from 1.5 onwards.
83-
def get_resolver_match(request):
84-
try:
85-
return request.resolver_match
86-
except AttributeError:
87-
# Django < 1.5
88-
from django.core.urlresolvers import resolve
89-
return resolve(request.path_info)
90-
91-
9270
# django-filter is optional
9371
try:
9472
import django_filters
@@ -125,25 +103,6 @@ def get_model_name(model_cls):
125103
return model_cls._meta.module_name
126104

127105

128-
# Support custom user models in Django 1.5+
129-
try:
130-
from django.contrib.auth import get_user_model
131-
except ImportError:
132-
from django.contrib.auth.models import User
133-
get_user_model = lambda: User
134-
135-
136-
# View._allowed_methods only present from 1.5 onwards
137-
if django.VERSION >= (1, 5):
138-
from django.views.generic import View
139-
else:
140-
from django.views.generic import View as DjangoView
141-
142-
class View(DjangoView):
143-
def _allowed_methods(self):
144-
return [m.upper() for m in self.http_method_names if hasattr(self, m)]
145-
146-
147106
# MinValueValidator, MaxValueValidator et al. only accept `message` in 1.8+
148107
if django.VERSION >= (1, 8):
149108
from django.core.validators import MinValueValidator, MaxValueValidator
@@ -154,21 +113,25 @@ def _allowed_methods(self):
154113
from django.core.validators import MinLengthValidator as DjangoMinLengthValidator
155114
from django.core.validators import MaxLengthValidator as DjangoMaxLengthValidator
156115

116+
157117
class MinValueValidator(DjangoMinValueValidator):
158118
def __init__(self, *args, **kwargs):
159119
self.message = kwargs.pop('message', self.message)
160120
super(MinValueValidator, self).__init__(*args, **kwargs)
161121

122+
162123
class MaxValueValidator(DjangoMaxValueValidator):
163124
def __init__(self, *args, **kwargs):
164125
self.message = kwargs.pop('message', self.message)
165126
super(MaxValueValidator, self).__init__(*args, **kwargs)
166127

128+
167129
class MinLengthValidator(DjangoMinLengthValidator):
168130
def __init__(self, *args, **kwargs):
169131
self.message = kwargs.pop('message', self.message)
170132
super(MinLengthValidator, self).__init__(*args, **kwargs)
171133

134+
172135
class MaxLengthValidator(DjangoMaxLengthValidator):
173136
def __init__(self, *args, **kwargs):
174137
self.message = kwargs.pop('message', self.message)
@@ -181,6 +144,7 @@ def __init__(self, *args, **kwargs):
181144
else:
182145
from django.core.validators import URLValidator as DjangoURLValidator
183146

147+
184148
class URLValidator(DjangoURLValidator):
185149
def __init__(self, *args, **kwargs):
186150
self.message = kwargs.pop('message', self.message)
@@ -194,6 +158,7 @@ def __init__(self, *args, **kwargs):
194158
from django.core.validators import EmailValidator as DjangoEmailValidator
195159
from django.core.validators import email_re
196160

161+
197162
class EmailValidator(DjangoEmailValidator):
198163
def __init__(self, *args, **kwargs):
199164
super(EmailValidator, self).__init__(email_re, *args, **kwargs)
@@ -208,6 +173,7 @@ def __init__(self, *args, **kwargs):
208173
try:
209174
import markdown
210175

176+
211177
def apply_markdown(text):
212178
"""
213179
Simple wrapper around :func:`markdown.markdown` to set the base level
@@ -233,7 +199,6 @@ def apply_markdown(text):
233199
LONG_SEPARATORS = (b', ', b': ')
234200
INDENT_SEPARATORS = (b',', b': ')
235201

236-
237202
if django.VERSION >= (1, 8):
238203
from django.db.models import DurationField
239204
from django.utils.dateparse import parse_duration

rest_framework/routers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from django.core.urlresolvers import NoReverseMatch
2424

2525
from rest_framework import views
26-
from rest_framework.compat import OrderedDict, get_resolver_match
26+
from rest_framework.compat import OrderedDict
2727
from rest_framework.response import Response
2828
from rest_framework.reverse import reverse
2929
from rest_framework.urlpatterns import format_suffix_patterns
@@ -284,7 +284,7 @@ class APIRoot(views.APIView):
284284

285285
def get(self, request, *args, **kwargs):
286286
ret = OrderedDict()
287-
namespace = get_resolver_match(request).namespace
287+
namespace = request.resolver_match.namespace
288288
for key, url_name in api_root_dict.items():
289289
if namespace:
290290
url_name = namespace + ':' + url_name

rest_framework/utils/formatting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
import re
77

8+
from django.utils.encoding import force_text
89
from django.utils.html import escape
910
from django.utils.safestring import mark_safe
1011

11-
from rest_framework.compat import apply_markdown, force_text
12+
from rest_framework.compat import apply_markdown
1213

1314

1415
def remove_trailing_string(content, trailing):

rest_framework/utils/serializer_helpers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import collections
44

5-
from rest_framework.compat import OrderedDict, force_text, unicode_to_repr
5+
from django.utils.encoding import force_text
6+
7+
from rest_framework.compat import OrderedDict, unicode_to_repr
68

79

810
class ReturnDict(OrderedDict):
@@ -11,6 +13,7 @@ class ReturnDict(OrderedDict):
1113
Includes a backlink to the serializer instance for renderers
1214
to use if they need richer field information.
1315
"""
16+
1417
def __init__(self, *args, **kwargs):
1518
self.serializer = kwargs.pop('serializer')
1619
super(ReturnDict, self).__init__(*args, **kwargs)
@@ -33,6 +36,7 @@ class ReturnList(list):
3336
Includes a backlink to the serializer instance for renderers
3437
to use if they need richer field information.
3538
"""
39+
3640
def __init__(self, *args, **kwargs):
3741
self.serializer = kwargs.pop('serializer')
3842
super(ReturnList, self).__init__(*args, **kwargs)
@@ -52,6 +56,7 @@ class BoundField(object):
5256
Returned when iterating over a serializer instance,
5357
providing an API similar to Django forms and form fields.
5458
"""
59+
5560
def __init__(self, field, value, errors, prefix=''):
5661
self._field = field
5762
self._prefix = prefix
@@ -82,6 +87,7 @@ class NestedBoundField(BoundField):
8287
in order to support nested bound fields. This class is the type of
8388
`BoundField` that is used for serializer fields.
8489
"""
90+
8591
def __iter__(self):
8692
for field in self.fields.values():
8793
yield self[field.field_name]
@@ -112,6 +118,7 @@ class BindingDict(collections.MutableMapping):
112118
`field.bind()` so that the `field_name` and `parent` attributes
113119
can be set correctly.
114120
"""
121+
115122
def __init__(self, serializer):
116123
self.serializer = serializer
117124
self.fields = OrderedDict()

rest_framework/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
from django.core.exceptions import PermissionDenied
77
from django.db import models
88
from django.http import Http404
9+
from django.http.response import HttpResponseBase
910
from django.utils import six
1011
from django.utils.encoding import smart_text
1112
from django.utils.translation import ugettext_lazy as _
1213
from django.views.decorators.csrf import csrf_exempt
14+
from django.views.generic import View
1315

1416
from rest_framework import exceptions, status
15-
from rest_framework.compat import HttpResponseBase, View, set_rollback
17+
from rest_framework.compat import set_rollback
1618
from rest_framework.request import Request
1719
from rest_framework.response import Response
1820
from rest_framework.settings import api_settings

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ addopts=--tb=short
44
[tox]
55
envlist =
66
py27-{lint,docs},
7-
{py26,py27}-django14,
87
{py26,py27,py32,py33,py34}-django{15,16},
98
{py27,py32,py33,py34}-django{17,18,master}
109

0 commit comments

Comments
 (0)