1b6fb478253eec2361aa2147acff32354bbe4bb7
[matthijs/projects/xerxes.git] / influences / notify.py
1 from django.db.models import signals
2 from django.dispatch import dispatcher
3 from django.conf import settings
4 from xerxes.influences.models import Character,Influence
5 from xerxes.tools.notify import notify
6 from django.contrib.auth.models import Group
7 from threadedcomments.models import ThreadedComment
8
9 def character_saved(**kwargs):
10     instance = kwargs['instance']
11     created  = kwargs['created']
12     if (not settings.DEBUG):
13         notify([instance.player, 'lextalionis@evolution-events.nl'], 'influences/email/character_changed.html', {'character' : instance, 'created' : created})
14
15 signals.post_save.connect(character_saved, sender=Character)
16
17 def influence_saved(**kwargs):
18     instance = kwargs['instance']
19     created  = kwargs['created']
20     if (not settings.DEBUG):
21         # TODO: Perhaps only notify when the status is / becomes Done?
22         notify([instance.character.player, 'lextalionis@evolution-events.nl'], 'influences/email/influence_changed.html', {'influence' : instance, 'created' : created})
23
24 def comment_saved(**kwargs):
25     if (settings.DEBUG):
26         return
27
28     comment = kwargs['instance']
29
30     # We don't support comment editing, but let's check this anyway
31     if not kwargs['created']:
32         return
33
34     object = comment.content_object
35     if isinstance(object, Influence):
36         recipients = ['lextalionis@evolution-events.nl']
37         if comment.is_public:
38             recipients.append(object.character.player)
39
40         notify(
41             recipients,
42             'influences/email/influence_comment_added.html',
43             {'comment'   : comment, 
44              'influence' : object,
45              'commenter' : comment.user
46             }
47         )
48
49 signals.post_save.connect(comment_saved, sender=ThreadedComment)
50
51 # vim: set sts=4 sw=4 expandtab: