{# @copyright: 2012 Thomas Waldmann, Jason Kirtland, Scott Wilson, Cheer Xiao @license: see flatland license Helpers for using flatland with jinja2 to create html forms. TODO: Several of these macros are not yet used. See utils.html for more macros. #} {% macro render_errors(field) %} {%- if field.errors %}
{%- for error in field.errors %}

{{ error }}

{% endfor %}
{% endif %} {%- endmacro %} {% macro render_submit(form, name=None, value=None) %}
{# needed to add vertical whitespace below floated element #} {%- if name and value %} {% endif %} {{ gen.input(type='submit', value=form.submit_label, class='moin-button', **kwargs) }}
{%- endmacro %} {% macro render(field) %} {%- set macro = { 'text': annotated_input, 'url': annotated_input, 'email': annotated_input, 'password': annotated_input, 'file': annotated_input, 'checkbox': annotated_input, 'multiline_text': multiline_text, 'inline_checkbox': inline_checkbox, 'any_integer': any_integer, 'small_natural': small_natural, 'radio_choice': radio_choice, 'datetime': datetime, 'search': search, 'hidden': raw_input, 'select': select, 'select_submit': select_submit, 'multi_select': multi_select, 'readonly_string_list': readonly_string_list, 'readonly_item_link_list': readonly_item_link_list, }[field.properties.widget] or stub -%} {{ macro(field, *varargs, **kwargs) }} {%- endmacro %} {% macro stub(field) %}
STUB: no widget for {{ field.name }} ({{ field.properties }}) yet
{%- endmacro %} {% macro raw_input(field, type=none) %} {{ gen.input(field, type=type or field.properties.widget, class=field.properties.class_ or '', **kwargs) }} {%- endmacro %} {% macro annotated_input(field, type=none) %} {%- set type = type or field.properties.widget %}
{%- if type == 'checkbox' %} {{ _checkbox_label(field) }} {%- else %} {{ gen.label(field) }} {% endif %}
{{ raw_input(field, type) }} {{ render_errors(field) }} {#- TODO make the helper more explicit and look better #} {%- if field.properties.helper %}

{{ field.properties.helper | e }}

{% endif %}
{%- endmacro %} {% macro multiline_text(field) %}
{{ gen.label(field) }}
{{ gen.textarea(field, rows=field.properties.rows|string, cols=field.properties.cols|string, **kwargs) }} {{ render_errors(field) }}
{%- endmacro %} {% macro _valued_label(field, value, contents=none) %} {#- XXX Patch