From 50453a799a979b7ae1f91b1bf4e094801d728854 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Thu, 27 May 2021 00:34:36 +0200 Subject: [PATCH] On utilise un template commun pour des formulaires --- .../templates/elections/delete_vote.html | 33 ++----------------- .../templates/elections/election_create.html | 13 ++------ .../templates/elections/election_update.html | 30 ++--------------- .../templates/elections/mail_voters.html | 32 ++---------------- .../templates/elections/option_update.html | 32 ++---------------- .../templates/elections/question_update.html | 32 ++---------------- elections/templatetags/bulma_utils.py | 5 +++ shared/templates/forms/common-form.html | 31 +++++++++++++++++ 8 files changed, 52 insertions(+), 156 deletions(-) create mode 100644 shared/templates/forms/common-form.html diff --git a/elections/templates/elections/delete_vote.html b/elections/templates/elections/delete_vote.html index bb829e8..649c568 100644 --- a/elections/templates/elections/delete_vote.html +++ b/elections/templates/elections/delete_vote.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load i18n %} +{% load i18n bulma_utils %} {% block content %} @@ -7,34 +7,7 @@

{% trans "Supprimer un vote" %}


-
-
-
- {% csrf_token %} - - {% include "forms/form.html" %} - -
-
- -
- - -
-
-
-
+{% url 'election.voters' election.pk as r_url %} +{% include "forms/common-form.html" with c_size="is-half" r_anchor="v_"|concatenate:anchor %} {% endblock %} diff --git a/elections/templates/elections/election_create.html b/elections/templates/elections/election_create.html index 4704c35..f756070 100644 --- a/elections/templates/elections/election_create.html +++ b/elections/templates/elections/election_create.html @@ -31,16 +31,7 @@

{% trans "Création d'une élection" %}


-
- {% csrf_token %} - - {% include "forms/form.html" with errors=False %} - -
-
- -
-
-
+{% url 'election.list' as r_url %} +{% include "forms/common-form.html" with c_size="is-12" errors=False %} {% endblock %} diff --git a/elections/templates/elections/election_update.html b/elections/templates/elections/election_update.html index bb1e378..50d886c 100644 --- a/elections/templates/elections/election_update.html +++ b/elections/templates/elections/election_update.html @@ -31,33 +31,7 @@

{% trans "Modification d'une élection" %}


-
-
-
- {% csrf_token %} - - {% include "forms/form.html" with errors=False %} - -
-
- -
- -
-
-
-
+{% url 'election.admin' election.pk as r_url %} +{% include "forms/common-form.html" with errors=False %} {% endblock %} diff --git a/elections/templates/elections/mail_voters.html b/elections/templates/elections/mail_voters.html index 3ec13cb..9aa5b34 100644 --- a/elections/templates/elections/mail_voters.html +++ b/elections/templates/elections/mail_voters.html @@ -18,34 +18,8 @@ -
-
-
- {% csrf_token %} - - {% include "forms/form.html" %} - -
-
- -
- - -
-
-
-
+{% url 'election.upload-voters' election.pk as r_url %} +{% trans "Envoyer" as f_submit %} +{% include "forms/common-form.html" %} {% endblock %} diff --git a/elections/templates/elections/option_update.html b/elections/templates/elections/option_update.html index 1e09e91..a4b2f00 100644 --- a/elections/templates/elections/option_update.html +++ b/elections/templates/elections/option_update.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load i18n static %} +{% load i18n static bulma_utils %} {% block content %} @@ -13,33 +13,7 @@

{% trans "Modification d'une option" %}


-
-
-
- {% csrf_token %} - - {% include "forms/form.html" with errors=False %} - -
-
- -
- -
-
-
-
+{% url 'election.admin' option.question.election.pk as r_url %} +{% include "forms/common-form.html" with anchor=o_|concatenate:option.pk %} {% endblock %} diff --git a/elections/templates/elections/question_update.html b/elections/templates/elections/question_update.html index ee607af..a7f0d7a 100644 --- a/elections/templates/elections/question_update.html +++ b/elections/templates/elections/question_update.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load i18n static %} +{% load i18n static bulma_utils %} {% block content %} @@ -13,33 +13,7 @@

{% trans "Modification d'une question" %}


-
-
-
- {% csrf_token %} - - {% include "forms/form.html" with errors=False %} - -
-
- -
- -
-
-
-
+{% url 'election.admin' question.election.pk as r_url %} +{% include "forms/common-form.html" with errors=False r_anchor="q_"|concatenate:question.pk %} {% endblock %} diff --git a/elections/templatetags/bulma_utils.py b/elections/templatetags/bulma_utils.py index e0e15e2..6507d77 100644 --- a/elections/templatetags/bulma_utils.py +++ b/elections/templatetags/bulma_utils.py @@ -72,3 +72,8 @@ def bulma_message_tag(tag): return "danger" return tag + + +@register.filter +def concatenate(a, b): + return str(a) + str(b) diff --git a/shared/templates/forms/common-form.html b/shared/templates/forms/common-form.html new file mode 100644 index 0000000..af1d6b7 --- /dev/null +++ b/shared/templates/forms/common-form.html @@ -0,0 +1,31 @@ +{% load i18n %} + +
+
+
+ {% csrf_token %} + + {% include "forms/form.html" %} + +
+
+ +
+ + +
+
+
+