Minor cleanup

This commit is contained in:
Tom Christie 2015-02-06 14:43:43 +00:00
parent a435b1b355
commit dec3493d7c
2 changed files with 4 additions and 19 deletions

View File

@ -578,19 +578,10 @@ class CharField(Field):
def to_internal_value(self, data):
value = six.text_type(data)
if self.trim_whitespace:
return value.strip()
return value
return value.strip() if self.trim_whitespace else value
def to_representation(self, value):
representation = six.text_type(value)
if self.trim_whitespace:
return representation.strip()
return representation
return six.text_type(value)
class EmailField(CharField):
@ -603,12 +594,6 @@ class EmailField(CharField):
validator = EmailValidator(message=self.error_messages['invalid'])
self.validators.append(validator)
def to_internal_value(self, data):
return six.text_type(data).strip()
def to_representation(self, value):
return six.text_type(value).strip()
class RegexField(CharField):
default_error_messages = {

View File

@ -412,11 +412,11 @@ class TestCharField(FieldValues):
def test_trim_whitespace_default(self):
field = serializers.CharField()
assert field.to_representation(' abc ') == 'abc'
assert field.to_internal_value(' abc ') == 'abc'
def test_trim_whitespace_disabled(self):
field = serializers.CharField(trim_whitespace=False)
assert field.to_representation(' abc ') == ' abc '
assert field.to_internal_value(' abc ') == ' abc '
class TestEmailField(FieldValues):