use send_mass_custom_mail_wrapper for bda notifications

This commit is contained in:
Martin Pépin 2019-01-23 18:19:54 +01:00
parent 2c53344f1f
commit 12c10847e7
2 changed files with 46 additions and 27 deletions

View file

@ -1,6 +1,5 @@
from datetime import timedelta
from custommail.shortcuts import send_mass_custom_mail
from dal.autocomplete import ModelSelect2
from django import forms
from django.contrib import admin
@ -20,6 +19,8 @@ from bda.models import (
Tirage,
)
from utils.mailutils import send_mass_custom_mail_wrapper, SendMassMailRecipientRefused
class ReadOnlyMixin(object):
readonly_fields_update = ()
@ -142,17 +143,28 @@ class ParticipantAdmin(ReadOnlyMixin, admin.ModelAdmin):
context["places"] = attribs
print(context)
datatuple.append((shortname, context, "bda@ens.fr", [member.user.email]))
send_mass_custom_mail(datatuple)
count = len(queryset.all())
if count == 1:
message_bit = "1 membre a"
plural = ""
else:
message_bit = "%d membres ont" % count
plural = "s"
self.message_user(
request, "%s été informé%s avec succès." % (message_bit, plural)
)
try:
send_mass_custom_mail_wrapper(datatuple)
except SendMassMailRecipientRefused as exn:
errors, = exn.args
faulty_emails = ", ".join(errors.keys())
count -= len(errors)
self.message_user(
request,
"Les emails suivant causent des erreurs: {}".format(faulty_emails)
)
raise
finally:
if count == 1:
message_bit = "[1/{}] membre a".format(len(queryset.all()))
plural = ""
else:
message_bit = "[{}/{}] membres ont".format(count, queryset.all())
plural = "s"
self.message_user(
request, "%s été informé%s avec succès." % (message_bit, plural)
)
send_attribs.short_description = "Envoyer les résultats par mail"

View file

@ -3,7 +3,6 @@ import random
from datetime import timedelta
from custommail.models import CustomMail
from custommail.shortcuts import send_mass_custom_mail
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
@ -12,6 +11,8 @@ from django.db import models
from django.db.models import Count
from django.utils import formats, timezone
from utils.mailutils import send_mass_custom_mail_wrapper
def get_generic_user():
generic, _ = User.objects.get_or_create(
@ -125,10 +126,12 @@ class Spectacle(models.Model):
)
for member in members
]
send_mass_custom_mail(datatuple)
# On enregistre le fait que l'envoi a bien eu lieu
self.rappel_sent = timezone.now()
self.save()
try:
send_mass_custom_mail_wrapper(datatuple)
finally:
# On enregistre le fait que l'envoi a bien eu lieu
self.rappel_sent = timezone.now()
self.save()
# On renvoie la liste des destinataires
return members
@ -343,10 +346,12 @@ class SpectacleRevente(models.Model):
)
for participant in inscrits
]
send_mass_custom_mail(datatuple)
self.notif_sent = True
self.notif_time = timezone.now()
self.save()
try:
send_mass_custom_mail_wrapper(datatuple)
finally:
self.notif_sent = True
self.notif_time = timezone.now()
self.save()
def mail_shotgun(self):
"""
@ -367,13 +372,15 @@ class SpectacleRevente(models.Model):
)
for participant in inscrits
]
send_mass_custom_mail(datatuple)
self.notif_sent = True
self.notif_time = timezone.now()
# Flag inutile, sauf si l'horloge interne merde
self.tirage_done = True
self.shotgun = True
self.save()
try:
send_mass_custom_mail_wrapper(datatuple)
finally:
self.notif_sent = True
self.notif_time = timezone.now()
# Flag inutile, sauf si l'horloge interne merde
self.tirage_done = True
self.shotgun = True
self.save()
def tirage(self, send_mails=True):
"""