1 ##############################################################################
2 # Copyright (c) 2018 Sawyer Bergeron, Parker Berberian, and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from django.db.models.signals import pre_save
11 from django.dispatch import receiver
12 from django.contrib import messages
13 from django.core.mail import send_mail
15 class DispatchHandler():
17 @receiver(pre_save, sender='notifier.Notifier')
18 def dispatch(sender, instance, *args, **kwargs):
20 msg_type = getattr(DispatchHandler, instance.message_type)
22 except AttributeError:
23 instance.msg_sent = 'no dispatcher by given name exists: sending by email'
27 if instance.msg_sent != 'no dispatcher by given name exists: sending by email':
28 instance.msg_sent = 'by email'
29 send_mail(instance.title,instance.content,
30 instance.sender,[instance.user.email_addr], fail_silently=False)
32 def webnotification(instance):
33 instance.msg_sent='by web notification'