use send_mass_custom_mail_wrapper for bda notifications
This commit is contained in:
parent
2c53344f1f
commit
12c10847e7
2 changed files with 46 additions and 27 deletions
20
bda/admin.py
20
bda/admin.py
|
@ -1,6 +1,5 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from custommail.shortcuts import send_mass_custom_mail
|
|
||||||
from dal.autocomplete import ModelSelect2
|
from dal.autocomplete import ModelSelect2
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
@ -20,6 +19,8 @@ from bda.models import (
|
||||||
Tirage,
|
Tirage,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from utils.mailutils import send_mass_custom_mail_wrapper, SendMassMailRecipientRefused
|
||||||
|
|
||||||
|
|
||||||
class ReadOnlyMixin(object):
|
class ReadOnlyMixin(object):
|
||||||
readonly_fields_update = ()
|
readonly_fields_update = ()
|
||||||
|
@ -142,13 +143,24 @@ class ParticipantAdmin(ReadOnlyMixin, admin.ModelAdmin):
|
||||||
context["places"] = attribs
|
context["places"] = attribs
|
||||||
print(context)
|
print(context)
|
||||||
datatuple.append((shortname, context, "bda@ens.fr", [member.user.email]))
|
datatuple.append((shortname, context, "bda@ens.fr", [member.user.email]))
|
||||||
send_mass_custom_mail(datatuple)
|
|
||||||
count = len(queryset.all())
|
count = len(queryset.all())
|
||||||
|
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:
|
if count == 1:
|
||||||
message_bit = "1 membre a"
|
message_bit = "[1/{}] membre a".format(len(queryset.all()))
|
||||||
plural = ""
|
plural = ""
|
||||||
else:
|
else:
|
||||||
message_bit = "%d membres ont" % count
|
message_bit = "[{}/{}] membres ont".format(count, queryset.all())
|
||||||
plural = "s"
|
plural = "s"
|
||||||
self.message_user(
|
self.message_user(
|
||||||
request, "%s été informé%s avec succès." % (message_bit, plural)
|
request, "%s été informé%s avec succès." % (message_bit, plural)
|
||||||
|
|
|
@ -3,7 +3,6 @@ import random
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from custommail.models import CustomMail
|
from custommail.models import CustomMail
|
||||||
from custommail.shortcuts import send_mass_custom_mail
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
|
@ -12,6 +11,8 @@ from django.db import models
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from django.utils import formats, timezone
|
from django.utils import formats, timezone
|
||||||
|
|
||||||
|
from utils.mailutils import send_mass_custom_mail_wrapper
|
||||||
|
|
||||||
|
|
||||||
def get_generic_user():
|
def get_generic_user():
|
||||||
generic, _ = User.objects.get_or_create(
|
generic, _ = User.objects.get_or_create(
|
||||||
|
@ -125,7 +126,9 @@ class Spectacle(models.Model):
|
||||||
)
|
)
|
||||||
for member in members
|
for member in members
|
||||||
]
|
]
|
||||||
send_mass_custom_mail(datatuple)
|
try:
|
||||||
|
send_mass_custom_mail_wrapper(datatuple)
|
||||||
|
finally:
|
||||||
# On enregistre le fait que l'envoi a bien eu lieu
|
# On enregistre le fait que l'envoi a bien eu lieu
|
||||||
self.rappel_sent = timezone.now()
|
self.rappel_sent = timezone.now()
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -343,7 +346,9 @@ class SpectacleRevente(models.Model):
|
||||||
)
|
)
|
||||||
for participant in inscrits
|
for participant in inscrits
|
||||||
]
|
]
|
||||||
send_mass_custom_mail(datatuple)
|
try:
|
||||||
|
send_mass_custom_mail_wrapper(datatuple)
|
||||||
|
finally:
|
||||||
self.notif_sent = True
|
self.notif_sent = True
|
||||||
self.notif_time = timezone.now()
|
self.notif_time = timezone.now()
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -367,7 +372,9 @@ class SpectacleRevente(models.Model):
|
||||||
)
|
)
|
||||||
for participant in inscrits
|
for participant in inscrits
|
||||||
]
|
]
|
||||||
send_mass_custom_mail(datatuple)
|
try:
|
||||||
|
send_mass_custom_mail_wrapper(datatuple)
|
||||||
|
finally:
|
||||||
self.notif_sent = True
|
self.notif_sent = True
|
||||||
self.notif_time = timezone.now()
|
self.notif_time = timezone.now()
|
||||||
# Flag inutile, sauf si l'horloge interne merde
|
# Flag inutile, sauf si l'horloge interne merde
|
||||||
|
|
Loading…
Add table
Reference in a new issue