Envoi de mail lors de la création d'un trigramme #833
|
@ -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>",
|
||||||
},
|
},
|
||||||
|
|
|
@ -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,32 @@ 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()
|
||||||
|
|
||||||
agroudiev marked this conversation as resolved
|
|||||||
|
|
||||||
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 +325,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",
|
||||||
|
@ -321,7 +348,6 @@ class AccountNegative(models.Model):
|
||||||
# On enregistre le fait que l'envoi a bien eu lieu
|
# On enregistre le fait que l'envoi a bien eu lieu
|
||||||
self.last_rappel = timezone.now()
|
self.last_rappel = timezone.now()
|
||||||
self.save()
|
self.save()
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
class CheckoutQuerySet(models.QuerySet):
|
class CheckoutQuerySet(models.QuerySet):
|
||||||
|
|
12
kfet/templates/kfet/mails/creation_trigramme.txt
Normal file
12
kfet/templates/kfet/mails/creation_trigramme.txt
Normal 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
|
|
@ -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(
|
||||||
|
|
Loading…
Reference in a new issue
Pas besoin de return