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
10e451a8
Commit
10e451a8
authored
May 18, 2013
by
Ryan Kaskel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle Python 3 strings and lazy strings.
parent
ef383d96
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletions
+12
-1
rest_framework/fields.py
+12
-1
No files found.
rest_framework/fields.py
View file @
10e451a8
...
...
@@ -19,6 +19,7 @@ from django.db.models.fields import BLANK_CHOICE_DASH
from
django
import
forms
from
django.forms
import
widgets
from
django.utils.encoding
import
is_protected_type
from
django.utils.functional
import
Promise
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.datastructures
import
SortedDict
...
...
@@ -45,6 +46,15 @@ def is_simple_callable(obj):
len_defaults
=
len
(
defaults
)
if
defaults
else
0
return
len_args
<=
len_defaults
if
six
.
PY3
:
def
is_non_str_iterable
(
obj
):
if
(
isinstance
(
obj
,
str
)
or
(
isinstance
(
obj
,
Promise
)
and
obj
.
_delegate_text
)):
return
False
return
hasattr
(
obj
,
'__iter__'
)
else
:
def
is_non_str_iterable
(
obj
):
return
hasattr
(
obj
,
'__iter__'
)
def
get_component
(
obj
,
attr_name
):
"""
...
...
@@ -169,7 +179,8 @@ class Field(object):
if
is_protected_type
(
value
):
return
value
elif
hasattr
(
value
,
'__iter__'
)
and
not
isinstance
(
value
,
(
dict
,
six
.
string_types
)):
elif
(
is_non_str_iterable
(
value
)
and
not
isinstance
(
value
,
(
dict
,
six
.
string_types
))):
return
[
self
.
to_native
(
item
)
for
item
in
value
]
elif
isinstance
(
value
,
dict
):
# Make sure we preserve field ordering, if it exists
...
...
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