mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Moved smart_unicode to Field ctor, to mimic Django Forms behavior.
This commit is contained in:
parent
a7849157bc
commit
2a82b64963
|
@ -45,8 +45,12 @@ class Field(object):
|
|||
Field.creation_counter += 1
|
||||
|
||||
self.source = source
|
||||
self.label = label
|
||||
self.help_text = help_text
|
||||
|
||||
if label is not None:
|
||||
self.label = smart_unicode(label)
|
||||
|
||||
if help_text is not None:
|
||||
self.help_text = smart_unicode(help_text)
|
||||
|
||||
def initialize(self, parent, field_name):
|
||||
"""
|
||||
|
|
|
@ -429,10 +429,10 @@ class ModelSerializer(Serializer):
|
|||
kwargs['max_length'] = max_length
|
||||
|
||||
if model_field.verbose_name is not None:
|
||||
kwargs['label'] = smart_unicode(model_field.verbose_name)
|
||||
kwargs['label'] = model_field.verbose_name
|
||||
|
||||
if model_field.help_text is not None:
|
||||
kwargs['help_text'] = smart_unicode(model_field.help_text)
|
||||
kwargs['help_text'] = model_field.help_text
|
||||
|
||||
field_mapping = {
|
||||
models.FloatField: FloatField,
|
||||
|
|
|
@ -659,13 +659,13 @@ class FieldLabelTest(TestCase):
|
|||
serializer = self.serializer_class()
|
||||
text_field = serializer.fields['text']
|
||||
|
||||
self.assertEquals('Text', text_field.label)
|
||||
self.assertEquals('Text description.', text_field.help_text)
|
||||
self.assertEquals(u'Text', text_field.label)
|
||||
self.assertEquals(u'Text description.', text_field.help_text)
|
||||
|
||||
def test_field_ctor(self):
|
||||
"""
|
||||
This is check that ctor supports both label and help_text.
|
||||
"""
|
||||
fields.Field(label='Label', help_text='Help')
|
||||
fields.CharField(label='Label', help_text='Help')
|
||||
fields.ManyHyperlinkedRelatedField(view_name='fake', label='Label', help_text='Help')
|
||||
self.assertEquals(u'Label', fields.Field(label='Label', help_text='Help').label)
|
||||
self.assertEquals(u'Help', fields.CharField(label='Label', help_text='Help').help_text)
|
||||
self.assertEquals(u'Label', fields.ManyHyperlinkedRelatedField(view_name='fake', label='Label', help_text='Help').label)
|
||||
|
|
Loading…
Reference in New Issue
Block a user