{# Forms macros for rendering forms and fields and stuff in templates. #} {% macro hidden_fields(form) -%} {% for field in form.hidden_fields() %} {% endfor %} {%- endmacro %} {% macro row(_field, label=None, help_text=None, attrs=None) -%}
{% if attrs == None %}{% set attrs = {} %}{% endif %} {% if _field.field.widget.__class__.__name__ == 'ForumTOS' %}{% do attrs.update({'inline': make_tos_label()}) %}{% endif %} {% if _field.field.widget.__class__.__name__ in ('CheckboxInput', 'ForumTOS') %} {% else %} {{ field(_field, attrs=attrs)|trim }} {% endif %} {% for error in _field.errors %}

{{ error }}

{% endfor %} {% if 'inline' in attrs or _field.field.widget.__class__.__name__ not in ('CheckboxInput', 'ForumTOS') %} {% if help_text %}

{{ help_text }}

{% elif _field.help_text %}

{{ _field.help_text }}

{% endif %} {% endif %}
{%- endmacro %} {% macro repeat(form, fields, label=None, help_text=None, attrs=None) -%}
{% if attrs == None %}{% set attrs = ({}, {}) %}{% endif %}
{{ field(fields[0], attrs=attrs[0]) }}
{{ field(fields[1], attrs=attrs[1]) }}
{% for error in form.errors[(fields[0].name ~ '_' ~ fields[1].name)] %}

{{ error }}

{% endfor %} {% for error in fields[0].errors %}

{{ error }}

{% endfor %} {% for error in fields[1].errors %} {% if not error in fields[0].errors %}

{{ error }}

{% endif %} {% endfor %} {% if help_text %}

{{ help_text }}

{% elif fields[0].help_text %}

{{ fields[0].help_text }}

{% endif %} {%- endmacro %} {% macro make_tos_label() -%} {% trans forum_tos=make_tos_link()|safe %}I have read and accept this forums {{forum_tos}}.{% endtrans %} {%- endmacro %} {% macro make_tos_link() -%} {% if settings.tos_title %}{{ settings.tos_title }}{% else %}{% trans %}Terms of Service{% endtrans %}{% endif %} {%- endmacro %} {% macro captcha(form, attrs=None) -%} {% if 'recaptcha' in form.fields %} {{ row(form.recaptcha) }} {% endif %} {% if 'captcha_qa' in form.fields %} {{ row(form.captcha_qa, attrs=attrs) }} {% endif %} {%- endmacro %} {% macro field(_field, attrs=None) -%} {% set widget = _field.field.widget.__class__.__name__ %} {% set context = _field.field.widget.get_context(_field.html_name, _field.value(), attrs=attrs) %} {% if 'inline' in context.attrs %}{% do context.attrs.pop('inline') %}{% endif %} {% if widget == 'Textarea' %} {{ _textarea(_field, context) }} {% elif widget == 'YesNoSwitch' %} {{ _yesno(_field, context) }} {% elif widget == 'Select' %} {{ _select(_field, context) }} {% elif widget == 'RadioSelect' %} {{ _radio_select(_field, context) }} {% elif widget == 'CheckboxSelectMultiple' %} {{ _checkbox_select(_field, context) }} {% elif widget == 'ReCaptchaWidget' %} {{ _field.field.widget.render()|safe }} {% else %} {{ _input(_field, context) }} {% endif %} {%- endmacro %} {% macro attributes(attrs) -%} {% for name, value in attrs.items() %} {{ name }}{% if value != True %}="{{ value }}"{% endif %}{% endfor %} {%- endmacro %} {% macro _input(_field, context) -%} {%- endmacro %} {% macro _textarea(_field, context) -%} {%- endmacro %} {% macro _yesno(_field, context) -%}
{{ _input(_field, context) }}
{%- endmacro %} {% macro _select(_field, context) -%} {%- endmacro %} {% macro _radio_select(_field, context) -%}
{% for option in context['optgroups'][0][1] %} {% endfor %}
{%- endmacro %} {% macro _checkbox_select(_field, context) %}
{% for option in context['optgroups'][0][1] %} {% endfor %}
{% endmacro %}