Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
b7edd463
Commit
b7edd463
authored
May 16, 2015
by
David Sanders
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use simpler dict.get() rather than try/except
parent
8e84a9f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
8 deletions
+2
-8
rest_framework/fields.py
+2
-8
No files found.
rest_framework/fields.py
View file @
b7edd463
...
@@ -1042,16 +1042,10 @@ class ChoiceField(Field):
...
@@ -1042,16 +1042,10 @@ class ChoiceField(Field):
except
KeyError
:
except
KeyError
:
self
.
fail
(
'invalid_choice'
,
input
=
data
)
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
):
def
to_representation
(
self
,
value
):
if
value
in
(
''
,
None
):
if
value
in
(
''
,
None
):
return
value
return
value
return
self
.
representation_value
(
value
)
return
self
.
choice_strings_to_values
.
get
(
six
.
text_type
(
value
),
value
)
class
MultipleChoiceField
(
ChoiceField
):
class
MultipleChoiceField
(
ChoiceField
):
...
@@ -1079,7 +1073,7 @@ class MultipleChoiceField(ChoiceField):
...
@@ -1079,7 +1073,7 @@ class MultipleChoiceField(ChoiceField):
def
to_representation
(
self
,
value
):
def
to_representation
(
self
,
value
):
return
set
([
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
])
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment