From eeab71bad90790c4e9fa010aced3367dbb6d33bb Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 12 Apr 2021 14:23:45 +0200 Subject: [PATCH] =?UTF-8?q?On=20renvoie=20sur=20la=20vue=20de=20l'=C3=A9le?= =?UTF-8?q?ction=20si=20on=20essaie=20de=20voter=20sans=20=C3=AAtre=20conn?= =?UTF-8?q?ect=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- elections/views.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/elections/views.py b/elections/views.py index 6857f26..df912d1 100644 --- a/elections/views.py +++ b/elections/views.py @@ -454,6 +454,14 @@ class VoteView(OpenElectionOnlyMixin, DetailView): model = Question template_name = "elections/vote.html" + def dispatch(self, request, *args, **kwargs): + # Si l'utilisateur n'est pas connecté on renvoie sur la vue de l'élection + if not request.user.is_authenticated: + return HttpResponseRedirect( + reverse("election.view", args=[super().get_object().election.pk]) + ) + return super().dispatch(request, *args, **kwargs) + def get_next_url(self): return reverse("election.view", args=[self.object.election.pk])