12 lines
705 B
Python
12 lines
705 B
Python
from django.db.models.signals import post_save
|
|
from django.dispatch import receiver
|
|
from django.core.mail import send_mail
|
|
from .models import Comment
|
|
from core.models import SiteSettings
|
|
|
|
@receiver(post_save, sender=Comment)
|
|
def send_email_notification(sender, instance, created, **kwargs):
|
|
if created and SiteSettings.objects.first().receive_emails_active:
|
|
subject = f"Nouveau commentaire sur la leçon - {instance.lesson.name} du cours {instance.lesson.module.course.name}"
|
|
message = f"Le commentaire suivant à été envoyé par {instance.user}:\n{instance.content}"
|
|
send_mail(subject, message, "infos@partirdezero.com", ['anthony.violet@outlook.be'], fail_silently=False)
|