mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-30 18:09:59 +03:00
Merge b5640bb778
into 2dd48fbb05
This commit is contained in:
commit
3fe6544ab3
|
@ -24,7 +24,7 @@ from rest_framework import ISO_8601
|
|||
from rest_framework.compat import timezone, parse_date, parse_datetime, parse_time
|
||||
from rest_framework.compat import BytesIO
|
||||
from rest_framework.compat import six
|
||||
from rest_framework.compat import smart_text
|
||||
from rest_framework.compat import smart_text, force_text
|
||||
from rest_framework.settings import api_settings
|
||||
|
||||
|
||||
|
@ -171,7 +171,7 @@ class Field(object):
|
|||
return [self.to_native(item) for item in value]
|
||||
elif isinstance(value, dict):
|
||||
return dict(map(self.to_native, (k, v)) for k, v in value.items())
|
||||
return smart_text(value)
|
||||
return force_text(value)
|
||||
|
||||
def attributes(self):
|
||||
"""
|
||||
|
|
|
@ -1143,3 +1143,32 @@ class DeserializeListTestCase(TestCase):
|
|||
self.assertFalse(serializer.is_valid())
|
||||
expected = [{}, {'email': ['This field is required.']}, {}]
|
||||
self.assertEqual(serializer.errors, expected)
|
||||
|
||||
|
||||
# test for issue 747
|
||||
|
||||
class LazyStringModel(object):
|
||||
def __init__(self, lazystring):
|
||||
self.lazystring = lazystring
|
||||
|
||||
|
||||
class LazyStringSerializer(serializers.Serializer):
|
||||
lazystring = serializers.Field()
|
||||
|
||||
def restore_object(self, attrs, instance=None):
|
||||
if instance is not None:
|
||||
instance.lazystring = attrs.get('lazystring', instance.lazystring)
|
||||
return instance
|
||||
return Comment(**attrs)
|
||||
|
||||
|
||||
class LazyStringsTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
self.model = LazyStringModel(lazystring=_("lazystring"))
|
||||
|
||||
def test_lazy_strings_are_translated(self):
|
||||
serializer = LazyStringSerializer(self.model)
|
||||
self.assertEqual(type(serializer.data['lazystring']), type("lazystring"))
|
||||
|
|
Loading…
Reference in New Issue
Block a user