Send influence notifications to all players involved.
[matthijs/projects/xerxes.git] / influences / notify.py
index 86a5047c63a4215dd00317c1f74af708fd140eb2..2e719de41c6f83b539d5a9daa4f4c5c78f0685f9 100644 (file)
@@ -4,6 +4,7 @@ from django.conf import settings
 from xerxes.influences.models import Character,Influence
 from xerxes.tools.notify import notify
 from django.contrib.auth.models import Group
+from threadedcomments.models import ThreadedComment
 
 def character_saved(**kwargs):
     instance = kwargs['instance']
@@ -18,8 +19,33 @@ def influence_saved(**kwargs):
     created  = kwargs['created']
     if (not settings.DEBUG):
         # TODO: Perhaps only notify when the status is / becomes Done?
-        notify([instance.character.player, 'lextalionis@evolution-events.nl'], 'influences/email/influence_changed.html', {'influence' : instance, 'created' : created})
+        notify([instance.related_players.keys(), 'lextalionis@evolution-events.nl'], 'influences/email/influence_changed.html', {'influence' : instance, 'created' : created})
 
-signals.post_save.connect(influence_saved, sender=Influence)
+def comment_saved(**kwargs):
+    if (settings.DEBUG):
+        return
+
+    comment = kwargs['instance']
+
+    # We don't support comment editing, but let's check this anyway
+    if not kwargs['created']:
+        return
+
+    object = comment.content_object
+    if isinstance(object, Influence):
+        recipients = ['lextalionis@evolution-events.nl']
+        if comment.is_public:
+            recipients.extend(object.related_players.keys())
+
+        notify(
+            recipients,
+            'influences/email/influence_comment_added.html',
+            {'comment'   : comment, 
+             'influence' : object,
+             'commenter' : comment.user
+            }
+        )
+
+signals.post_save.connect(comment_saved, sender=ThreadedComment)
 
 # vim: set sts=4 sw=4 expandtab: