diff options
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/renderers.py | 15 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/fields/inline/textarea.html | 6 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/form.html | 33 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/horizontal/fields/checkbox.html (renamed from rest_framework/templates/rest_framework/fields/horizontal/checkbox.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/horizontal/fields/fieldset.html (renamed from rest_framework/templates/rest_framework/fields/horizontal/fieldset.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/horizontal/fields/input.html (renamed from rest_framework/templates/rest_framework/fields/horizontal/input.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/horizontal/fields/list_fieldset.html (renamed from rest_framework/templates/rest_framework/fields/horizontal/list_fieldset.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/horizontal/fields/select.html (renamed from rest_framework/templates/rest_framework/fields/horizontal/select.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/horizontal/fields/select_checkbox.html (renamed from rest_framework/templates/rest_framework/fields/horizontal/select_checkbox.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/horizontal/fields/select_multiple.html (renamed from rest_framework/templates/rest_framework/fields/horizontal/select_multiple.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/horizontal/fields/select_radio.html (renamed from rest_framework/templates/rest_framework/fields/horizontal/select_radio.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/horizontal/fields/textarea.html (renamed from rest_framework/templates/rest_framework/fields/horizontal/textarea.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/horizontal/form.html | 15 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/inline/fields/checkbox.html (renamed from rest_framework/templates/rest_framework/fields/inline/checkbox.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/inline/fields/fieldset.html (renamed from rest_framework/templates/rest_framework/fields/inline/fieldset.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/inline/fields/input.html (renamed from rest_framework/templates/rest_framework/fields/inline/input.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/inline/fields/select.html (renamed from rest_framework/templates/rest_framework/fields/inline/select.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/inline/fields/select_checkbox.html (renamed from rest_framework/templates/rest_framework/fields/inline/select_checkbox.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/inline/fields/select_multiple.html (renamed from rest_framework/templates/rest_framework/fields/inline/select_multiple.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/inline/fields/select_radio.html (renamed from rest_framework/templates/rest_framework/fields/inline/select_radio.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/inline/fields/textarea.html | 6 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/inline/form.html | 11 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/vertical/fields/checkbox.html (renamed from rest_framework/templates/rest_framework/fields/vertical/checkbox.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/vertical/fields/fieldset.html (renamed from rest_framework/templates/rest_framework/fields/vertical/fieldset.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/vertical/fields/input.html (renamed from rest_framework/templates/rest_framework/fields/vertical/input.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/vertical/fields/list_fieldset.html (renamed from rest_framework/templates/rest_framework/fields/vertical/list_fieldset.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/vertical/fields/select.html (renamed from rest_framework/templates/rest_framework/fields/vertical/select.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/vertical/fields/select_checkbox.html (renamed from rest_framework/templates/rest_framework/fields/vertical/select_checkbox.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/vertical/fields/select_multiple.html (renamed from rest_framework/templates/rest_framework/fields/vertical/select_multiple.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/vertical/fields/select_radio.html (renamed from rest_framework/templates/rest_framework/fields/vertical/select_radio.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/vertical/fields/textarea.html (renamed from rest_framework/templates/rest_framework/fields/vertical/textarea.html) | 0 | ||||
| -rw-r--r-- | rest_framework/templates/rest_framework/vertical/form.html | 11 | ||||
| -rw-r--r-- | rest_framework/templatetags/rest_framework.py | 4 |
33 files changed, 49 insertions, 52 deletions
diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 4fb36060..5fae75f2 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -339,7 +339,6 @@ class HTMLFormRenderer(BaseRenderer): """ media_type = 'text/html' format = 'form' - template = 'rest_framework/form.html' charset = 'utf-8' field_templates = ClassLookupDict({ @@ -383,26 +382,21 @@ class HTMLFormRenderer(BaseRenderer): serializers.TimeField: 'time', }) - def render_field(self, field, layout=None): - layout = layout or 'vertical' + def render_field(self, field, template_pack=None): style_type = field.style.get('type', 'default') - if style_type == 'textarea' and layout == 'inline': - style_type = 'default' input_type = self.input_type[field] if input_type == 'datetime-local' and isinstance(field.value, six.text_type): field.value = field.value.rstrip('Z') 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) context = Context({ 'field': field, 'input_type': input_type, 'renderer': self, - 'layout': layout }) - return template.render(context) def render(self, data, accepted_media_type=None, renderer_context=None): @@ -411,11 +405,10 @@ class HTMLFormRenderer(BaseRenderer): """ renderer_context = renderer_context or {} request = renderer_context['request'] - - template = loader.get_template(self.template) + template = loader.get_template('rest_framework/horizontal/form.html') context = RequestContext(request, { 'form': data.serializer, - 'layout': getattr(getattr(data, 'Meta', None), 'layout', 'horizontal'), + 'template_pack': 'rest_framework/horizontal', 'renderer': self }) return template.render(context) diff --git a/rest_framework/templates/rest_framework/fields/inline/textarea.html b/rest_framework/templates/rest_framework/fields/inline/textarea.html deleted file mode 100644 index a644ea38..00000000 --- a/rest_framework/templates/rest_framework/fields/inline/textarea.html +++ /dev/null @@ -1,6 +0,0 @@ -<div class="form-group"> - {% if field.label %} - <label class="sr-only">{{ field.label }}</label> - {% 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> -</div> diff --git a/rest_framework/templates/rest_framework/form.html b/rest_framework/templates/rest_framework/form.html deleted file mode 100644 index 162c5633..00000000 --- a/rest_framework/templates/rest_framework/form.html +++ /dev/null @@ -1,33 +0,0 @@ -<!-- <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 %} -<form {% if layout == "inline" %}class="form-inline"{% elif layout == "horizontal" %}class="form-horizontal"{% endif %} role="form" action="." method="POST"> - {% csrf_token %} - {% for field in form %} - {% if not field.read_only %} - {% render_field field layout=layout renderer=renderer %} - {% endif %} - {% endfor %} - <!-- form.non_field_errors --> - {% if layout == "horizontal" %} - <div class="form-group"> - <div class="col-sm-offset-2 col-sm-10"> - <button type="submit" class="btn btn-default">Submit</button> - </div> - </div> - {% else %} - <button type="submit" class="btn btn-default">Submit</button> - {% endif %} -</form> -<!-- -</div> -</div></body> -</html> --> diff --git a/rest_framework/templates/rest_framework/fields/horizontal/checkbox.html b/rest_framework/templates/rest_framework/horizontal/fields/checkbox.html index ee3bf936..ee3bf936 100644 --- a/rest_framework/templates/rest_framework/fields/horizontal/checkbox.html +++ b/rest_framework/templates/rest_framework/horizontal/fields/checkbox.html diff --git a/rest_framework/templates/rest_framework/fields/horizontal/fieldset.html b/rest_framework/templates/rest_framework/horizontal/fields/fieldset.html index ff93c6ba..ff93c6ba 100644 --- a/rest_framework/templates/rest_framework/fields/horizontal/fieldset.html +++ b/rest_framework/templates/rest_framework/horizontal/fields/fieldset.html diff --git a/rest_framework/templates/rest_framework/fields/horizontal/input.html b/rest_framework/templates/rest_framework/horizontal/fields/input.html index 6621c7e6..6621c7e6 100644 --- a/rest_framework/templates/rest_framework/fields/horizontal/input.html +++ b/rest_framework/templates/rest_framework/horizontal/fields/input.html diff --git a/rest_framework/templates/rest_framework/fields/horizontal/list_fieldset.html b/rest_framework/templates/rest_framework/horizontal/fields/list_fieldset.html index 68c75d4f..68c75d4f 100644 --- a/rest_framework/templates/rest_framework/fields/horizontal/list_fieldset.html +++ b/rest_framework/templates/rest_framework/horizontal/fields/list_fieldset.html diff --git a/rest_framework/templates/rest_framework/fields/horizontal/select.html b/rest_framework/templates/rest_framework/horizontal/fields/select.html index eaa6d575..eaa6d575 100644 --- a/rest_framework/templates/rest_framework/fields/horizontal/select.html +++ b/rest_framework/templates/rest_framework/horizontal/fields/select.html diff --git a/rest_framework/templates/rest_framework/fields/horizontal/select_checkbox.html b/rest_framework/templates/rest_framework/horizontal/fields/select_checkbox.html index ff3fab57..ff3fab57 100644 --- a/rest_framework/templates/rest_framework/fields/horizontal/select_checkbox.html +++ b/rest_framework/templates/rest_framework/horizontal/fields/select_checkbox.html diff --git a/rest_framework/templates/rest_framework/fields/horizontal/select_multiple.html b/rest_framework/templates/rest_framework/horizontal/fields/select_multiple.html index 3ed2874b..3ed2874b 100644 --- a/rest_framework/templates/rest_framework/fields/horizontal/select_multiple.html +++ b/rest_framework/templates/rest_framework/horizontal/fields/select_multiple.html diff --git a/rest_framework/templates/rest_framework/fields/horizontal/select_radio.html b/rest_framework/templates/rest_framework/horizontal/fields/select_radio.html index 6e56afb5..6e56afb5 100644 --- a/rest_framework/templates/rest_framework/fields/horizontal/select_radio.html +++ b/rest_framework/templates/rest_framework/horizontal/fields/select_radio.html diff --git a/rest_framework/templates/rest_framework/fields/horizontal/textarea.html b/rest_framework/templates/rest_framework/horizontal/fields/textarea.html index ae263c48..ae263c48 100644 --- a/rest_framework/templates/rest_framework/fields/horizontal/textarea.html +++ b/rest_framework/templates/rest_framework/horizontal/fields/textarea.html diff --git a/rest_framework/templates/rest_framework/horizontal/form.html b/rest_framework/templates/rest_framework/horizontal/form.html new file mode 100644 index 00000000..7560d8a2 --- /dev/null +++ b/rest_framework/templates/rest_framework/horizontal/form.html @@ -0,0 +1,15 @@ +{% load rest_framework %} +<form class="form-horizontal" 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 --> + <div class="form-group"> + <div class="col-sm-offset-2 col-sm-10"> + <button type="submit" class="btn btn-default">Submit</button> + </div> + </div> +</form> diff --git a/rest_framework/templates/rest_framework/fields/inline/checkbox.html b/rest_framework/templates/rest_framework/inline/fields/checkbox.html index 57fa5dc0..57fa5dc0 100644 --- a/rest_framework/templates/rest_framework/fields/inline/checkbox.html +++ b/rest_framework/templates/rest_framework/inline/fields/checkbox.html diff --git a/rest_framework/templates/rest_framework/fields/inline/fieldset.html b/rest_framework/templates/rest_framework/inline/fields/fieldset.html index ba9f1835..ba9f1835 100644 --- a/rest_framework/templates/rest_framework/fields/inline/fieldset.html +++ b/rest_framework/templates/rest_framework/inline/fields/fieldset.html diff --git a/rest_framework/templates/rest_framework/fields/inline/input.html b/rest_framework/templates/rest_framework/inline/fields/input.html index bdf25ffe..bdf25ffe 100644 --- a/rest_framework/templates/rest_framework/fields/inline/input.html +++ b/rest_framework/templates/rest_framework/inline/fields/input.html diff --git a/rest_framework/templates/rest_framework/fields/inline/select.html b/rest_framework/templates/rest_framework/inline/fields/select.html index 730fcce6..730fcce6 100644 --- a/rest_framework/templates/rest_framework/fields/inline/select.html +++ b/rest_framework/templates/rest_framework/inline/fields/select.html diff --git a/rest_framework/templates/rest_framework/fields/inline/select_checkbox.html b/rest_framework/templates/rest_framework/inline/fields/select_checkbox.html index cca71d68..cca71d68 100644 --- a/rest_framework/templates/rest_framework/fields/inline/select_checkbox.html +++ b/rest_framework/templates/rest_framework/inline/fields/select_checkbox.html diff --git a/rest_framework/templates/rest_framework/fields/inline/select_multiple.html b/rest_framework/templates/rest_framework/inline/fields/select_multiple.html index 3f9b2701..3f9b2701 100644 --- a/rest_framework/templates/rest_framework/fields/inline/select_multiple.html +++ b/rest_framework/templates/rest_framework/inline/fields/select_multiple.html diff --git a/rest_framework/templates/rest_framework/fields/inline/select_radio.html b/rest_framework/templates/rest_framework/inline/fields/select_radio.html index 3fffceac..3fffceac 100644 --- a/rest_framework/templates/rest_framework/fields/inline/select_radio.html +++ b/rest_framework/templates/rest_framework/inline/fields/select_radio.html diff --git a/rest_framework/templates/rest_framework/inline/fields/textarea.html b/rest_framework/templates/rest_framework/inline/fields/textarea.html new file mode 100644 index 00000000..bdf25ffe --- /dev/null +++ b/rest_framework/templates/rest_framework/inline/fields/textarea.html @@ -0,0 +1,6 @@ +<div class="form-group"> + {% if field.label %} + <label class="sr-only">{{ field.label }}</label> + {% endif %} + <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> diff --git a/rest_framework/templates/rest_framework/inline/form.html b/rest_framework/templates/rest_framework/inline/form.html new file mode 100644 index 00000000..b13d1661 --- /dev/null +++ b/rest_framework/templates/rest_framework/inline/form.html @@ -0,0 +1,11 @@ +{% 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> diff --git a/rest_framework/templates/rest_framework/fields/vertical/checkbox.html b/rest_framework/templates/rest_framework/vertical/fields/checkbox.html index 9fd4cdaa..9fd4cdaa 100644 --- a/rest_framework/templates/rest_framework/fields/vertical/checkbox.html +++ b/rest_framework/templates/rest_framework/vertical/fields/checkbox.html diff --git a/rest_framework/templates/rest_framework/fields/vertical/fieldset.html b/rest_framework/templates/rest_framework/vertical/fields/fieldset.html index 248fe904..248fe904 100644 --- a/rest_framework/templates/rest_framework/fields/vertical/fieldset.html +++ b/rest_framework/templates/rest_framework/vertical/fields/fieldset.html diff --git a/rest_framework/templates/rest_framework/fields/vertical/input.html b/rest_framework/templates/rest_framework/vertical/fields/input.html index 10a576b2..10a576b2 100644 --- a/rest_framework/templates/rest_framework/fields/vertical/input.html +++ b/rest_framework/templates/rest_framework/vertical/fields/input.html diff --git a/rest_framework/templates/rest_framework/fields/vertical/list_fieldset.html b/rest_framework/templates/rest_framework/vertical/fields/list_fieldset.html index 6b99a834..6b99a834 100644 --- a/rest_framework/templates/rest_framework/fields/vertical/list_fieldset.html +++ b/rest_framework/templates/rest_framework/vertical/fields/list_fieldset.html diff --git a/rest_framework/templates/rest_framework/fields/vertical/select.html b/rest_framework/templates/rest_framework/vertical/fields/select.html index b0545f7e..b0545f7e 100644 --- a/rest_framework/templates/rest_framework/fields/vertical/select.html +++ b/rest_framework/templates/rest_framework/vertical/fields/select.html diff --git a/rest_framework/templates/rest_framework/fields/vertical/select_checkbox.html b/rest_framework/templates/rest_framework/vertical/fields/select_checkbox.html index c486b1b3..c486b1b3 100644 --- a/rest_framework/templates/rest_framework/fields/vertical/select_checkbox.html +++ b/rest_framework/templates/rest_framework/vertical/fields/select_checkbox.html diff --git a/rest_framework/templates/rest_framework/fields/vertical/select_multiple.html b/rest_framework/templates/rest_framework/vertical/fields/select_multiple.html index ca63192e..ca63192e 100644 --- a/rest_framework/templates/rest_framework/fields/vertical/select_multiple.html +++ b/rest_framework/templates/rest_framework/vertical/fields/select_multiple.html diff --git a/rest_framework/templates/rest_framework/fields/vertical/select_radio.html b/rest_framework/templates/rest_framework/vertical/fields/select_radio.html index d7655b00..d7655b00 100644 --- a/rest_framework/templates/rest_framework/fields/vertical/select_radio.html +++ b/rest_framework/templates/rest_framework/vertical/fields/select_radio.html diff --git a/rest_framework/templates/rest_framework/fields/vertical/textarea.html b/rest_framework/templates/rest_framework/vertical/fields/textarea.html index 8d951496..8d951496 100644 --- a/rest_framework/templates/rest_framework/fields/vertical/textarea.html +++ b/rest_framework/templates/rest_framework/vertical/fields/textarea.html diff --git a/rest_framework/templates/rest_framework/vertical/form.html b/rest_framework/templates/rest_framework/vertical/form.html new file mode 100644 index 00000000..fe908af0 --- /dev/null +++ b/rest_framework/templates/rest_framework/vertical/form.html @@ -0,0 +1,11 @@ +{% 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> diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index 49a4c338..c092d39f 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -32,8 +32,8 @@ class_re = re.compile(r'(?<=class=["\'])(.*)(?=["\'])') # And the template tags themselves... @register.simple_tag -def render_field(field, layout=None, renderer=None): - return renderer.render_field(field, layout) +def render_field(field, template_pack=None, renderer=None): + return renderer.render_field(field, template_pack) @register.simple_tag |
