diff --git a/elections/migrations/0030_auto_20210619_1845.py b/elections/migrations/0030_auto_20210619_1845.py new file mode 100644 index 0000000..1470675 --- /dev/null +++ b/elections/migrations/0030_auto_20210619_1845.py @@ -0,0 +1,29 @@ +# Generated by Django 3.2.4 on 2021-06-19 16:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("elections", "0029_alter_election_visible"), + ] + + operations = [ + migrations.AddField( + model_name="user", + name="has_valid_email", + field=models.BooleanField( + default=None, null=True, verbose_name="email valide" + ), + ), + migrations.AlterField( + model_name="election", + name="sent_mail", + field=models.BooleanField( + default=False, + null=True, + verbose_name="mail avec les identifiants envoyé", + ), + ), + ] diff --git a/elections/models.py b/elections/models.py index cdc02e2..7fed2d2 100644 --- a/elections/models.py +++ b/elections/models.py @@ -50,7 +50,7 @@ class Election(models.Model): ) sent_mail = models.BooleanField( - _("mail avec les identifiants envoyé"), default=False + _("mail avec les identifiants envoyé"), null=True, default=False ) created_by = models.ForeignKey( @@ -222,6 +222,7 @@ class User(AbstractUser): on_delete=models.CASCADE, ) full_name = models.CharField(_("Nom et Prénom"), max_length=150, blank=True) + has_valid_email = models.BooleanField(_("email valide"), null=True, default=None) @property def base_username(self): diff --git a/elections/tasks.py b/elections/tasks.py index fe7a859..0401872 100644 --- a/elections/tasks.py +++ b/elections/tasks.py @@ -1,2 +1,13 @@ -def send_election_mail(election): - pass +from celery import shared_task + +from .models import Election +from .utils import send_mail + + +@shared_task +def send_election_mail(election_pk, subject, body): + election = Election.objects.get(pk=election_pk) + send_mail(election, subject, body) + election.sent_mail = False + election.save() + # election.sent_mail = True diff --git a/elections/templates/elections/upload_voters.html b/elections/templates/elections/upload_voters.html index a657596..fb8baab 100644 --- a/elections/templates/elections/upload_voters.html +++ b/elections/templates/elections/upload_voters.html @@ -29,7 +29,7 @@