Commit 977fbf0f authored by Hamza Dely's avatar Hamza Dely
Browse files

[comptes] Envoi d'un mail lors de la suppression d'un adhérent

parent 6afb9c00
......@@ -7,6 +7,7 @@ from datetime import timedelta
from django.db import models, transaction, IntegrityError
from django.db.models import Q
from django.db.models.signals import post_delete
from django.contrib.auth import get_backends
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
from django.core.mail import send_mail
......@@ -654,7 +655,9 @@ class Adherent(AbstractBaseUser):
Supprime un adhérent.
Dans les faits, celui-ci n'est jamais retiré de la base de données.
"""
email = self.email
shred = kwargs.get('shred', False)
nom, prenom = self.nom, self.prenom
if shred:
self.shred()
......@@ -662,6 +665,7 @@ class Adherent(AbstractBaseUser):
self.supprime = True
self.save()
post_delete.send(self.__class__, instance=self, shred=shred, nom=nom, prenom=prenom)
def shred(self, *args, **kwargs):
"""
......
......@@ -48,3 +48,16 @@ def resize_avatar_if_necessary(sender, instance=None, **kwargs):
image = Image.open(instance.avatar.path)
image.thumbnail(settings.THUMBNAIL_SIZE)
image.save(instance.avatar.path, "PNG")
@receiver(signal.post_delete, sender=Adherent)
def send_mail_after_deletion(sender, instance=None, email=None, nom=None, prenom=None, shred=False, **kwargs):
"""
Envoie un mail pour confirmer la suppression d'un compte à un adhérent.
"""
context = {
'nom' : nom,
'prenom' : prenom,
'shred' : shred,
}
instance.email = email
instance.email_user_from_template('Suppression de ton compte Note Kfet', 'adherent_suppression', context=context)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment