0002-templates-add-support-for-custom-widget-template-546.patch
gadjo/templates/gadjo/form.html | ||
---|---|---|
17 | 17 |
{% endfor %} |
18 | 18 |
</div> |
19 | 19 |
{% endif %} |
20 |
{% for field in form %}
|
|
20 |
{% for field, widget_template in fields_with_templates %}
|
|
21 | 21 |
{% if field.is_hidden %} |
22 | 22 |
{{ field }} |
23 | 23 |
{% else %} |
24 |
{% include "gadjo/widget.html" with field=field %}
|
|
24 |
{% include widget_template with field=field %}
|
|
25 | 25 |
{% endif %} |
26 | 26 |
{% endfor %} |
gadjo/templates/gadjo/widget.html | ||
---|---|---|
16 | 16 |
</div> |
17 | 17 |
{% endblock %} |
18 | 18 |
{% block widget-content %} |
19 |
<div class="content" aria-labelledby="{{ field.name }}"> |
|
19 |
<div class="content" aria-labelledby="{{ field.name }}" {% block widget-attrs %}{% endblock %}>
|
|
20 | 20 |
{% block widget-error %} |
21 | 21 |
{% if field.errors %} |
22 | 22 |
<div class="error"> |
gadjo/templatetags/gadjo.py | ||
---|---|---|
122 | 122 |
@register.filter |
123 | 123 |
def with_template(form): |
124 | 124 |
form_template = template.loader.get_template('gadjo/form.html') |
125 |
return form_template.render({'form': form}) |
|
125 |
fields_with_templates = [] |
|
126 |
for field in form: |
|
127 |
templates = ['gadjo/%s-widget.html' % field.field.widget.input_type, 'gadjo/widget.html'] |
|
128 |
fields_with_templates.append( |
|
129 |
( |
|
130 |
field, |
|
131 |
template.loader.select_template(templates), |
|
132 |
) |
|
133 |
) |
|
134 |
return form_template.render({'form': form, 'fields_with_templates': fields_with_templates}) |
|
126 | 135 | |
127 | 136 | |
128 | 137 |
# pattern to transform Django camel case class names to CSS class names with |
129 |
- |