{# @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 %}
{{ gen.label(field) }}
{{ 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 any_integer(field) %} {{ annotated_input(field, 'text') }} {%- endmacro %} {% macro small_natural(field) %}
{{ field['label'] }}
{%- for i in range(field.properties.lower, field.properties.upper+1) %} {{ gen.input(field, type='radio', value=i|string) }} {{ _radio_label(field, value=i|string, class='moin-inline-label') }} {%- endfor %}
{%- endmacro %} {% macro radio_choice(field) %}
{{ field['label'] }}
{%- for id, theme in (field.properties.choices) %} {{ gen.input(field, type='radio', value=id) -}} {{ gen.label(field, value=id, contents=theme, class='moin-inline-label') }} {%- if not loop.last -%}
{% endif -%} {%- endfor %}
{%- endmacro %} {% macro datetime(field) %} {{ annotated_input(field, 'text') }} {%- endmacro %} {% macro search(field) %} {{ raw_input(field, class='moin-search-query') }} {%- endmacro %} {% macro select(field) %}
{{ gen.label(field) }}
{{ gen.select.open(field) }} {%- for value, label in field.properties['choice_specs'] %} {{ gen.option(field, value=value, contents=label or value) }} {% endfor %} {{ gen.select.close() }} {{ render_errors(field) }}
{%- endmacro %} {% macro select_submit(field) %} {%- set labels = field.properties.get('labels', {}) %} {%- for value in field.valid_values %} {{ gen.button(field, type='submit', value=value, contents=labels.get(value, value), id='f_submit_' + value) }} {% endfor %} {%- endmacro %} {% macro multi_select(field) %} {%- for value, label, description in field.member_schema.properties['choice_specs'] %}
  • {{ raw_input(field, 'checkbox', value=value) }} {{ gen.label(field, value=value, contents=label or value) }} {%- if description %} {{ description }} {% endif %}
  • {% endfor %} {{ render_errors(field) }} {%- endmacro %} {% macro readonly_string_list(field) %}
    {{ gen.label(field) }}
    {%- for v in field.value %} {#- TODO style .moin-string-list-item #} {{ v }} {% endfor %}
    {%- endmacro %} {% macro readonly_item_link_list(field) %}
    {{ field['label'] }}
    {%- for v in field.value %} {#- TODO style .moin-item-link-list-item #} {{ v }} {% endfor %}
    {%- endmacro %} {% macro render_file_uploader(submit_url) %} {# pages that use this macro must also use file_uploader_scripts macro below #}

    {%- endmacro %} {% macro file_uploader_scripts() %} {%- endmacro %} {#- Show a list of names that will be affected by a recursive action; delete, destroy, rename #} {%- macro list_subitems(subitem_names, action) %} {%- if subitem_names %}
    {{ action|safe }}
    {%- endif %} {%- endmacro %}