mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Use simpler dict.get() rather than try/except
This commit is contained in:
parent
8e84a9f6d0
commit
b7edd46313
|
@ -1042,16 +1042,10 @@ class ChoiceField(Field):
|
|||
except KeyError:
|
||||
self.fail('invalid_choice', input=data)
|
||||
|
||||
def representation_value(self, value):
|
||||
try:
|
||||
return self.choice_strings_to_values[six.text_type(value)]
|
||||
except KeyError:
|
||||
return value
|
||||
|
||||
def to_representation(self, value):
|
||||
if value in ('', None):
|
||||
return value
|
||||
return self.representation_value(value)
|
||||
return self.choice_strings_to_values.get(six.text_type(value), value)
|
||||
|
||||
|
||||
class MultipleChoiceField(ChoiceField):
|
||||
|
@ -1079,7 +1073,7 @@ class MultipleChoiceField(ChoiceField):
|
|||
|
||||
def to_representation(self, value):
|
||||
return set([
|
||||
self.representation_value(item) for item in value
|
||||
self.choice_strings_to_values.get(six.text_type(item), item) for item in value
|
||||
])
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user