On renvoie sur la vue de l'élection si on essaie de voter sans être connecté

This commit is contained in:
Tom Hubrecht 2021-04-12 14:23:45 +02:00
parent d3e3ff23ce
commit eeab71bad9

View file

@ -454,6 +454,14 @@ class VoteView(OpenElectionOnlyMixin, DetailView):
model = Question model = Question
template_name = "elections/vote.html" 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): def get_next_url(self):
return reverse("election.view", args=[self.object.election.pk]) return reverse("election.view", args=[self.object.election.pk])