diff --git a/elections/templates/elections/election_create.html b/elections/templates/elections/election_create.html index 7479283..d07c883 100644 --- a/elections/templates/elections/election_create.html +++ b/elections/templates/elections/election_create.html @@ -29,6 +29,7 @@ {% endfor %}

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

+
@@ -37,9 +38,9 @@ {% include "elections/forms/form.html" with errors=False %}
-

- -

+
+ +
diff --git a/elections/views.py b/elections/views.py index a46e520..f25c07e 100644 --- a/elections/views.py +++ b/elections/views.py @@ -4,6 +4,7 @@ from django.db.models import Count, Prefetch from django.http import HttpResponseRedirect from django.urls import reverse from django.utils import timezone +from django.utils.text import slugify from django.utils.translation import gettext_lazy as _ from django.views.generic import CreateView, DetailView, RedirectView, UpdateView from django.views.generic.detail import SingleObjectMixin @@ -20,6 +21,18 @@ class ElectionCreateView(SuccessMessageMixin, CreateView): template_name = "elections/election_create.html" success_message = _("Élection crée avec succès !") + def get_success_url(self): + return reverse("election.admin", args=[self.object.pk]) + + def form_valid(self, form): + # We need to add the short name and the creator od the election + form.instance.short_name = slugify( + str(form.instance.start_date.year) + "_" + form.instance.name + )[:50] + # TODO: Change this if we modify the user model + form.instance.created_by = self.request.user + return super().form_valid(form) + # TODO : only the creator can edit the election and view the admin panel class ElectionAdminView(DetailView):