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
2a82b649
Commit
2a82b649
authored
Dec 04, 2012
by
Michal Dvorak (cen38289)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved smart_unicode to Field ctor, to mimic Django Forms behavior.
parent
a7849157
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
9 deletions
+13
-9
rest_framework/fields.py
+6
-2
rest_framework/serializers.py
+2
-2
rest_framework/tests/serializer.py
+5
-5
No files found.
rest_framework/fields.py
View file @
2a82b649
...
...
@@ -45,8 +45,12 @@ class Field(object):
Field
.
creation_counter
+=
1
self
.
source
=
source
self
.
label
=
label
self
.
help_text
=
help_text
if
label
is
not
None
:
self
.
label
=
smart_unicode
(
label
)
if
help_text
is
not
None
:
self
.
help_text
=
smart_unicode
(
help_text
)
def
initialize
(
self
,
parent
,
field_name
):
"""
...
...
rest_framework/serializers.py
View file @
2a82b649
...
...
@@ -429,10 +429,10 @@ class ModelSerializer(Serializer):
kwargs
[
'max_length'
]
=
max_length
if
model_field
.
verbose_name
is
not
None
:
kwargs
[
'label'
]
=
smart_unicode
(
model_field
.
verbose_name
)
kwargs
[
'label'
]
=
model_field
.
verbose_name
if
model_field
.
help_text
is
not
None
:
kwargs
[
'help_text'
]
=
smart_unicode
(
model_field
.
help_text
)
kwargs
[
'help_text'
]
=
model_field
.
help_text
field_mapping
=
{
models
.
FloatField
:
FloatField
,
...
...
rest_framework/tests/serializer.py
View file @
2a82b649
...
...
@@ -659,13 +659,13 @@ class FieldLabelTest(TestCase):
serializer
=
self
.
serializer_class
()
text_field
=
serializer
.
fields
[
'text'
]
self
.
assertEquals
(
'Text'
,
text_field
.
label
)
self
.
assertEquals
(
'Text description.'
,
text_field
.
help_text
)
self
.
assertEquals
(
u
'Text'
,
text_field
.
label
)
self
.
assertEquals
(
u
'Text description.'
,
text_field
.
help_text
)
def
test_field_ctor
(
self
):
"""
This is check that ctor supports both label and help_text.
"""
fields
.
Field
(
label
=
'Label'
,
help_text
=
'Help'
)
fields
.
CharField
(
label
=
'Label'
,
help_text
=
'Help'
)
fields
.
ManyHyperlinkedRelatedField
(
view_name
=
'fake'
,
label
=
'Label'
,
help_text
=
'Help'
)
self
.
assertEquals
(
u'Label'
,
fields
.
Field
(
label
=
'Label'
,
help_text
=
'Help'
)
.
label
)
self
.
assertEquals
(
u'Help'
,
fields
.
CharField
(
label
=
'Label'
,
help_text
=
'Help'
)
.
help_text
)
self
.
assertEquals
(
u'Label'
,
fields
.
ManyHyperlinkedRelatedField
(
view_name
=
'fake'
,
label
=
'Label'
,
help_text
=
'Help'
)
.
label
)
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