Only notify a player of finished influence changes.
[matthijs/projects/xerxes.git] / influences / notify.py
index e5c763ae36b40dea3d20b39d324233b8aad15378..daffadf5cb4a53aa42a3967ce5c394eb3ddaa9fe 100644 (file)
@@ -18,22 +18,31 @@ def influence_saved(**kwargs):
     instance = kwargs['instance']
     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})
+        recipients = ['lextalionis@evolution-events.nl']
+        if instance.status == 'D':
+            recipients.append(instance.character.player)
+        notify(recipients, '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.append(object.character.player)
+
         notify(
-            [object.character.player, 'matthijs@stdin.nl'],
+            recipients,
             'influences/email/influence_comment_added.html',
             {'comment'   : comment, 
              'influence' : object,