diff options
Diffstat (limited to 'app/lttr/models.py')
-rw-r--r-- | app/lttr/models.py | 25 |
1 files changed, 25 insertions, 0 deletions
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) + |