From 694a845aae36c739d1ad88242e9269010d1a1096 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Fri, 18 Dec 2020 17:38:44 +0100 Subject: [PATCH] Render the formset correctly --- elections/templates/elections/base.html | 2 +- .../templates/elections/forms/checkbox.html | 16 ++++++++-------- elections/templates/elections/forms/form.html | 2 +- elections/templates/elections/forms/formset.html | 4 ++++ elections/templates/elections/vote.html | 2 +- elections/views.py | 6 +++--- 6 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 elections/templates/elections/forms/formset.html diff --git a/elections/templates/elections/base.html b/elections/templates/elections/base.html index aa18e37..d916c34 100644 --- a/elections/templates/elections/base.html +++ b/elections/templates/elections/base.html @@ -1,4 +1,4 @@ -{% load staticfiles %} +{% load static %} {% load bulma_utils %} {% load i18n %} diff --git a/elections/templates/elections/forms/checkbox.html b/elections/templates/elections/forms/checkbox.html index 109ba75..01c54c1 100644 --- a/elections/templates/elections/forms/checkbox.html +++ b/elections/templates/elections/forms/checkbox.html @@ -1,16 +1,16 @@
{% if field.auto_id %} - + {% endif %} {% for error in field.errors %} - {{ error }} + {{ error }} {% endfor %} {% if field.help_text %} -

- {{ field.help_text|safe }} -

+

+ {{ field.help_text|safe }} +

{% endif %} -
\ No newline at end of file + diff --git a/elections/templates/elections/forms/form.html b/elections/templates/elections/forms/form.html index 2686307..48fa29a 100644 --- a/elections/templates/elections/forms/form.html +++ b/elections/templates/elections/forms/form.html @@ -19,4 +19,4 @@ {% for field in form.visible_fields %} {% include 'elections/forms/field.html' %} -{% endfor %} \ No newline at end of file +{% endfor %} diff --git a/elections/templates/elections/forms/formset.html b/elections/templates/elections/forms/formset.html new file mode 100644 index 0000000..0c7c2b3 --- /dev/null +++ b/elections/templates/elections/forms/formset.html @@ -0,0 +1,4 @@ +{{ formset.management_form }} +{% for form in formset %} +{% include "elections/forms/form.html" %} +{% endfor %} diff --git a/elections/templates/elections/vote.html b/elections/templates/elections/vote.html index f27f786..29ec391 100644 --- a/elections/templates/elections/vote.html +++ b/elections/templates/elections/vote.html @@ -10,7 +10,7 @@
{% csrf_token %} - {{ vote_form }} + {% include "elections/forms/formset.html" %}

diff --git a/elections/views.py b/elections/views.py index 0a3140b..2fe7e7a 100644 --- a/elections/views.py +++ b/elections/views.py @@ -6,7 +6,7 @@ from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.views.generic import CreateView, DetailView, UpdateView -from .forms import OptionFormSet +from .forms import ElectionCreateForm, OptionFormSet from .models import Election, Option, Question # TODO: access control *everywhere* @@ -14,8 +14,8 @@ from .models import Election, Option, Question class ElectionCreateView(SuccessMessageMixin, CreateView): model = Election + form_class = ElectionCreateForm template_name = "elections/election_create.html" - fields = ["name", "description", "start_time", "end_time"] success_message = _("Élection crée avec succès !") @@ -65,7 +65,7 @@ class VoteView(SuccessMessageMixin, DetailView): self.object = self.get_object() vote_form = OptionFormSet(instance=self.object) - return self.render_to_response(self.get_context_data(vote_form=vote_form)) + return self.render_to_response(self.get_context_data(formset=vote_form)) def post(self, request, *args, **kwargs): self.object = self.get_object()