Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use simpler dict.get() rather than try/except
  • Loading branch information
David Sanders committed May 15, 2015
commit b7edd463139a02ccad268bc6c9f8a17d02641421
10 changes: 2 additions & 8 deletions rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,16 +1042,10 @@ def to_internal_value(self, data):
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):
Expand Down Expand Up @@ -1079,7 +1073,7 @@ def to_internal_value(self, data):

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


Expand Down