On supprime l'ancienne vue
This commit is contained in:
parent
bca8d03400
commit
0e9b7e82cc
1 changed files with 0 additions and 60 deletions
|
@ -250,66 +250,6 @@ class DeleteVoteView(ClosedElectionMixin, JsonDeleteView):
|
|||
return self.render_to_json(action="delete")
|
||||
|
||||
|
||||
class DeleteVoteViewa(ClosedElectionMixin, FormView):
|
||||
model = Election
|
||||
template_name = "elections/delete_vote.html"
|
||||
form_class = DeleteVoteForm
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("election.voters", args=[self.object.pk]) + "#v_{anchor}".format(
|
||||
**self.kwargs
|
||||
)
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs["voter"] = self.voter
|
||||
return kwargs
|
||||
|
||||
def get_queryset(self):
|
||||
# On n'affiche la page que pour les élections ouvertes à toustes
|
||||
return super().get_queryset().filter(restricted=False)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["anchor"] = self.kwargs["anchor"]
|
||||
return context
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = super().get_object()
|
||||
self.voter = User.objects.get(pk=self.kwargs["user_pk"])
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = super().get_object()
|
||||
self.voter = User.objects.get(pk=self.kwargs["user_pk"])
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
||||
@transaction.atomic
|
||||
def form_valid(self, form):
|
||||
if form.cleaned_data["delete"] == "oui":
|
||||
# On envoie un mail à la personne lui indiquant que le vote est supprimé
|
||||
EmailMessage(
|
||||
subject="Vote removed",
|
||||
body=MAIL_VOTE_DELETED.format(
|
||||
full_name=self.voter.full_name,
|
||||
election_name=self.object.name,
|
||||
),
|
||||
to=[self.voter.email],
|
||||
).send()
|
||||
|
||||
# On supprime les votes
|
||||
Vote.objects.filter(
|
||||
user=self.voter,
|
||||
option__question__election=self.object,
|
||||
).delete()
|
||||
|
||||
# On marque les questions comme non votées
|
||||
self.voter.cast_elections.remove(self.object)
|
||||
self.voter.cast_questions.remove(*list(self.object.questions.all()))
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ElectionTallyView(ClosedElectionMixin, BackgroundUpdateView):
|
||||
model = Election
|
||||
pattern_name = "election.admin"
|
||||
|
|
Loading…
Reference in a new issue