{# edit macros #} {%- macro m_field(field, horizontal=False, label_width=2, field_width=8) %} {%- set is_hidden = field.is_hidden or field.type in ('CSRFTokenField', 'HiddenField') %} {%- set with_label = kwargs.pop('with_label', not is_hidden) %} {%- set placeholder = '' %} {%- if not with_label %} {%- set placeholder = field.label.text %} {%- endif %} {%- set css_class = kwargs.pop('class_', '') %} {%- set standard_field = field.type not in ('CSRFTokenField',) %} {%- if standard_field and field.type not in ('BooleanField',) %} {%- set css_class = 'form-control ' + css_class %} {%- endif %} {%- if field.flags.required %} {%- set css_class = css_class + ' required' %} {%- endif %} {%- if is_hidden %} {{ field(**kwargs) }} {%- else %}
{%- if with_label and not is_hidden %} {%- endif %} {%- if horizontal and standard_field %}
{%- endif %} {%- if field.type == 'CSRFTokenField' %} {{ field(**kwargs) }} {%- elif field.type == 'BooleanField' %} {%- else %} {%- if field.type == 'FileField' %} {%- set css_class = css_class + ' input-file' %} {%- endif %} {{ field(class_=css_class, placeholder=placeholder, **kwargs)|safe }} {%- endif %} {%- if field.errors and not field.form %} {%- if 'FieldList' in field.type %} {% for error in field.errors %} {% if 'dict' in error.__class__.__name__ %} {% if not loop.first %}
{% endif %} {% for key, val in error.iteritems() %} {{ field._field_nameTolabel[key] }} : {{val|join(', ')}} {% endfor %} {% else %} {{ error |safe }} {% endif %} {% endfor %}
{%- else %} {{ field.errors|join('
'|safe) }}
{%- endif %} {%- endif %} {%- if field.description %} {{ field.description|safe }} {%- endif %} {%- if standard_field and horizontal %}
{# when horizontal: close input div; else closes div.col-xs-12 before label #} {%- endif %}
{# form-group #} {%- endif %} {%- endmacro %} {%- macro m_form(form, fields=(), action="", method="POST", enctype="multipart/form-data", horizontal=False, id=None, role="form", label_width=2, field_width=8) %}
{%- for field in (fields or form) %} {{ m_field(field, horizontal=horizontal, label_width=label_width, field_width=field_width) }} {%- endfor %}
{%- for button in g.view.buttons %} {{ button.render() }} {%- endfor %}
{%- endmacro %} {# view macros #} {% macro m_field_view(field, label_width=4, field_width=8) %} {{ field.label }} {{ field.render_view() | safe }} {% endmacro %} {%- macro m_form_view(form, fields=(), id=None, label_width=4, field_width=8) %} {%- for field in (fields or form) %} {{ m_field_view(field, label_width=label_width, field_width=field_width) }} {%- endfor %}
{%- endmacro %}