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
e59b3d17
Commit
e59b3d17
authored
Jan 21, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ReturnDict cachable. Closes #2360.
parent
9d24809a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
rest_framework/utils/serializer_helpers.py
+10
-0
tests/test_serializer.py
+17
-0
No files found.
rest_framework/utils/serializer_helpers.py
View file @
e59b3d17
...
@@ -19,6 +19,11 @@ class ReturnDict(OrderedDict):
...
@@ -19,6 +19,11 @@ class ReturnDict(OrderedDict):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
dict
.
__repr__
(
self
)
return
dict
.
__repr__
(
self
)
def
__reduce__
(
self
):
# Pickling these objects will drop the .serializer backlink,
# but preserve the raw data.
return
(
dict
,
(
dict
(
self
),))
class
ReturnList
(
list
):
class
ReturnList
(
list
):
"""
"""
...
@@ -33,6 +38,11 @@ class ReturnList(list):
...
@@ -33,6 +38,11 @@ class ReturnList(list):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
list
.
__repr__
(
self
)
return
list
.
__repr__
(
self
)
def
__reduce__
(
self
):
# Pickling these objects will drop the .serializer backlink,
# but preserve the raw data.
return
(
list
,
(
list
(
self
),))
class
BoundField
(
object
):
class
BoundField
(
object
):
"""
"""
...
...
tests/test_serializer.py
View file @
e59b3d17
...
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
...
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
from
.utils
import
MockObject
from
.utils
import
MockObject
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
rest_framework.compat
import
unicode_repr
from
rest_framework.compat
import
unicode_repr
import
pickle
import
pytest
import
pytest
...
@@ -278,3 +279,19 @@ class TestNotRequiredOutput:
...
@@ -278,3 +279,19 @@ class TestNotRequiredOutput:
serializer
=
ExampleSerializer
(
instance
)
serializer
=
ExampleSerializer
(
instance
)
with
pytest
.
raises
(
AttributeError
):
with
pytest
.
raises
(
AttributeError
):
serializer
.
data
serializer
.
data
class
TestCacheSerializerData
:
def
test_cache_serializer_data
(
self
):
"""
Caching serializer data with pickle will drop the serializer info,
but does preserve the data itself.
"""
class
ExampleSerializer
(
serializers
.
Serializer
):
field1
=
serializers
.
CharField
()
field2
=
serializers
.
CharField
()
serializer
=
ExampleSerializer
({
'field1'
:
'a'
,
'field2'
:
'b'
})
pickled
=
pickle
.
dumps
(
serializer
.
data
)
data
=
pickle
.
loads
(
pickled
)
assert
data
==
{
'field1'
:
'a'
,
'field2'
:
'b'
}
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