view MoinMoin/templates/forms.html @ 215:d661d49a46dc

reverted 214:0f501a426b50, it will be solved differently by a filter for the Generator in util.forms
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 07 May 2011 19:33:57 +0200
parents 0f501a426b50
children 62452154e3a0
line wrap: on
line source
{#
Helpers for using flatland with jinja2 to create html forms.

@copyright: Thomas Waldmann, Jason Kirtland, Scott Wilson
@license: see flatland license
#}

{% macro render_errors(field) %}
  {% if field.errors %}
    <ul class="moin-error">
      {% for error in field.errors %}
        <li>{{ error }}</li>
      {% endfor %}
    </ul>
  {% endif %}
{% endmacro %}

{% macro render_field(gen, field, field_type) %}
  {% set f_class = "optional" if field.optional else "required" %}
  <dt>
    {{ gen.label(field, class=f_class) }}
  </dt>
  <dd>
    {{ gen.input(field, class=f_class, type=field_type) }}
    {{ render_errors(field) }}
  </dd>
{% endmacro %}

{% macro render_select(gen, field) %}
  <dt>
    {{ gen.label(field) }}
  </dt>
  <dd>
    {{ gen.select.open(field) }}
    {% set labels = field.properties.get('labels', {}) %}
    {% for value in field.valid_values %}
      {{ gen.option(field, value=value, contents=labels.get(value, value)) }}
    {% endfor %}
    {{ gen.select.close() }}
    {{ render_errors(field) }}
  </dd>
{% endmacro %}

{% macro render_textcha(gen, form) %}
    {% if form.textcha_question.value %}
    <dt>
        {{ gen.label(form.textcha, class="required") }}
    </dt>
    <dd>
        {# The value of -51 below is the sum of signature length, timestamp and a space (see security/textcha.py) #}
        {{ form.textcha_question.value[:-51] }}
        {{ gen.input(form.textcha_question, class=f_class, type='hidden') }}<br />
        {{ gen.input(form.textcha, class="required") }}
        {{ render_errors(form.textcha) }}
    </dd>
    {% endif %}
{% endmacro %}