Moved smart_unicode to Field ctor, to mimic Django Forms behavior.

This commit is contained in:
Michal Dvorak (cen38289) 2012-12-04 14:16:45 +01:00
parent a7849157bc
commit 2a82b64963
3 changed files with 13 additions and 9 deletions

View File

@ -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):
"""

View File

@ -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,

View File

@ -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)