{%- macro m_field(field, horizontal=False, label_width=2, field_width=8) %} {%- set with_label = kwargs.pop('with_label', not field.flags.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 with_label and not (field.is_hidden or field.type in ('CSRFTokenField', 'HiddenField')) %} {%- endif %} {%- if horizontal and standard_field %}
{%- endif %} {%- if field.type == 'CSRFTokenField' %} {{ field() }} {%- 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 %} {{ field.errors|join('
'|safe) }}
{%- 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 #} {%- 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 %}