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
5e7c9687
Commit
5e7c9687
authored
Dec 15, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First pass at serializer repr bug
parent
a72f812d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletions
+19
-1
rest_framework/utils/representation.py
+2
-1
tests/test_serializer.py
+17
-0
No files found.
rest_framework/utils/representation.py
View file @
5e7c9687
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
Helper functions for creating user-friendly representations
Helper functions for creating user-friendly representations
of serializer classes and serializer fields.
of serializer classes and serializer fields.
"""
"""
from
__future__
import
unicode_literals
from
django.db
import
models
from
django.db
import
models
from
django.utils.encoding
import
force_text
from
django.utils.encoding
import
force_text
from
django.utils.functional
import
Promise
from
django.utils.functional
import
Promise
...
@@ -24,7 +25,7 @@ def smart_repr(value):
...
@@ -24,7 +25,7 @@ def smart_repr(value):
if
isinstance
(
value
,
Promise
)
and
value
.
_delegate_text
:
if
isinstance
(
value
,
Promise
)
and
value
.
_delegate_text
:
value
=
force_text
(
value
)
value
=
force_text
(
value
)
value
=
repr
(
value
)
value
=
repr
(
value
)
.
decode
(
'utf-8'
)
# Representations like u'help text'
# Representations like u'help text'
# should simply be presented as 'help text'
# should simply be presented as 'help text'
...
...
tests/test_serializer.py
View file @
5e7c9687
# coding: utf-8
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
rest_framework
import
serializers
from
rest_framework
import
serializers
import
pytest
import
pytest
...
@@ -197,3 +198,19 @@ class TestIncorrectlyConfigured:
...
@@ -197,3 +198,19 @@ class TestIncorrectlyConfigured:
"The serializer field might be named incorrectly and not match any attribute or key on the `ExampleObject` instance.
\n
"
"The serializer field might be named incorrectly and not match any attribute or key on the `ExampleObject` instance.
\n
"
"Original exception text was:"
"Original exception text was:"
)
)
class
TestUnicodeRepr
:
def
test_unicode_repr
(
self
):
class
ExampleSerializer
(
serializers
.
Serializer
):
example
=
serializers
.
CharField
()
class
ExampleObject
:
def
__init__
(
self
):
self
.
example
=
'한국'
def
__repr__
(
self
):
return
self
.
example
.
encode
(
'utf8'
)
instance
=
ExampleObject
()
serializer
=
ExampleSerializer
(
instance
)
repr
(
serializer
)
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