Add a field macro to the event creation form

This commit is contained in:
Gergely Polonkai 2018-07-13 11:22:28 +02:00
parent a133218906
commit d06cfaa02e
7 changed files with 49 additions and 74 deletions

View File

@ -0,0 +1,21 @@
{% macro field(field, inline=false) %}
{% if field.errors %}
{% for error in field.errors %}
{{ error }}
{% endfor %}
<br>
{% endif %}
{% if field.widget.input_type != 'checkbox' %}
{{ field.label }}
{% endif %}
{{ field }}
{% if field.widget.input_type == 'checkbox' %}
{{ field.label }}
{% endif %}
{% if not inline %}
<br>
{% endif %}
{% if field.description %}
{{ field.description }}
{% endif %}
{% endmacro %}

View File

@ -1,4 +1,5 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% from '_macros.html' import field %}
{% block content %} {% block content %}
<h1> <h1>
@ -28,9 +29,7 @@
<form method="post"> <form method="post">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{{ form.invitee.errors }} {{ field(form.invitee, inline=true) }}
{{ form.invitee.label }}
{{ form.invitee}}
<button type="submit">{% trans %}Invite{% endtrans %}</button> <button type="submit">{% trans %}Invite{% endtrans %}</button>
</form> </form>

View File

@ -1,41 +1,24 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% from '_macros.html' import field %}
{% block content %} {% block content %}
<h2>Create event</h2>
<form method="post"> <form method="post">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{{ form.errors }} {% if form.errors %}
{% for error in form.errors %}
{{ error }}
{% endfor %}
<br> <br>
{% endif %}
{{ form.title.errors }} {{ field(form.title) }}
{{ form.title.label }} {{ field(form.time_zone) }}
{{ form.title }} {{ field(form.start_time) }}
<br> {{ field(form.end_time) }}
{{ field(form.all_day) }}
{{ form.time_zone.errors }} {{ field(form.description) }}
{{ form.time_zone.label }}
{{ form.time_zone }}
<br>
{{ form.start_time.errors }}
{{ form.start_time.label }}
{{ form.start_time }}
<br>
{{ form.end_time.errors }}
{{ form.end_time.label }}
{{ form.end_time }}
<br>
{{ form.all_day.errors }}
{{ form.all_day.label }}
{{ form.all_day }}
<br>
{{ form.description.errors }}
{{ form.description.label }}
{{ form.description }}
<br>
<button type="submit">{% trans %}Save{% endtrans %}</button> <button type="submit">{% trans %}Save{% endtrans %}</button>
<a href="{{ url_for('hello') }}">Cancel</a> <a href="{{ url_for('hello') }}">Cancel</a>

View File

@ -1,4 +1,5 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% from '_macros.html' import field %}
{% block content %} {% block content %}
<h1>{% trans %}First steps{% endtrans %}</h1> <h1>{% trans %}First steps{% endtrans %}</h1>
@ -13,17 +14,10 @@
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<p> <p>
{{ form.display_name.errors }} {{ field(form.display_name) }}
{{ form.display_name.label }}
{{ form.display_name }}<br>
{{ form.display_name.description }}
</p> </p>
<p> <p>
{{ form.time_zone.errors }} {{ field(form.time_zone) }}
{{ form.time_zone.label }}
{{ form.time_zone }}<br>
{{ form.time_zone.description }}
</p> </p>
<button type="submit">{% trans %}Save{% endtrans %}</button> <button type="submit">{% trans %}Save{% endtrans %}</button>

View File

@ -1,4 +1,5 @@
{% extends 'settings-base.html' %} {% extends 'settings-base.html' %}
{% from '_macros.html' import field %}
{% block content %} {% block content %}
{{ super() }} {{ super() }}
@ -7,15 +8,8 @@
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{{ form.errors }} {{ form.errors }}
{{ form.display_name.errors }} {{ field(form.display_name) }}
{{ form.display_name.label }} {{ field(form.locked) }}
{{ form.display_name }}
<br>
{{ form.locked.errors }}
{{ form.locked.label }}
{{ form.locked}}
<br>
<button type="submit">{% trans %}Save{% endtrans %}</button> <button type="submit">{% trans %}Save{% endtrans %}</button>
</form> </form>

View File

@ -1,29 +1,15 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% from '_macros.html' import field %}
{% block content %} {% block content %}
<form method="post"> <form method="post">
{{ form.errors }} {{ form.errors }}
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{{ form.username.errors }} {{ field(form.username) }}
{{ form.username.label }} {{ field(form.email) }}
{{ form.username }} {{ field(form.password) }}
<br> {{ field(form.password_retype) }}
{{ form.email.errors }}
{{ form.email.label }}
{{ form.email }}
<br>
{{ form.password.errors }}
{{ form.password.label }}
{{ form.password }}
<br>
{{ form.password_retype.errors }}
{{ form.password_retype.label }}
{{ form.password_retype }}
<br>
<button type="submit">{% trans %}Register{% endtrans %}</button> <button type="submit">{% trans %}Register{% endtrans %}</button>
</form> </form>

View File

@ -1,4 +1,5 @@
{% extends 'settings-base.html' %} {% extends 'settings-base.html' %}
{% from '_macros.html' import field %}
{% block content %} {% block content %}
{{ super() }} {{ super() }}
@ -9,10 +10,7 @@
{{ form.errors }} {{ form.errors }}
<br> <br>
{{ form.timezone.errors }} {{ field(form.timezone) }}
{{ form.timezone.label }}
{{ form.timezone}}
<br>
<button type="submit">{% trans %}Save{% endtrans %}</button> <button type="submit">{% trans %}Save{% endtrans %}</button>
<a href="{{ url_for('hello') }}">Cancel</a> <a href="{{ url_for('hello') }}">Cancel</a>