forked from DGNum/gestioCOF
Catch errors while sending K-Fêt reminder emails
This commit is contained in:
parent
1c880b265e
commit
e18873115a
1 changed files with 27 additions and 17 deletions
|
@ -1,4 +1,6 @@
|
||||||
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import smtplib
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -20,6 +22,8 @@ from .auth.models import GenericTeamToken # noqa
|
||||||
from .config import kfet_config
|
from .config import kfet_config
|
||||||
from .utils import to_ukf
|
from .utils import to_ukf
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AccountManager(models.Manager):
|
class AccountManager(models.Manager):
|
||||||
"""Manager for Account Model."""
|
"""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.
|
Envoie un mail de rappel signalant que la personne est en négatif.
|
||||||
"""
|
"""
|
||||||
# On envoie le mail
|
# On envoie le mail
|
||||||
send_mail(
|
try:
|
||||||
"Compte K-Psul négatif",
|
send_mail(
|
||||||
loader.render_to_string(
|
"Compte K-Psul négatif",
|
||||||
"kfet/mails/rappel.txt",
|
loader.render_to_string(
|
||||||
context={
|
"kfet/mails/rappel.txt",
|
||||||
"account": self.account,
|
context={
|
||||||
"neg_amount": -self.account.balance,
|
"account": self.account,
|
||||||
"start_date": self.start,
|
"neg_amount": -self.account.balance,
|
||||||
},
|
"start_date": self.start,
|
||||||
),
|
},
|
||||||
settings.MAIL_DATA["rappel_negatif"]["FROM"],
|
),
|
||||||
[self.account.email],
|
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()
|
# On enregistre le fait que l'envoi a bien eu lieu
|
||||||
self.save()
|
self.last_rappel = timezone.now()
|
||||||
return
|
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):
|
class CheckoutQuerySet(models.QuerySet):
|
||||||
|
|
Loading…
Reference in a new issue