Election creation

This commit is contained in:
Tom Hubrecht 2020-12-19 20:58:38 +01:00
parent 3387186f76
commit b284d65d3e
2 changed files with 17 additions and 3 deletions

View file

@ -29,6 +29,7 @@
{% endfor %} {% endfor %}
<h1 class="title">{% trans "Création d'une élection" %}</h1> <h1 class="title">{% trans "Création d'une élection" %}</h1>
<hr>
<div class="container"> <div class="container">
<form action="" method="post"> <form action="" method="post">
@ -37,9 +38,9 @@
{% include "elections/forms/form.html" with errors=False %} {% include "elections/forms/form.html" with errors=False %}
<div class="field"> <div class="field">
<p class="control"> <div class="control">
<input class="button is-fullwidth" type="submit" value={% trans "Enregistrer" %}> <button class="button is-fullwidth is-outlined is-primary is-light">{% trans "Enregistrer" %}</button>
</p> </div>
</div> </div>
</form> </form>
</div> </div>

View file

@ -4,6 +4,7 @@ from django.db.models import Count, Prefetch
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, DetailView, RedirectView, UpdateView from django.views.generic import CreateView, DetailView, RedirectView, UpdateView
from django.views.generic.detail import SingleObjectMixin from django.views.generic.detail import SingleObjectMixin
@ -20,6 +21,18 @@ class ElectionCreateView(SuccessMessageMixin, CreateView):
template_name = "elections/election_create.html" template_name = "elections/election_create.html"
success_message = _("Élection crée avec succès !") 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 # TODO : only the creator can edit the election and view the admin panel
class ElectionAdminView(DetailView): class ElectionAdminView(DetailView):