Remove \r's.
[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         recipients = ['lextalionis@evolution-events.nl']
22         if instance.status == 'D':
23             recipients.append(instance.character.player)
24         notify(recipients, 'influences/email/influence_changed.html', {'influence' : instance, 'created' : created})
25
26 signals.post_save.connect(influence_saved, sender=Influence)
27
28 def comment_saved(**kwargs):
29     if (settings.DEBUG):
30         return
31
32     comment = kwargs['instance']
33
34     # We don't support comment editing, but let's check this anyway
35     if not kwargs['created']:
36         return
37
38     object = comment.content_object
39     if isinstance(object, Influence):
40         recipients = ['lextalionis@evolution-events.nl']
41         if comment.is_public:
42             recipients.append(object.character.player)
43
44         notify(
45             recipients,
46             'influences/email/influence_comment_added.html',
47             {'comment'   : comment, 
48              'influence' : object,
49              'commenter' : comment.user
50             }
51         )
52
53 signals.post_save.connect(comment_saved, sender=ThreadedComment)
54
55 # vim: set sts=4 sw=4 expandtab: