Compare commits

...

1 commit

Author SHA1 Message Date
Martin Pépin e18873115a
Catch errors while sending K-Fêt reminder emails 2021-10-27 14:02:14 +02:00

View file

@ -1,4 +1,6 @@
import logging
import re
import smtplib
from django.conf import settings
from django.contrib.auth.models import User
@ -20,6 +22,8 @@ from .auth.models import GenericTeamToken # noqa
from .config import kfet_config
from .utils import to_ukf
logger = logging.getLogger(__name__)
class AccountManager(models.Manager):
"""Manager for Account Model."""
@ -298,23 +302,29 @@ class AccountNegative(models.Model):
Envoie un mail de rappel signalant que la personne est en négatif.
"""
# On envoie le mail
send_mail(
"Compte K-Psul négatif",
loader.render_to_string(
"kfet/mails/rappel.txt",
context={
"account": self.account,
"neg_amount": -self.account.balance,
"start_date": self.start,
},
),
settings.MAIL_DATA["rappel_negatif"]["FROM"],
[self.account.email],
)
# On enregistre le fait que l'envoi a bien eu lieu
self.last_rappel = timezone.now()
self.save()
return
try:
send_mail(
"Compte K-Psul négatif",
loader.render_to_string(
"kfet/mails/rappel.txt",
context={
"account": self.account,
"neg_amount": -self.account.balance,
"start_date": self.start,
},
),
settings.MAIL_DATA["rappel_negatif"]["FROM"],
[self.account.email],
)
# On enregistre le fait que l'envoi a bien eu lieu
self.last_rappel = timezone.now()
self.save()
except smtplib.SMTPException:
logger.warning(
"L'envoi du mail de rappel pour le négatif de {} a échoué".format(
self.account
)
)
class CheckoutQuerySet(models.QuerySet):