Merge pull request 'Envoi de mail lors de la création d'un trigramme' (#833) from agroudiev/mail-creation-trigramme into master
Reviewed-on: #833
This commit is contained in:
commit
69976a878a
4 changed files with 42 additions and 3 deletions
|
@ -206,7 +206,7 @@ MAIL_DATA = {
|
|||
"REPLYTO": "cof@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>",
|
||||
"REPLYTO": "La K-Fêt <chefs-k-fet@ens.fr>",
|
||||
},
|
||||
|
|
|
@ -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,32 @@ 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()
|
||||
|
||||
|
||||
def get_deleted_account():
|
||||
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.
|
||||
"""
|
||||
mail_data = settings.MAIL_DATA["rappel_negatif"]
|
||||
mail_data = settings.MAIL_DATA["kfet"]
|
||||
|
||||
email = EmailMessage(
|
||||
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
|
||||
self.last_rappel = timezone.now()
|
||||
self.save()
|
||||
return
|
||||
|
||||
|
||||
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.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(
|
||||
|
|
Loading…
Reference in a new issue