Skip to content

Commit 77eeefa

Browse files
committed
Merge branch 'master' of https://github.com/tomchristie/django-rest-framework into model-tofield-serializer
2 parents f808b6c + c0fa92e commit 77eeefa

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed

docs/api-guide/routers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ For example, you can append `router.urls` to a list of existing views…
6060
router.register(r'accounts', AccountViewSet)
6161

6262
urlpatterns = [
63-
url(r'^forgot-password/$, ForgotPasswordFormView.as_view(),
63+
url(r'^forgot-password/$', ForgotPasswordFormView.as_view(),
6464
]
6565

6666
urlpatterns += router.urls
6767

6868
Alternatively you can use Django's `include` function, like so…
6969

7070
urlpatterns = [
71-
url(r'^forgot-password/$, ForgotPasswordFormView.as_view(),
71+
url(r'^forgot-password/$', ForgotPasswordFormView.as_view(),
7272
url(r'^', include(router.urls))
7373
]
7474

7575
Router URL patterns can also be namespaces.
7676

7777
urlpatterns = [
78-
url(r'^forgot-password/$, ForgotPasswordFormView.as_view(),
78+
url(r'^forgot-password/$', ForgotPasswordFormView.as_view(),
7979
url(r'^api/', include(router.urls, namespace='api'))
8080
]
8181

docs/tutorial/1-serialization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Open the file `snippets/serializers.py` again, and replace the `SnippetSerialize
198198
model = Snippet
199199
fields = ('id', 'title', 'code', 'linenos', 'language', 'style')
200200

201-
One nice property that serializers have is that you can inspect all the fields in a serializer instance, by printing it's representation. Open the Django shell with `python manage.py shell`, then try the following:
201+
One nice property that serializers have is that you can inspect all the fields in a serializer instance, by printing its representation. Open the Django shell with `python manage.py shell`, then try the following:
202202

203203
>>> from snippets.serializers import SnippetSerializer
204204
>>> serializer = SnippetSerializer()

rest_framework/compat.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def unicode_to_repr(value):
3333
return value
3434

3535

36+
def total_seconds(timedelta):
37+
# TimeDelta.total_seconds() is only available in Python 2.7
38+
if hasattr(timedelta, 'total_seconds'):
39+
return timedelta.total_seconds()
40+
else:
41+
return (timedelta.days * 86400.0) + float(timedelta.seconds) + (timedelta.microseconds / 1000000.0)
42+
43+
3644
# OrderedDict only available in Python 2.7.
3745
# This will always be the case in Django 1.7 and above, as these versions
3846
# no longer support Python 2.6.

rest_framework/renderers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class BaseRenderer(object):
4646
render_style = 'text'
4747

4848
def render(self, data, accepted_media_type=None, renderer_context=None):
49-
raise NotImplemented('Renderer class requires .render() to be implemented')
49+
raise NotImplementedError('Renderer class requires .render() to be implemented')
5050

5151

5252
class JSONRenderer(BaseRenderer):

rest_framework/routers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ def get_default_base_name(self, viewset):
6565
If `base_name` is not specified, attempt to automatically determine
6666
it from the viewset.
6767
"""
68-
raise NotImplemented('get_default_base_name must be overridden')
68+
raise NotImplementedError('get_default_base_name must be overridden')
6969

7070
def get_urls(self):
7171
"""
7272
Return a list of URL patterns, given the registered viewsets.
7373
"""
74-
raise NotImplemented('get_urls must be overridden')
74+
raise NotImplementedError('get_urls must be overridden')
7575

7676
@property
7777
def urls(self):

rest_framework/utils/encoders.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
from django.utils import six, timezone
77
from django.utils.encoding import force_text
88
from django.utils.functional import Promise
9-
from rest_framework.compat import OrderedDict
9+
from rest_framework.compat import OrderedDict, total_seconds
1010
from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList
1111
import datetime
1212
import decimal
1313
import types
1414
import json
15+
import uuid
1516

1617

1718
class JSONEncoder(json.JSONEncoder):
@@ -41,10 +42,12 @@ def default(self, obj):
4142
representation = representation[:12]
4243
return representation
4344
elif isinstance(obj, datetime.timedelta):
44-
return six.text_type(obj.total_seconds())
45+
return six.text_type(total_seconds(obj))
4546
elif isinstance(obj, decimal.Decimal):
4647
# Serializers will coerce decimals to strings by default.
4748
return float(obj)
49+
elif isinstance(obj, uuid.UUID):
50+
return six.text_type(obj)
4851
elif isinstance(obj, QuerySet):
4952
return tuple(obj)
5053
elif hasattr(obj, 'tolist'):

rest_framework/utils/serializer_helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def __init__(self, *args, **kwargs):
1616
def copy(self):
1717
return ReturnDict(self, serializer=self.serializer)
1818

19+
def __repr__(self):
20+
return dict.__repr__(self)
21+
1922

2023
class ReturnList(list):
2124
"""
@@ -27,6 +30,9 @@ def __init__(self, *args, **kwargs):
2730
self.serializer = kwargs.pop('serializer')
2831
super(ReturnList, self).__init__(*args, **kwargs)
2932

33+
def __repr__(self):
34+
return list.__repr__(self)
35+
3036

3137
class BoundField(object):
3238
"""

0 commit comments

Comments
 (0)