Ajout du champ receive_emails_active dans SiteSettings, mise à jour de l'admin, ajout d'un signal pour les notifications par email sur les commentaires, et amélioration des context_processors.
This commit is contained in:
parent
38e4ce2562
commit
acd9f42cea
6 changed files with 40 additions and 4 deletions
|
|
@ -14,7 +14,7 @@ class SiteSettingsAdmin(admin.ModelAdmin):
|
|||
# Petite astuce visuelle pour l'admin
|
||||
fieldsets = (
|
||||
('Général', {
|
||||
'fields': ('site_name', 'site_logo')
|
||||
'fields': ('site_name', 'site_logo', 'receive_emails_active')
|
||||
}),
|
||||
('Réseaux Sociaux', {
|
||||
'fields': ('facebook_url', 'twitter_url', 'youtube_url'),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CoreConfig(AppConfig):
|
||||
name = 'core'
|
||||
|
||||
def ready(self):
|
||||
import courses.signals
|
||||
18
core/migrations/0005_sitesettings_receive_emails_active.py
Normal file
18
core/migrations/0005_sitesettings_receive_emails_active.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 6.0 on 2025-12-17 09:36
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0004_visit'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sitesettings',
|
||||
name='receive_emails_active',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -6,6 +6,7 @@ class SiteSettings(models.Model):
|
|||
site_name = models.CharField(max_length=200, default="Mon Super Site")
|
||||
site_logo = models.ImageField(upload_to='settings/', blank=True)
|
||||
contact_email = models.EmailField(blank=True)
|
||||
receive_emails_active = models.BooleanField(default=True)
|
||||
|
||||
# Réseaux sociaux
|
||||
facebook_url = models.URLField(blank=True)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
from .models import Course
|
||||
from .models import Course, Comment
|
||||
|
||||
def course_list(request):
|
||||
courses = Course.objects.all()
|
||||
return {'courses': courses}
|
||||
|
||||
def courses_comments(request):
|
||||
return {'comments_count': Comment.objects.all()}
|
||||
12
courses/signals.py
Normal file
12
courses/signals.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue