diff options
author | lxf <sng@luxagraf.net> | 2021-10-30 09:42:17 -0400 |
---|---|---|
committer | lxf <sng@luxagraf.net> | 2021-10-30 09:42:17 -0400 |
commit | 0ba68fc83b1651cf5f2d190476be1eb955f24e24 (patch) | |
tree | 42bcb0a2ec9ceadea9cd714b401a84023a910b85 /app/lttr | |
parent | 203479c9b9f69450a913652f9e4874b551d56778 (diff) |
lttr: added notification email for newsletter sign ups
Diffstat (limited to 'app/lttr')
-rw-r--r-- | app/lttr/admin.py | 15 | ||||
-rw-r--r-- | app/lttr/models.py | 25 | ||||
-rw-r--r-- | app/lttr/views.py | 1 |
3 files changed, 38 insertions, 3 deletions
diff --git a/app/lttr/admin.py b/app/lttr/admin.py index 570780c..ad35959 100644 --- a/app/lttr/admin.py +++ b/app/lttr/admin.py @@ -2,7 +2,14 @@ from django.contrib import admin from utils.widgets import AdminImageWidget, LGEntryForm -from .models import NewsletterMailing, OldNewsletterMailing, Subscriber, Newsletter, MailingStatus, PostcardSubscriber +from .models import ( + NewsletterMailing, + OldNewsletterMailing, + Subscriber, + Newsletter, + MailingStatus, + PostcardSubscriber +) @admin.register(Subscriber) class SubscriberAdmin(admin.ModelAdmin): @@ -13,10 +20,12 @@ class SubscriberAdmin(admin.ModelAdmin): class Media: js = ('next-prev-links.js',) + @admin.register(Newsletter) class NewsletterAdmin(admin.ModelAdmin): pass + @admin.register(OldNewsletterMailing) class OldNewsletterMailingAdmin(admin.ModelAdmin): form = LGEntryForm @@ -49,11 +58,13 @@ class OldNewsletterMailingAdmin(admin.ModelAdmin): "all": ("my_styles.css",) } + @admin.register(MailingStatus) class MailingStatusAdmin(admin.ModelAdmin): list_display = ('newsletter_mailing', 'subscriber', 'status', 'creation_date', 'newsletter') list_filter = ('status', 'creation_date', 'newsletter_mailing__newsletter') + @admin.register(NewsletterMailing) class NewsletterMailingAdmin(admin.ModelAdmin): form = LGEntryForm @@ -85,10 +96,10 @@ class NewsletterMailingAdmin(admin.ModelAdmin): "all": ("my_styles.css",) } + @admin.register(PostcardSubscriber) class PostcardSubscriberAdmin(admin.ModelAdmin): list_display = ('name', 'address') class Media: js = ('next-prev-links.js',) - diff --git a/app/lttr/models.py b/app/lttr/models.py index 863d4e4..fe99858 100644 --- a/app/lttr/models.py +++ b/app/lttr/models.py @@ -480,3 +480,28 @@ class PostcardSubscriber(models.Model): def __str__(self): return self.name + class Meta: + verbose_name = _('Postcard Subscriber') + + +def send_notification_email(self, newsletter, message, instance): + recipient_list = ['sng@luxagraf.net',] + subject = _('[%(site)s] New Subscriber to "%(object)s"') % { + 'site': get_current_site(request).name, + 'object': newsletter, + } + send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list, fail_silently=True) + + +@receiver(post_save, sender=PostcardSubscriber) +def post_save_events(sender, update_fields, created, instance, **kwargs): + message = "%s has requested a postcard.\nSend to:\n%s" %(instance.name, instance.address) + send_notification_email("Postcards", message, instance) + + +@receiver(post_save, sender=Subscriber) +def post_save_events(sender, update_fields, created, instance, **kwargs): + if instance.subscribed: + message = "%s has signed up for %s." %(instance.email_field, instance.newsletter) + send_notification_email(instance.newsletter, message, instance) + diff --git a/app/lttr/views.py b/app/lttr/views.py index c6b0434..0d96b2f 100644 --- a/app/lttr/views.py +++ b/app/lttr/views.py @@ -123,4 +123,3 @@ class PostcardSubscribeView(CreateView): def get_success_url(self): return reverse_lazy('lttr:postcard_thanks') - |