This commit is contained in:
mattxbart 2015-02-18 17:05:51 +00:00
commit f21aa33a90

View File

@ -910,7 +910,7 @@ class DateField(Field):
self.fail('invalid', format=humanized_format) self.fail('invalid', format=humanized_format)
def to_representation(self, value): def to_representation(self, value):
if self.format is None: if self.format or value is None:
return value return value
# Applying a `DateField` to a datetime value is almost always # Applying a `DateField` to a datetime value is almost always
@ -1024,8 +1024,10 @@ class ChoiceField(Field):
def to_representation(self, value): def to_representation(self, value):
if value in ('', None): if value in ('', None):
return value return value
return self.choice_strings_to_values[six.text_type(value)] try:
return self.choice_strings_to_values[six.text_type(value)]
except KeyError:
return value
class MultipleChoiceField(ChoiceField): class MultipleChoiceField(ChoiceField):
default_error_messages = { default_error_messages = {
@ -1051,10 +1053,12 @@ class MultipleChoiceField(ChoiceField):
]) ])
def to_representation(self, value): def to_representation(self, value):
return set([ if value in ('', None):
self.choice_strings_to_values[six.text_type(item)] for item in value return value
]) try:
return self.choice_strings_to_values[six.text_type(value)]
except KeyError:
return value
# File types... # File types...