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
a33c2176
Commit
a33c2176
authored
Sep 08, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #256 from markotibold/put-post-delete
Re-enable PUT/POST/DELETE in the browsable api
parents
247696e8
ef0bf1e7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
32 deletions
+28
-32
djangorestframework/mixins.py
+1
-1
djangorestframework/renderers.py
+26
-27
djangorestframework/templates/djangorestframework/base.html
+1
-4
No files found.
djangorestframework/mixins.py
View file @
a33c2176
...
@@ -22,7 +22,7 @@ class CreateModelMixin(object):
...
@@ -22,7 +22,7 @@ class CreateModelMixin(object):
self
.
object
=
serializer
.
object
self
.
object
=
serializer
.
object
self
.
object
.
save
()
self
.
object
.
save
()
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
)
return
Response
(
serializer
.
error
_data
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
return
Response
(
serializer
.
error
s
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
class
ListModelMixin
(
object
):
class
ListModelMixin
(
object
):
...
...
djangorestframework/renderers.py
View file @
a33c2176
...
@@ -16,6 +16,7 @@ from djangorestframework.utils import encoders
...
@@ -16,6 +16,7 @@ from djangorestframework.utils import encoders
from
djangorestframework.utils.breadcrumbs
import
get_breadcrumbs
from
djangorestframework.utils.breadcrumbs
import
get_breadcrumbs
from
djangorestframework.utils.mediatypes
import
get_media_type_params
,
add_media_type_param
,
media_type_matches
from
djangorestframework.utils.mediatypes
import
get_media_type_params
,
add_media_type_param
,
media_type_matches
from
djangorestframework
import
VERSION
from
djangorestframework
import
VERSION
from
djangorestframework.fields
import
FloatField
,
IntegerField
,
DateTimeField
,
DateField
,
EmailField
,
CharField
,
BooleanField
import
string
import
string
...
@@ -233,33 +234,31 @@ class DocumentingTemplateRenderer(BaseRenderer):
...
@@ -233,33 +234,31 @@ class DocumentingTemplateRenderer(BaseRenderer):
In the absence on of the Resource having an associated form then
In the absence on of the Resource having an associated form then
provide a form that can be used to submit arbitrary content.
provide a form that can be used to submit arbitrary content.
"""
"""
if
not
hasattr
(
self
.
view
,
'get_serializer'
):
# No serializer, no form.
# Get the form instance if we have one bound to the input
return
form_instance
=
None
# We need to map our Fields to Django's Fields.
if
method
==
getattr
(
view
,
'method'
,
view
.
request
.
method
)
.
lower
():
field_mapping
=
dict
([
form_instance
=
getattr
(
view
,
'bound_form_instance'
,
None
)
[
FloatField
.
__name__
,
forms
.
FloatField
],
[
IntegerField
.
__name__
,
forms
.
IntegerField
],
if
not
form_instance
and
hasattr
(
view
,
'get_bound_form'
):
[
DateTimeField
.
__name__
,
forms
.
DateTimeField
],
# Otherwise if we have a response that is valid against the form then use that
[
DateField
.
__name__
,
forms
.
DateField
],
if
view
.
response
.
has_content_body
:
[
EmailField
.
__name__
,
forms
.
EmailField
],
try
:
[
CharField
.
__name__
,
forms
.
CharField
],
form_instance
=
view
.
get_bound_form
(
view
.
response
.
cleaned_content
,
method
=
method
)
[
BooleanField
.
__name__
,
forms
.
BooleanField
]
if
form_instance
and
not
form_instance
.
is_valid
():
])
form_instance
=
None
except
Exception
:
# Creating an on the fly form see: http://stackoverflow.com/questions/3915024/dynamically-creating-classes-python
form_instance
=
None
fields
=
{}
object
,
data
=
None
,
None
# If we still don't have a form instance then try to get an unbound form
if
hasattr
(
self
.
view
,
'object'
):
if
not
form_instance
:
object
=
self
.
view
.
object
try
:
serializer
=
self
.
view
.
get_serializer
(
instance
=
object
)
form_instance
=
view
.
get_bound_form
(
method
=
method
)
for
k
,
v
in
serializer
.
fields
.
items
():
except
Exception
:
fields
[
k
]
=
field_mapping
[
v
.
__class__
.
__name__
]()
pass
OnTheFlyForm
=
type
(
"OnTheFlyForm"
,
(
forms
.
Form
,),
fields
)
if
object
and
not
self
.
view
.
request
.
method
==
'DELETE'
:
# Don't fill in the form when the object is deleted
# If we still don't have a form instance then try to get an unbound form which can tunnel arbitrary content types
data
=
serializer
.
data
if
not
form_instance
:
form_instance
=
OnTheFlyForm
(
data
)
form_instance
=
self
.
_get_generic_content_form
(
view
)
return
form_instance
return
form_instance
def
_get_generic_content_form
(
self
,
view
):
def
_get_generic_content_form
(
self
,
view
):
...
...
djangorestframework/templates/djangorestframework/base.html
View file @
a33c2176
...
@@ -78,8 +78,6 @@
...
@@ -78,8 +78,6 @@
</form>
</form>
{% endif %}
{% endif %}
{% comment %}
DROP POST/PUT/DELETE until the forms are working with REST framework 2
{# Only display the POST/PUT/DELETE forms if method tunneling via POST forms is enabled and the user has permissions on this view. #}
{# Only display the POST/PUT/DELETE forms if method tunneling via POST forms is enabled and the user has permissions on this view. #}
{% if response.status_code != 403 %}
{% if response.status_code != 403 %}
...
@@ -90,7 +88,7 @@
...
@@ -90,7 +88,7 @@
<h2>
POST {{ name }}
</h2>
<h2>
POST {{ name }}
</h2>
{% csrf_token %}
{% csrf_token %}
{{ post_form.non_field_errors }}
{{ post_form.non_field_errors }}
{% for field in post_form %}
{% for field in post_form %}
<div
class=
'form-row'
>
<div
class=
'form-row'
>
{{ field.label_tag }}
{{ field.label_tag }}
{{ field }}
{{ field }}
...
@@ -141,7 +139,6 @@
...
@@ -141,7 +139,6 @@
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endcomment %}
</div>
</div>
<!-- END content-main -->
<!-- END content-main -->
...
...
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