Nouveau mixin pour travailler avec des élections terminées
This commit is contained in:
parent
da43ecbffe
commit
fdab401eb3
2 changed files with 17 additions and 13 deletions
|
@ -82,5 +82,17 @@ class CreatorOnlyEditMixin(CreatorOnlyMixin, SingleObjectMixin):
|
|||
return filters
|
||||
|
||||
|
||||
class ClosedElectionMixin(CreatorOnlyMixin, SingleObjectMixin):
|
||||
"""Permet d'agir sur une élection terminée"""
|
||||
|
||||
def get_filters(self):
|
||||
f_prefix = self.get_f_prefix()
|
||||
# L'élection doit être terminée et non archivée
|
||||
filters = super().get_filters()
|
||||
filters[f_prefix + "end_date__lt"] = timezone.now()
|
||||
filters[f_prefix + "archived"] = False
|
||||
return filters
|
||||
|
||||
|
||||
class VoterOnlyMixin:
|
||||
"""Restreint l'accès aux voteureuses de l'élection"""
|
||||
|
|
|
@ -16,7 +16,6 @@ from django.views.generic import (
|
|||
RedirectView,
|
||||
UpdateView,
|
||||
)
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
|
||||
from .forms import (
|
||||
ElectionForm,
|
||||
|
@ -28,6 +27,7 @@ from .forms import (
|
|||
)
|
||||
from .mixins import (
|
||||
AdminOnlyMixin,
|
||||
ClosedElectionMixin,
|
||||
CreatorOnlyEditMixin,
|
||||
CreatorOnlyMixin,
|
||||
OpenElectionOnlyMixin,
|
||||
|
@ -173,7 +173,7 @@ class ElectionUpdateView(CreatorOnlyEditMixin, SuccessMessageMixin, UpdateView):
|
|||
return reverse("election.admin", args=[self.object.pk])
|
||||
|
||||
|
||||
class ElectionTallyView(CreatorOnlyMixin, SingleObjectMixin, BackgroundUpdateView):
|
||||
class ElectionTallyView(ClosedElectionMixin, BackgroundUpdateView):
|
||||
model = Election
|
||||
pattern_name = "election.admin"
|
||||
success_message = _("Élection dépouillée avec succès !")
|
||||
|
@ -182,7 +182,7 @@ class ElectionTallyView(CreatorOnlyMixin, SingleObjectMixin, BackgroundUpdateVie
|
|||
return (
|
||||
super()
|
||||
.get_queryset()
|
||||
.filter(end_date__lt=timezone.now(), tallied=False)
|
||||
.filter(tallied=False)
|
||||
.prefetch_related("questions__options")
|
||||
)
|
||||
|
||||
|
@ -196,9 +196,7 @@ class ElectionTallyView(CreatorOnlyMixin, SingleObjectMixin, BackgroundUpdateVie
|
|||
return super().get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class ElectionChangePublicationView(
|
||||
CreatorOnlyMixin, SingleObjectMixin, BackgroundUpdateView
|
||||
):
|
||||
class ElectionChangePublicationView(ClosedElectionMixin, BackgroundUpdateView):
|
||||
model = Election
|
||||
pattern_name = "election.admin"
|
||||
|
||||
|
@ -207,9 +205,6 @@ class ElectionChangePublicationView(
|
|||
return _("Élection publiée avec succès !")
|
||||
return _("Élection dépubliée avec succès !")
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(end_date__lt=timezone.now())
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.election = self.get_object()
|
||||
self.election.results_public = not self.election.results_public
|
||||
|
@ -217,14 +212,11 @@ class ElectionChangePublicationView(
|
|||
return super().get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class ElectionArchiveView(CreatorOnlyMixin, SingleObjectMixin, BackgroundUpdateView):
|
||||
class ElectionArchiveView(ClosedElectionMixin, BackgroundUpdateView):
|
||||
model = Election
|
||||
pattern_name = "election.admin"
|
||||
success_message = _("Élection archivée avec succès !")
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(end_date__lt=timezone.now())
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
election = self.get_object()
|
||||
election.archived = True
|
||||
|
|
Loading…
Reference in a new issue