{% load i18n %} {# Render whole form macro #} {%- macro form_widget(form, horizontal=false, width=12) -%}
{{ form_hidden_widget(form) }} {% for fieldset in form.fieldsets %}{% if fieldset.legend %}
{{ fieldset.legend }}{% if fieldset.help %} {{ fieldset.help }}{% endif %}
{% endif %} {% for field in fieldset.fields %} {{ row_widget(field, horizontal=horizontal, width=width) }} {% endfor %}
{% if not fieldset.last %} {% endif %}{% endfor %} {%- endmacro -%} {# Render hidden fields macro #} {%- macro form_hidden_widget(form) -%} {% for field in form.hidden %} {% endfor %} {%- endmacro -%} {# Render form row macro #} {%- macro row_widget(field, horizontal=false, width=12) -%}
{% if field.label %} {% endif %}{% if field.nested %}
{% for subfield in field.nested %}
{{ field_widget(subfield, horizontal=horizontal, width=width, nested=true) }}
{% endfor %}
{% for error in field.errors %}

{{ error }}

{% endfor %}{% if field.help_text %}

{{ field.help_text }}

{% endif %}
{% else %}
{{ field_widget(field, horizontal=horizontal, width=width) }}{% for error in field.errors %}

{{ error }}

{% endfor %}{% if field.help_text %}

{{ field.help_text }}

{% endif %}
{% endif %}
{%- endmacro -%} {# Render form field macro #} {%- macro field_widget(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {%- if field.widget == "checkbox" -%} {{ input_checkbox(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif -%} {%- if field.widget == "date" -%} {{ input_date(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif %} {%- if field.widget == "file_clearable" -%} {{ input_file_clearable(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif -%} {%- if field.widget == "forumTos" -%} {{ input_forum_tos(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif -%} {%- if field.widget == "recaptcha" -%} {{ input_recaptcha(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif -%} {%- if field.widget == "radio_select" -%} {{ input_radio_select(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif -%} {%- if field.widget == "select" -%} {{ input_select(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif -%} {%- if field.widget == "checkbox_select_multiple" -%} {{ input_checkbox_select_multiple(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif -%} {%- if field.widget == "text" -%} {{ input_text(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif -%} {%- if field.widget == "textarea" -%} {{ input_textarea(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif -%} {%- if field.widget == "yes_no_switch" -%} {{ input_yes_no_switch(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }} {%- endif %} {%- endmacro -%} {# Render form field attributes macro #} {%- macro field_attrs(attrs={}, extras=[]) -%} {% for attribute in attrs %} {{ attribute }}="{{ attrs[attribute] }}"{% endfor %}{% for extra in extras %} {{ extra }}{% endfor %} {%- endmacro -%} {# Render form field class attribute macro #} {%- macro field_classes(classes=[]) -%} {% if classes %} class="{% for class in classes %}{% if not loop.first %} {% endif %}{{ class }}{% endfor %}"{% endif %} {%- endmacro -%} {# Checkbox input #} {%- macro input_checkbox(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {%- endmacro -%} {# Forum Terms of Service input #} {%- macro input_forum_tos(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {%- endmacro -%} {%- macro make_tos() -%} {% if settings.tos_title %}{{ settings.tos_title }}{% else %}{% trans %}Terms of Service{% endtrans %}{% endif %} {%- endmacro -%} {# Date input #} {%- macro input_date(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {%- do field.attrs.update(attrs) -%} {%- if horizontal -%} {%- do classes.append('span' ~ (widthratio(field.width, 100, width) - 2)) -%} {%- else -%} {%- do classes.append('span' ~ widthratio(field.width, 100, width)) -%} {%- endif -%} {%- endmacro -%} {# Multiple Checkbox input #} {%- macro input_checkbox_select_multiple(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {%- do field.attrs.update(attrs) -%} {%- do classes.append('select-multiple') -%} {% for choice in field.choices %} {% endfor %} {%- endmacro -%} {# File Upload input #} {%- macro input_file_clearable(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {%- endmacro -%} {# Recaptcha input #} {%- macro input_recaptcha(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {{ field.attrs.html|safe }} {%- endmacro -%} {# RadioSelect input #} {%- macro input_radio_select(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {%- do field.attrs.update(attrs) -%} {%- do classes.append('radio-group') -%} {% for choice in field.choices %} {% endfor %} {%- endmacro -%} {# Select input #} {%- macro input_select(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {%- do field.attrs.update(attrs) -%} {%- if horizontal %} {%- do classes.append('span' ~ (widthratio(field.width, 100, width) - 2)) -%} {%- else -%} {%- do classes.append('span' ~ widthratio(field.width, 100, width)) -%} {%- endif -%} {% for choice in field.choices %} {% endfor %} {%- endmacro -%} {# Text/password input #} {%- macro input_text(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {%- do field.attrs.update(attrs) -%} {%- if horizontal -%} {%- do classes.append('span' ~ (widthratio(field.width, 100, width) - 2)) -%} {%- else -%} {%- do classes.append('span' ~ widthratio(field.width, 100, width)) -%} {%- endif -%} {%- endmacro -%} {# Textarea input #} {%- macro input_textarea(field, attrs={'rows': 4}, classes=[], horizontal=false, width=12, nested=false) -%} {%- do field.attrs.update(attrs) -%} {%- if horizontal -%} {%- do classes.append('span' ~ (widthratio(field.width, 100, width) - 2)) -%} {%- else -%} {%- do classes.append('span' ~ widthratio(field.width, 100, width)) -%} {%- endif -%} {% if field.has_value %}{{ field.value }}{% endif %} {%- endmacro -%} {# YesNoSwitch input #} {%- macro input_yes_no_switch(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%} {%- do field.attrs.update(attrs) -%} {%- do classes.append('yes-no-switch') -%} {%- endmacro -%}