Send a notification on comment creation.
authorMatthijs Kooijman <matthijs@stdin.nl>
Fri, 31 Oct 2008 20:23:04 +0000 (21:23 +0100)
committerMatthijs Kooijman <matthijs@stdin.nl>
Fri, 31 Oct 2008 20:23:04 +0000 (21:23 +0100)
influences/notify.py

index 86a5047c63a4215dd00317c1f74af708fd140eb2..e5c763ae36b40dea3d20b39d324233b8aad15378 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']
@@ -20,6 +21,26 @@ def influence_saved(**kwargs):
         # 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})
 
-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):
+        notify(
+            [object.character.player, 'matthijs@stdin.nl'],
+            '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: