On utilise un template commun pour des formulaires

This commit is contained in:
Tom Hubrecht 2021-05-27 00:34:36 +02:00
parent b9703e6e78
commit 50453a799a
8 changed files with 52 additions and 156 deletions

View file

@ -1,5 +1,5 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n %} {% load i18n bulma_utils %}
{% block content %} {% block content %}
@ -7,34 +7,7 @@
<h1 class="title">{% trans "Supprimer un vote" %}</h1> <h1 class="title">{% trans "Supprimer un vote" %}</h1>
<hr> <hr>
<div class="columns is-centered"> {% url 'election.voters' election.pk as r_url %}
<div class="column is-half"> {% include "forms/common-form.html" with c_size="is-half" r_anchor="v_"|concatenate:anchor %}
<form method="post">
{% csrf_token %}
{% include "forms/form.html" %}
<div class="field is-grouped is-centered">
<div class="control is-expanded">
<button class="button is-fullwidth is-outlined is-primary is-light" type="submit">
<span class="icon">
<i class="fas fa-check"></i>
</span>
<span>{% trans "Enregistrer" %}</span>
</button>
</div>
<div class="control">
<a class="button is-primary" href="{% url 'election.voters' election.pk %}#v_{{ anchor }}">
<span class="icon">
<i class="fas fa-undo-alt"></i>
</span>
<span>{% trans "Retour" %}</span>
</a>
</div>
</div>
</form>
</div>
</div>
{% endblock %} {% endblock %}

View file

@ -31,16 +31,7 @@
<h1 class="title">{% trans "Création d'une élection" %}</h1> <h1 class="title">{% trans "Création d'une élection" %}</h1>
<hr> <hr>
<form action="" method="post"> {% url 'election.list' as r_url %}
{% csrf_token %} {% include "forms/common-form.html" with c_size="is-12" errors=False %}
{% include "forms/form.html" with errors=False %}
<div class="field">
<div class="control">
<button class="button is-fullwidth is-outlined is-primary is-light" type="submit">{% trans "Enregistrer" %}</button>
</div>
</div>
</form>
{% endblock %} {% endblock %}

View file

@ -31,33 +31,7 @@
<h1 class="title">{% trans "Modification d'une élection" %}</h1> <h1 class="title">{% trans "Modification d'une élection" %}</h1>
<hr> <hr>
<div class="columns is-centered"> {% url 'election.admin' election.pk as r_url %}
<div class="column is-two-thirds"> {% include "forms/common-form.html" with errors=False %}
<form action="" method="post">
{% csrf_token %}
{% include "forms/form.html" with errors=False %}
<div class="field is-grouped is-centered">
<div class="control is-expanded">
<button class="button is-fullwidth is-outlined is-primary is-light" type="submit">
<span class="icon">
<i class="fas fa-check"></i>
</span>
<span>{% trans "Enregistrer" %}</span>
</button>
</div>
<div class="control">
<a class="button is-primary" href="{% url 'election.admin' election.pk %}">
<span class="icon">
<i class="fas fa-undo-alt"></i>
</span>
<span>{% trans "Retour" %}</span>
</a>
</div>
</div>
</form>
</div>
</div>
{% endblock %} {% endblock %}

View file

@ -18,34 +18,8 @@
</div> </div>
</div> </div>
<div class="columns is-centered"> {% url 'election.upload-voters' election.pk as r_url %}
<div class="column is-two-thirds"> {% trans "Envoyer" as f_submit %}
<form action="" method="post" enctype="multipart/form-data" id="import-voters"> {% include "forms/common-form.html" %}
{% csrf_token %}
{% include "forms/form.html" %}
<div class="field is-grouped is-centered">
<div class="control is-expanded">
<button class="button is-fullwidth is-outlined is-primary is-light" type="submit">
<span class="icon">
<i class="fas fa-check"></i>
</span>
<span>{% trans "Envoyer" %}</span>
</button>
</div>
<div class="control">
<a class="button is-primary" href="{% url 'election.upload-voters' election.pk %}">
<span class="icon">
<i class="fas fa-undo-alt"></i>
</span>
<span>{% trans "Retour" %}</span>
</a>
</div>
</div>
</form>
</div>
</div>
{% endblock %} {% endblock %}

View file

@ -1,5 +1,5 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n static %} {% load i18n static bulma_utils %}
{% block content %} {% block content %}
@ -13,33 +13,7 @@
<h1 class="title">{% trans "Modification d'une option" %}</h1> <h1 class="title">{% trans "Modification d'une option" %}</h1>
<hr> <hr>
<div class="columns is-centered"> {% url 'election.admin' option.question.election.pk as r_url %}
<div class="column is-two-thirds"> {% include "forms/common-form.html" with anchor=o_|concatenate:option.pk %}
<form action="" method="post">
{% csrf_token %}
{% include "forms/form.html" with errors=False %}
<div class="field is-grouped is-centered">
<div class="control is-expanded">
<button class="button is-fullwidth is-outlined is-primary is-light" type="submit">
<span class="icon">
<i class="fas fa-check"></i>
</span>
<span>{% trans "Enregistrer" %}</span>
</button>
</div>
<div class="control">
<a class="button is-primary" href="{% url 'election.admin' option.question.election.pk %}#o_{{ option.pk }}">
<span class="icon">
<i class="fas fa-undo-alt"></i>
</span>
<span>{% trans "Retour" %}</span>
</a>
</div>
</div>
</form>
</div>
</div>
{% endblock %} {% endblock %}

View file

@ -1,5 +1,5 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n static %} {% load i18n static bulma_utils %}
{% block content %} {% block content %}
@ -13,33 +13,7 @@
<h1 class="title">{% trans "Modification d'une question" %}</h1> <h1 class="title">{% trans "Modification d'une question" %}</h1>
<hr> <hr>
<div class="columns is-centered"> {% url 'election.admin' question.election.pk as r_url %}
<div class="column is-two-thirds"> {% include "forms/common-form.html" with errors=False r_anchor="q_"|concatenate:question.pk %}
<form action="" method="post">
{% csrf_token %}
{% include "forms/form.html" with errors=False %}
<div class="field is-grouped is-centered">
<div class="control is-expanded">
<button class="button is-fullwidth is-outlined is-primary is-light" type="submit">
<span class="icon">
<i class="fas fa-check"></i>
</span>
<span>{% trans "Enregistrer" %}</span>
</button>
</div>
<div class="control">
<a class="button is-primary" href="{% url 'election.admin' question.election.pk %}#q_{{ question.pk }}">
<span class="icon">
<i class="fas fa-undo-alt"></i>
</span>
<span>{% trans "Retour" %}</span>
</a>
</div>
</div>
</form>
</div>
</div>
{% endblock %} {% endblock %}

View file

@ -72,3 +72,8 @@ def bulma_message_tag(tag):
return "danger" return "danger"
return tag return tag
@register.filter
def concatenate(a, b):
return str(a) + str(b)

View file

@ -0,0 +1,31 @@
{% load i18n %}
<div class="columns is-centered">
<div class="column {% if c_size %}{{ c_size }}{% else %}is-two-thirds{% endif %}">
<form action="" method="post">
{% csrf_token %}
{% include "forms/form.html" %}
<div class="field is-grouped is-centered">
<div class="control is-expanded">
<button class="button is-fullwidth is-outlined is-primary is-light" type="submit">
<span class="icon">
<i class="fas fa-{% if f_icon %}{{ f_icon }}{% else %}check{% endif %}"></i>
</span>
<span>{% if f_submit %}{{ f_submit }}{% else %}{% trans "Enregister" %}{% endif %}</span>
</button>
</div>
<div class="control">
<a class="button is-primary" href="{{ r_url }}{% if r_anchor %}#{{ r_anchor }}{% endif %}">
<span class="icon">
<i class="fas fa-undo-alt"></i>
</span>
<span>{% if f_return %}{{ f_return }}{% else %}{% trans "Retour" %}{% endif %}</span>
</a>
</div>
</div>
</form>
</div>
</div>