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
d1beedad
Commit
d1beedad
authored
Jun 10, 2011
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge flashingpumpkin's fix
parents
88a3e55e
06177b8d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
5 deletions
+29
-5
djangorestframework/parsers.py
+2
-3
djangorestframework/resources.py
+0
-2
djangorestframework/tests/parsers.py
+27
-0
No files found.
djangorestframework/parsers.py
View file @
d1beedad
...
@@ -11,12 +11,11 @@ We need a method to be able to:
...
@@ -11,12 +11,11 @@ We need a method to be able to:
and multipart/form-data. (eg also handle multipart/json)
and multipart/form-data. (eg also handle multipart/json)
"""
"""
from
django.http
import
QueryDict
from
django.http.multipartparser
import
MultiPartParser
as
DjangoMultiPartParser
from
django.http.multipartparser
import
MultiPartParser
as
DjangoMultiPartParser
from
django.utils
import
simplejson
as
json
from
django.utils
import
simplejson
as
json
from
djangorestframework
import
status
from
djangorestframework
import
status
from
djangorestframework.compat
import
parse_qs
from
djangorestframework.response
import
ErrorResponse
from
djangorestframework.response
import
ErrorResponse
from
djangorestframework.utils
import
as_tuple
from
djangorestframework.utils.mediatypes
import
media_type_matches
from
djangorestframework.utils.mediatypes
import
media_type_matches
__all__
=
(
__all__
=
(
...
@@ -117,7 +116,7 @@ class FormParser(BaseParser):
...
@@ -117,7 +116,7 @@ class FormParser(BaseParser):
`data` will be a :class:`QueryDict` containing all the form parameters.
`data` will be a :class:`QueryDict` containing all the form parameters.
`files` will always be :const:`None`.
`files` will always be :const:`None`.
"""
"""
data
=
parse_qs
(
stream
.
read
(),
keep_blank_values
=
True
)
data
=
QueryDict
(
stream
.
read
()
)
return
(
data
,
None
)
return
(
data
,
None
)
...
...
djangorestframework/resources.py
View file @
d1beedad
...
@@ -247,8 +247,6 @@ class FormResource(Resource):
...
@@ -247,8 +247,6 @@ class FormResource(Resource):
# Validation succeeded...
# Validation succeeded...
cleaned_data
=
bound_form
.
cleaned_data
cleaned_data
=
bound_form
.
cleaned_data
cleaned_data
.
update
(
bound_form
.
files
)
# Add in any extra fields to the cleaned content...
# Add in any extra fields to the cleaned content...
for
key
in
(
allowed_extra_fields_set
&
seen_fields_set
)
-
set
(
cleaned_data
.
keys
()):
for
key
in
(
allowed_extra_fields_set
&
seen_fields_set
)
-
set
(
cleaned_data
.
keys
()):
cleaned_data
[
key
]
=
data
[
key
]
cleaned_data
[
key
]
=
data
[
key
]
...
...
djangorestframework/tests/parsers.py
View file @
d1beedad
...
@@ -131,3 +131,30 @@
...
@@ -131,3 +131,30 @@
# self.assertEqual(data['key1'], 'val1')
# self.assertEqual(data['key1'], 'val1')
# self.assertEqual(files['file1'].read(), 'blablabla')
# self.assertEqual(files['file1'].read(), 'blablabla')
from
StringIO
import
StringIO
from
cgi
import
parse_qs
from
django
import
forms
from
django.test
import
TestCase
from
djangorestframework.parsers
import
FormParser
class
Form
(
forms
.
Form
):
field1
=
forms
.
CharField
(
max_length
=
3
)
field2
=
forms
.
CharField
()
class
TestFormParser
(
TestCase
):
def
setUp
(
self
):
self
.
string
=
"field1=abc&field2=defghijk"
def
test_fail
(
self
):
""" Demonstrate that `parse_qs` fails on forms """
data
=
parse_qs
(
self
.
string
,
keep_blank_values
=
True
)
self
.
assertEqual
(
Form
(
data
)
.
is_valid
(),
False
)
def
test_parse
(
self
):
""" Make sure the `QueryDict` works OK """
parser
=
FormParser
(
None
)
stream
=
StringIO
(
self
.
string
)
(
data
,
files
)
=
parser
.
parse
(
stream
)
self
.
assertEqual
(
Form
(
data
)
.
is_valid
(),
True
)
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