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
c10a95de
Commit
c10a95de
authored
Dec 30, 2010
by
tom christie tom@tomchristie.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parsers, form validation, etc...
parent
c56e48f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
0 deletions
+46
-0
src/rest/utils.py
+39
-0
src/testapp/forms.py
+7
-0
No files found.
src/rest/utils.py
0 → 100644
View file @
c10a95de
# From piston...
def
coerce_put_post
(
request
):
"""
Django doesn't particularly understand REST.
In case we send data over PUT, Django won't
actually look at the data and load it. We need
to twist its arm here.
The try/except abominiation here is due to a bug
in mod_python. This should fix it.
"""
if
request
.
method
!=
'PUT'
:
return
# Bug fix: if _load_post_and_files has already been called, for
# example by middleware accessing request.POST, the below code to
# pretend the request is a POST instead of a PUT will be too late
# to make a difference. Also calling _load_post_and_files will result
# in the following exception:
# AttributeError: You cannot set the upload handlers after the upload has been processed.
# The fix is to check for the presence of the _post field which is set
# the first time _load_post_and_files is called (both by wsgi.py and
# modpython.py). If it's set, the request has to be 'reset' to redo
# the query value parsing in POST mode.
if
hasattr
(
request
,
'_post'
):
del
request
.
_post
del
request
.
_files
try
:
request
.
method
=
"POST"
request
.
_load_post_and_files
()
request
.
method
=
"PUT"
except
AttributeError
:
request
.
META
[
'REQUEST_METHOD'
]
=
'POST'
request
.
_load_post_and_files
()
request
.
META
[
'REQUEST_METHOD'
]
=
'PUT'
request
.
PUT
=
request
.
POST
src/testapp/forms.py
0 → 100644
View file @
c10a95de
from
django
import
forms
class
ExampleForm
(
forms
.
Form
):
title
=
forms
.
CharField
(
max_length
=
100
)
message
=
forms
.
CharField
()
sender
=
forms
.
EmailField
()
valid
=
forms
.
BooleanField
(
required
=
False
)
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