From 9288daaf9ea4ef1290398e0641c1c8a4e13b1b07 Mon Sep 17 00:00:00 2001 From: Antoine Groudiev Date: Sat, 6 Jul 2024 12:14:49 +0200 Subject: [PATCH] =?UTF-8?q?feat(kfet):=20envoi=20de=20mail=20lors=20de=20l?= =?UTF-8?q?a=20cr=C3=A9ation=20d'un=20trigramme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestioasso/settings/cof_prod.py | 2 +- kfet/models.py | 30 ++++++++++++++++++- .../kfet/mails/creation_trigramme.txt | 12 ++++++++ kfet/views.py | 1 + 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 kfet/templates/kfet/mails/creation_trigramme.txt diff --git a/gestioasso/settings/cof_prod.py b/gestioasso/settings/cof_prod.py index 7e24f936..9e3f9f70 100644 --- a/gestioasso/settings/cof_prod.py +++ b/gestioasso/settings/cof_prod.py @@ -206,7 +206,7 @@ MAIL_DATA = { "REPLYTO": "cof@ens.fr", }, "rappels": {"FROM": "Le BdA ", "REPLYTO": "Le BdA "}, - "rappel_negatif": { + "kfet": { "FROM": "La K-Fêt ", "REPLYTO": "La K-Fêt ", }, diff --git a/kfet/models.py b/kfet/models.py index 0b5b7481..dc3462c2 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -2,6 +2,7 @@ import re from django.conf import settings from django.contrib.auth.models import User +from django.contrib.sites.models import Site from django.core.mail import EmailMessage from django.core.validators import RegexValidator from django.db import models, transaction @@ -269,6 +270,33 @@ class Account(models.Model): def __init__(self, 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(): 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. """ - mail_data = settings.MAIL_DATA["rappel_negatif"] + mail_data = settings.MAIL_DATA["kfet"] email = EmailMessage( subject="Compte K-Psul négatif", diff --git a/kfet/templates/kfet/mails/creation_trigramme.txt b/kfet/templates/kfet/mails/creation_trigramme.txt new file mode 100644 index 00000000..25638186 --- /dev/null +++ b/kfet/templates/kfet/mails/creation_trigramme.txt @@ -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 diff --git a/kfet/views.py b/kfet/views.py index 94e9e5fe..154be949 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -243,6 +243,7 @@ def account_create(request): account_form = AccountNoTriForm(request.POST, instance=account) account_form.save() messages.success(request, "Compte créé : %s" % account.trigramme) + account.send_creation_email() return redirect("kfet.account.create") except Account.UserHasAccount as e: messages.error(