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
024780a9
Commit
024780a9
authored
Sep 08, 2012
by
Marko Tibold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fields are showing up again. Still WIP.
parent
274420c6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
30 deletions
+20
-30
djangorestframework/renderers.py
+19
-26
djangorestframework/templates/djangorestframework/base.html
+1
-4
No files found.
djangorestframework/renderers.py
View file @
024780a9
...
@@ -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
...
@@ -234,32 +235,24 @@ class DocumentingTemplateRenderer(BaseRenderer):
...
@@ -234,32 +235,24 @@ class DocumentingTemplateRenderer(BaseRenderer):
provide a form that can be used to submit arbitrary content.
provide a form that can be used to submit arbitrary content.
"""
"""
# Get the form instance if we have one bound to the input
# We need to map our Fields to Django's Fields.
form_instance
=
None
field_mapping
=
dict
([
if
method
==
getattr
(
view
,
'method'
,
view
.
request
.
method
)
.
lower
():
[
FloatField
.
__name__
,
forms
.
FloatField
],
form_instance
=
getattr
(
view
,
'bound_form_instance'
,
None
)
[
IntegerField
.
__name__
,
forms
.
IntegerField
],
[
DateTimeField
.
__name__
,
forms
.
DateTimeField
],
if
not
form_instance
and
hasattr
(
view
,
'get_bound_form'
):
[
DateField
.
__name__
,
forms
.
DateField
],
# Otherwise if we have a response that is valid against the form then use that
[
EmailField
.
__name__
,
forms
.
EmailField
],
if
view
.
response
.
has_content_body
:
[
CharField
.
__name__
,
forms
.
CharField
],
try
:
[
BooleanField
.
__name__
,
forms
.
BooleanField
]
form_instance
=
view
.
get_bound_form
(
view
.
response
.
cleaned_content
,
method
=
method
)
])
if
form_instance
and
not
form_instance
.
is_valid
():
form_instance
=
None
# Creating an on the fly form see: http://stackoverflow.com/questions/3915024/dynamically-creating-classes-python
except
Exception
:
fields
=
{}
form_instance
=
None
for
k
,
v
in
self
.
view
.
get_serializer
()
.
fields
.
items
():
fields
[
k
]
=
field_mapping
[
v
.
__class__
.
__name__
]()
# If we still don't have a form instance then try to get an unbound form
OnTheFlyForm
=
type
(
"OnTheFlyForm"
,
(
forms
.
Form
,),
fields
)
if
not
form_instance
:
try
:
form_instance
=
OnTheFlyForm
(
self
.
view
.
get_serializer
()
.
data
)
form_instance
=
view
.
get_bound_form
(
method
=
method
)
except
Exception
:
pass
# If we still don't have a form instance then try to get an unbound form which can tunnel arbitrary content types
if
not
form_instance
:
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 @
024780a9
...
@@ -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