From 4fd9e3a2117f54c4184b02fd3aef31626fcad149 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Thu, 11 Jul 2024 15:02:47 +0200 Subject: [PATCH] feat(elections): Pseudonimize votes after tallying --- elections/tasks.py | 8 ++++++++ elections/views.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/elections/tasks.py b/elections/tasks.py index d6b94bf..b5f564e 100644 --- a/elections/tasks.py +++ b/elections/tasks.py @@ -10,3 +10,11 @@ def send_election_mail(election_pk: int, subject: str, body: str, reply_to: str) send_mail(election, subject, body, reply_to) election.sent_mail = True election.save(update_fields=["sent_mail"]) + + +@background +def pseudonimize_election(election_pk: int): + election = Election.objects.get(pk=election_pk) + + for q in election.questions.all(): + q.pseudonymize() diff --git a/elections/views.py b/elections/views.py index 6b7ebc8..9bc0ace 100644 --- a/elections/views.py +++ b/elections/views.py @@ -41,13 +41,14 @@ from .mixins import ( ) from .models import Election, Option, Question, Vote from .staticdefs import MAIL_VOTE_DELETED, MAIL_VOTERS, QUESTION_TYPES, VOTE_RULES -from .tasks import send_election_mail +from .tasks import pseudonimize_election, send_election_mail from .utils import create_users if TYPE_CHECKING: from elections.typing import User else: from django.contrib.auth import get_user_model + User = get_user_model() # TODO: access control *everywhere* @@ -299,6 +300,9 @@ class ElectionTallyView(ClosedElectionMixin, BackgroundUpdateView): election.tallied = True election.time_tallied = timezone.now() election.save() + + pseudonimize_election(election.pk) + return super().get(request, *args, **kwargs)