mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Py3k fixes.
This commit is contained in:
parent
0b6267d8cd
commit
28ae26466e
|
@ -7,8 +7,7 @@ from django.core.paginator import Page
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.forms import widgets
|
from django.forms import widgets
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
from rest_framework.compat import get_concrete_model
|
from rest_framework.compat import get_concrete_model, six
|
||||||
from rest_framework.compat import six
|
|
||||||
|
|
||||||
# Note: We do the following so that users of the framework can use this style:
|
# Note: We do the following so that users of the framework can use this style:
|
||||||
#
|
#
|
||||||
|
@ -326,7 +325,7 @@ class BaseSerializer(Field):
|
||||||
if self.many is not None:
|
if self.many is not None:
|
||||||
many = self.many
|
many = self.many
|
||||||
else:
|
else:
|
||||||
many = hasattr(obj, '__iter__') and not isinstance(obj, (Page, dict))
|
many = hasattr(obj, '__iter__') and not isinstance(obj, (Page, dict, six.text_type))
|
||||||
|
|
||||||
if many:
|
if many:
|
||||||
return [self.to_native(item) for item in obj]
|
return [self.to_native(item) for item in obj]
|
||||||
|
@ -344,7 +343,7 @@ class BaseSerializer(Field):
|
||||||
if self.many is not None:
|
if self.many is not None:
|
||||||
many = self.many
|
many = self.many
|
||||||
else:
|
else:
|
||||||
many = hasattr(data, '__iter__') and not isinstance(data, (Page, dict))
|
many = hasattr(data, '__iter__') and not isinstance(data, (Page, dict, six.text_type))
|
||||||
if many:
|
if many:
|
||||||
warnings.warn('Implict list/queryset serialization is due to be deprecated. '
|
warnings.warn('Implict list/queryset serialization is due to be deprecated. '
|
||||||
'Use the `many=True` flag when instantiating the serializer.',
|
'Use the `many=True` flag when instantiating the serializer.',
|
||||||
|
@ -362,6 +361,7 @@ class BaseSerializer(Field):
|
||||||
|
|
||||||
if not self._errors:
|
if not self._errors:
|
||||||
self.object = ret
|
self.object = ret
|
||||||
|
|
||||||
return self._errors
|
return self._errors
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
|
|
|
@ -1108,5 +1108,5 @@ class DeserializeListTestCase(TestCase):
|
||||||
|
|
||||||
serializer = CommentSerializer(data=data)
|
serializer = CommentSerializer(data=data)
|
||||||
self.assertFalse(serializer.is_valid())
|
self.assertFalse(serializer.is_valid())
|
||||||
expected = [{}, {'email': [u'This field is required.']}, {}]
|
expected = [{}, {'email': ['This field is required.']}, {}]
|
||||||
self.assertEqual(serializer.errors, expected)
|
self.assertEqual(serializer.errors, expected)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user