feat(kfet): envoi de mail lors de la création d'un trigramme

This commit is contained in:
Antoine Groudiev 2024-07-06 12:14:49 +02:00
parent e92c500940
commit 9288daaf9e
4 changed files with 43 additions and 2 deletions

View file

@ -206,7 +206,7 @@ MAIL_DATA = {
"REPLYTO": "cof@ens.fr", "REPLYTO": "cof@ens.fr",
}, },
"rappels": {"FROM": "Le BdA <bda@ens.fr>", "REPLYTO": "Le BdA <bda@ens.fr>"}, "rappels": {"FROM": "Le BdA <bda@ens.fr>", "REPLYTO": "Le BdA <bda@ens.fr>"},
"rappel_negatif": { "kfet": {
"FROM": "La K-Fêt <chefs-k-fet@ens.fr>", "FROM": "La K-Fêt <chefs-k-fet@ens.fr>",
"REPLYTO": "La K-Fêt <chefs-k-fet@ens.fr>", "REPLYTO": "La K-Fêt <chefs-k-fet@ens.fr>",
}, },

View file

@ -2,6 +2,7 @@ import re
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.core.mail import EmailMessage from django.core.mail import EmailMessage
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
from django.db import models, transaction from django.db import models, transaction
@ -269,6 +270,33 @@ class Account(models.Model):
def __init__(self, trigramme): def __init__(self, trigramme):
self.trigramme = trigramme self.trigramme = trigramme
def send_creation_email(self):
"""
Envoie un mail à la création du trigramme.
"""
mail_data = settings.MAIL_DATA["kfet"]
email = EmailMessage(
subject="Création d'un trigramme",
body=loader.render_to_string(
"kfet/mails/creation_trigramme.txt",
context={
"account": self,
"site": Site.objects.get_current(),
"url_read": reverse("kfet.account.read", args=(self.trigramme)),
"url_update": reverse("kfet.account.update", args=(self.trigramme)),
"url_delete": reverse("kfet.account.delete", args=(self.trigramme))
},
),
from_email=mail_data["FROM"],
to=[self.email],
reply_to=[mail_data["REPLYTO"]],
)
# On envoie le mail
email.send()
return
def get_deleted_account(): def get_deleted_account():
return Account.objects.get(trigramme=KFET_DELETED_TRIGRAMME) return Account.objects.get(trigramme=KFET_DELETED_TRIGRAMME)
@ -298,7 +326,7 @@ 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.
""" """
mail_data = settings.MAIL_DATA["rappel_negatif"] mail_data = settings.MAIL_DATA["kfet"]
email = EmailMessage( email = EmailMessage(
subject="Compte K-Psul négatif", subject="Compte K-Psul négatif",

View file

@ -0,0 +1,12 @@
Salut {{ account.name }},
Ton compte K-Fêt a bien été créé le {{ account.created_at }} avec le trigramme {{ account.trigramme }}.
Tu peux désormais :
- Accéder à ton historique personnel des consommations : https://{{ site }}{{ url_read }}
- Modifier tes informations : https://{{ site }}{{ url_update }}
- Supprimer ton compte : https://{{ site }}{{ url_delete }}
En espérant te revoir bientôt,
--
L'équipe K-Fêt

View file

@ -243,6 +243,7 @@ def account_create(request):
account_form = AccountNoTriForm(request.POST, instance=account) account_form = AccountNoTriForm(request.POST, instance=account)
account_form.save() account_form.save()
messages.success(request, "Compte créé : %s" % account.trigramme) messages.success(request, "Compte créé : %s" % account.trigramme)
account.send_creation_email()
return redirect("kfet.account.create") return redirect("kfet.account.create")
except Account.UserHasAccount as e: except Account.UserHasAccount as e:
messages.error( messages.error(