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
cc1c4232
Commit
cc1c4232
authored
Oct 15, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorganize to use template_pack in form rendering
parent
e558f806
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
35 additions
and
38 deletions
+35
-38
rest_framework/renderers.py
+4
-11
rest_framework/templates/rest_framework/horizontal/fields/checkbox.html
+0
-0
rest_framework/templates/rest_framework/horizontal/fields/fieldset.html
+0
-0
rest_framework/templates/rest_framework/horizontal/fields/input.html
+0
-0
rest_framework/templates/rest_framework/horizontal/fields/list_fieldset.html
+0
-0
rest_framework/templates/rest_framework/horizontal/fields/select.html
+0
-0
rest_framework/templates/rest_framework/horizontal/fields/select_checkbox.html
+0
-0
rest_framework/templates/rest_framework/horizontal/fields/select_multiple.html
+0
-0
rest_framework/templates/rest_framework/horizontal/fields/select_radio.html
+0
-0
rest_framework/templates/rest_framework/horizontal/fields/textarea.html
+0
-0
rest_framework/templates/rest_framework/horizontal/form.html
+6
-24
rest_framework/templates/rest_framework/inline/fields/checkbox.html
+0
-0
rest_framework/templates/rest_framework/inline/fields/fieldset.html
+0
-0
rest_framework/templates/rest_framework/inline/fields/input.html
+0
-0
rest_framework/templates/rest_framework/inline/fields/select.html
+0
-0
rest_framework/templates/rest_framework/inline/fields/select_checkbox.html
+0
-0
rest_framework/templates/rest_framework/inline/fields/select_multiple.html
+0
-0
rest_framework/templates/rest_framework/inline/fields/select_radio.html
+0
-0
rest_framework/templates/rest_framework/inline/fields/textarea.html
+1
-1
rest_framework/templates/rest_framework/inline/form.html
+11
-0
rest_framework/templates/rest_framework/vertical/fields/checkbox.html
+0
-0
rest_framework/templates/rest_framework/vertical/fields/fieldset.html
+0
-0
rest_framework/templates/rest_framework/vertical/fields/input.html
+0
-0
rest_framework/templates/rest_framework/vertical/fields/list_fieldset.html
+0
-0
rest_framework/templates/rest_framework/vertical/fields/select.html
+0
-0
rest_framework/templates/rest_framework/vertical/fields/select_checkbox.html
+0
-0
rest_framework/templates/rest_framework/vertical/fields/select_multiple.html
+0
-0
rest_framework/templates/rest_framework/vertical/fields/select_radio.html
+0
-0
rest_framework/templates/rest_framework/vertical/fields/textarea.html
+0
-0
rest_framework/templates/rest_framework/vertical/form.html
+11
-0
rest_framework/templatetags/rest_framework.py
+2
-2
No files found.
rest_framework/renderers.py
View file @
cc1c4232
...
@@ -339,7 +339,6 @@ class HTMLFormRenderer(BaseRenderer):
...
@@ -339,7 +339,6 @@ class HTMLFormRenderer(BaseRenderer):
"""
"""
media_type
=
'text/html'
media_type
=
'text/html'
format
=
'form'
format
=
'form'
template
=
'rest_framework/form.html'
charset
=
'utf-8'
charset
=
'utf-8'
field_templates
=
ClassLookupDict
({
field_templates
=
ClassLookupDict
({
...
@@ -383,26 +382,21 @@ class HTMLFormRenderer(BaseRenderer):
...
@@ -383,26 +382,21 @@ class HTMLFormRenderer(BaseRenderer):
serializers
.
TimeField
:
'time'
,
serializers
.
TimeField
:
'time'
,
})
})
def
render_field
(
self
,
field
,
layout
=
None
):
def
render_field
(
self
,
field
,
template_pack
=
None
):
layout
=
layout
or
'vertical'
style_type
=
field
.
style
.
get
(
'type'
,
'default'
)
style_type
=
field
.
style
.
get
(
'type'
,
'default'
)
if
style_type
==
'textarea'
and
layout
==
'inline'
:
style_type
=
'default'
input_type
=
self
.
input_type
[
field
]
input_type
=
self
.
input_type
[
field
]
if
input_type
==
'datetime-local'
and
isinstance
(
field
.
value
,
six
.
text_type
):
if
input_type
==
'datetime-local'
and
isinstance
(
field
.
value
,
six
.
text_type
):
field
.
value
=
field
.
value
.
rstrip
(
'Z'
)
field
.
value
=
field
.
value
.
rstrip
(
'Z'
)
base
=
self
.
field_templates
[
field
][
style_type
]
base
=
self
.
field_templates
[
field
][
style_type
]
template_name
=
'rest_framework/fields/'
+
layout
+
'
/'
+
base
template_name
=
template_pack
+
'/fields
/'
+
base
template
=
loader
.
get_template
(
template_name
)
template
=
loader
.
get_template
(
template_name
)
context
=
Context
({
context
=
Context
({
'field'
:
field
,
'field'
:
field
,
'input_type'
:
input_type
,
'input_type'
:
input_type
,
'renderer'
:
self
,
'renderer'
:
self
,
'layout'
:
layout
})
})
return
template
.
render
(
context
)
return
template
.
render
(
context
)
def
render
(
self
,
data
,
accepted_media_type
=
None
,
renderer_context
=
None
):
def
render
(
self
,
data
,
accepted_media_type
=
None
,
renderer_context
=
None
):
...
@@ -411,11 +405,10 @@ class HTMLFormRenderer(BaseRenderer):
...
@@ -411,11 +405,10 @@ class HTMLFormRenderer(BaseRenderer):
"""
"""
renderer_context
=
renderer_context
or
{}
renderer_context
=
renderer_context
or
{}
request
=
renderer_context
[
'request'
]
request
=
renderer_context
[
'request'
]
template
=
loader
.
get_template
(
'rest_framework/horizontal/form.html'
)
template
=
loader
.
get_template
(
self
.
template
)
context
=
RequestContext
(
request
,
{
context
=
RequestContext
(
request
,
{
'form'
:
data
.
serializer
,
'form'
:
data
.
serializer
,
'
layout'
:
getattr
(
getattr
(
data
,
'Meta'
,
None
),
'layout'
,
'horizontal'
)
,
'
template_pack'
:
'rest_framework/horizontal'
,
'renderer'
:
self
'renderer'
:
self
})
})
return
template
.
render
(
context
)
return
template
.
render
(
context
)
...
...
rest_framework/templates/rest_framework/
fields/horizontal
/checkbox.html
→
rest_framework/templates/rest_framework/
horizontal/fields
/checkbox.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/horizontal
/fieldset.html
→
rest_framework/templates/rest_framework/
horizontal/fields
/fieldset.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/horizontal
/input.html
→
rest_framework/templates/rest_framework/
horizontal/fields
/input.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/horizontal
/list_fieldset.html
→
rest_framework/templates/rest_framework/
horizontal/fields
/list_fieldset.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/horizontal
/select.html
→
rest_framework/templates/rest_framework/
horizontal/fields
/select.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/horizontal
/select_checkbox.html
→
rest_framework/templates/rest_framework/
horizontal/fields
/select_checkbox.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/horizontal
/select_multiple.html
→
rest_framework/templates/rest_framework/
horizontal/fields
/select_multiple.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/horizontal
/select_radio.html
→
rest_framework/templates/rest_framework/
horizontal/fields
/select_radio.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/horizontal
/textarea.html
→
rest_framework/templates/rest_framework/
horizontal/fields
/textarea.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/form.html
→
rest_framework/templates/rest_framework/
horizontal/
form.html
View file @
cc1c4232
<!-- <html>
<head>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>User update</h1>
<div class="well"> -->
{% load rest_framework %}
{% load rest_framework %}
<form
{%
if
layout =
=
"
inline
"
%}
class=
"form-inline"
{%
elif
layout =
=
"
horizontal
"
%}
class=
"form-horizontal"
{%
endif
%}
role=
"form"
action=
"."
method=
"POST"
>
<form
class=
"form-horizontal"
role=
"form"
action=
"."
method=
"POST"
>
{% csrf_token %}
{% csrf_token %}
{% for field in form %}
{% for field in form %}
{% if not field.read_only %}
{% if not field.read_only %}
{% render_field field
layout=layout
renderer=renderer %}
{% render_field field
template_pack=template_pack
renderer=renderer %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
<!-- form.non_field_errors -->
<!-- form.non_field_errors -->
{% if layout == "horizontal" %}
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<div
class=
"col-sm-offset-2 col-sm-10"
>
<div
class=
"col-sm-offset-2 col-sm-10"
>
<button
type=
"submit"
class=
"btn btn-default"
>
Submit
</button>
<button
type=
"submit"
class=
"btn btn-default"
>
Submit
</button>
</div>
</div>
</div>
{% else %}
</div>
<button
type=
"submit"
class=
"btn btn-default"
>
Submit
</button>
{% endif %}
</form>
</form>
<!--
</div>
</div></body>
</html> -->
rest_framework/templates/rest_framework/
fields/inline
/checkbox.html
→
rest_framework/templates/rest_framework/
inline/fields
/checkbox.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/inline
/fieldset.html
→
rest_framework/templates/rest_framework/
inline/fields
/fieldset.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/inline
/input.html
→
rest_framework/templates/rest_framework/
inline/fields
/input.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/inline
/select.html
→
rest_framework/templates/rest_framework/
inline/fields
/select.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/inline
/select_checkbox.html
→
rest_framework/templates/rest_framework/
inline/fields
/select_checkbox.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/inline
/select_multiple.html
→
rest_framework/templates/rest_framework/
inline/fields
/select_multiple.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/inline
/select_radio.html
→
rest_framework/templates/rest_framework/
inline/fields
/select_radio.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/inline
/textarea.html
→
rest_framework/templates/rest_framework/
inline/fields
/textarea.html
View file @
cc1c4232
...
@@ -2,5 +2,5 @@
...
@@ -2,5 +2,5 @@
{% if field.label %}
{% if field.label %}
<label
class=
"sr-only"
>
{{ field.label }}
</label>
<label
class=
"sr-only"
>
{{ field.label }}
</label>
{% endif %}
{% endif %}
<
textarea
name=
"{{ field.name }}"
class=
"form-control"
{%
if
field
.
style
.
placeholder
%}
placeholder=
"{{ field.style.placeholder }}"
{%
endif
%}
{%
if
field
.
style
.
rows
%}
rows=
"{{ field.style.rows }}"
{%
endif
%}
>
{% if field.value %}{{ field.value }}{% endif %}
</textarea
>
<
input
name=
"{{ field.name }}"
type=
"{{ input_type }}"
class=
"form-control"
{%
if
field
.
style
.
placeholder
%}
placeholder=
"{{ field.style.placeholder }}"
{%
endif
%}
{%
if
field
.
value
%}
value=
"{{ field.value }}"
{%
endif
%}
>
</div>
</div>
rest_framework/templates/rest_framework/inline/form.html
0 → 100644
View file @
cc1c4232
{% load rest_framework %}
<form
class=
"form-inline"
role=
"form"
action=
"."
method=
"POST"
>
{% csrf_token %}
{% for field in form %}
{% if not field.read_only %}
{% render_field field template_pack=template_pack renderer=renderer %}
{% endif %}
{% endfor %}
<!-- form.non_field_errors -->
<button
type=
"submit"
class=
"btn btn-default"
>
Submit
</button>
</form>
rest_framework/templates/rest_framework/
fields/vertical
/checkbox.html
→
rest_framework/templates/rest_framework/
vertical/fields
/checkbox.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/vertical
/fieldset.html
→
rest_framework/templates/rest_framework/
vertical/fields
/fieldset.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/vertical
/input.html
→
rest_framework/templates/rest_framework/
vertical/fields
/input.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/vertical
/list_fieldset.html
→
rest_framework/templates/rest_framework/
vertical/fields
/list_fieldset.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/vertical
/select.html
→
rest_framework/templates/rest_framework/
vertical/fields
/select.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/vertical
/select_checkbox.html
→
rest_framework/templates/rest_framework/
vertical/fields
/select_checkbox.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/vertical
/select_multiple.html
→
rest_framework/templates/rest_framework/
vertical/fields
/select_multiple.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/vertical
/select_radio.html
→
rest_framework/templates/rest_framework/
vertical/fields
/select_radio.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/
fields/vertical
/textarea.html
→
rest_framework/templates/rest_framework/
vertical/fields
/textarea.html
View file @
cc1c4232
File moved
rest_framework/templates/rest_framework/vertical/form.html
0 → 100644
View file @
cc1c4232
{% load rest_framework %}
<form
role=
"form"
action=
"."
method=
"POST"
>
{% csrf_token %}
{% for field in form %}
{% if not field.read_only %}
{% render_field field template_pack=template_pack renderer=renderer %}
{% endif %}
{% endfor %}
<!-- form.non_field_errors -->
<button
type=
"submit"
class=
"btn btn-default"
>
Submit
</button>
</form>
rest_framework/templatetags/rest_framework.py
View file @
cc1c4232
...
@@ -32,8 +32,8 @@ class_re = re.compile(r'(?<=class=["\'])(.*)(?=["\'])')
...
@@ -32,8 +32,8 @@ class_re = re.compile(r'(?<=class=["\'])(.*)(?=["\'])')
# And the template tags themselves...
# And the template tags themselves...
@register.simple_tag
@register.simple_tag
def
render_field
(
field
,
layout
=
None
,
renderer
=
None
):
def
render_field
(
field
,
template_pack
=
None
,
renderer
=
None
):
return
renderer
.
render_field
(
field
,
layout
)
return
renderer
.
render_field
(
field
,
template_pack
)
@register.simple_tag
@register.simple_tag
...
...
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