]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/subscriptions.py
the contributors_info template tag should tag context and pass it
[osqa.git] / forum / subscriptions.py
index 24479b74ced3819747c45eab84f0a00abefbc798..fad24a5c95fa3a16e38548263f8407e0e39c3e1f 100644 (file)
@@ -12,9 +12,17 @@ from django.db.models import Q, F
 def create_subscription_if_not_exists(question, user):
     try:
         subscription = QuestionSubscription.objects.get(question=question, user=user)
-    except:
+        return subscription
+    except QuestionSubscription.MultipleObjectsReturned:
+        pass
+    except QuestionSubscription.DoesNotExist:
         subscription = QuestionSubscription(question=question, user=user)
         subscription.save()
+        return subscription
+    except Exception, e:
+        logging.error(e)
+
+    return False
 
 def filter_subscribers(subscribers):
     subscribers = subscribers.exclude(is_active=False)
@@ -27,6 +35,9 @@ def filter_subscribers(subscribers):
 def question_posted(action, new):
     question = action.node
 
+    if not question.is_notifiable:
+        return
+
     subscribers = User.objects.filter(
             Q(subscription_settings__enable_notifications=True, subscription_settings__new_question='i') |
             (Q(subscription_settings__new_question_watched_tags='i') &
@@ -57,6 +68,11 @@ def answer_posted(action, new):
     answer = action.node
     question = answer.question
 
+    logging.error("Answer posted: %s" % str(answer.is_notifiable))
+
+    if not answer.is_notifiable or not question.is_notifiable:
+        return
+
     subscribers = question.subscribers.filter(
             subscription_settings__enable_notifications=True,
             subscription_settings__notify_answers=True,
@@ -76,6 +92,9 @@ def comment_posted(action, new):
     comment = action.node
     post = comment.parent
 
+    if not comment.is_notifiable or not post.is_notifiable:
+        return
+
     if post.__class__ == Question:
         question = post
     else:
@@ -106,6 +125,9 @@ CommentAction.hook(comment_posted)
 def answer_accepted(action, new):
     question = action.node.question
 
+    if not question.is_notifiable:
+        return
+
     subscribers = question.subscribers.filter(
             subscription_settings__enable_notifications=True,
             subscription_settings__subscribed_questions='i'