diff --git a/templates/helpers/_forms.html b/templates/helpers/_forms.html new file mode 100644 index 0000000..0742a2b --- /dev/null +++ b/templates/helpers/_forms.html @@ -0,0 +1,19 @@ +{% macro generate_fields(form) -%} + {% for field in form %} + {% if field.type != 'CSRFTokenField' %} +
+ {{ field.label }} + {% if field.type in ('StringField', 'PasswordField') %} + {{ field(class='form-control') }} + {% else %} + {{ field() }} + {% endif %} + {% for error in field.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ field() }} + {% endif %} + {% endfor %} +{%- endmacro %} diff --git a/templates/layouts/master.html b/templates/layouts/master.html index b5abfe3..a4754bc 100644 --- a/templates/layouts/master.html +++ b/templates/layouts/master.html @@ -1,3 +1,4 @@ +{% from 'helpers/_forms.html' import generate_fields with context %} diff --git a/templates/web/edit_contact.html b/templates/web/edit_contact.html index dd177fb..af0bae3 100644 --- a/templates/web/edit_contact.html +++ b/templates/web/edit_contact.html @@ -3,18 +3,7 @@ {% block body %}

Edit contact

- {{ form.csrf_token }} - {% for field in form %} - {% if field.label.text != 'CSRF Token' %} -
- {{ field.label }} - {{ field(class='form-control') }} - {% for error in field.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% endfor %} + {{ generate_fields(form) }}
{% endblock %} diff --git a/templates/web/new_contact.html b/templates/web/new_contact.html index 8ca32e4..2cef33d 100644 --- a/templates/web/new_contact.html +++ b/templates/web/new_contact.html @@ -3,18 +3,7 @@ {% block body %}

New contact

- {{ form.csrf_token }} - {% for field in form %} - {% if field.label.text != 'CSRF Token' %} -
- {{ field.label }} - {{ field(class='form-control', value='') }} - {% for error in field.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% endfor %} + {{ generate_fields(form) }}
{% endblock %}