kadenios/elections/tasks.py

20 lines
548 B
Python

from background_task import background
from .models import Election
from .utils import send_mail
@background
def send_election_mail(election_pk: int, subject: str, body: str, reply_to: str):
election = Election.objects.get(pk=election_pk)
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()