]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/subscriptions.py
disabling the submit buttons for question and answers.
[osqa.git] / forum / subscriptions.py
index b361823f5ed8b024fb9753d4d905e7c676bf59fc..7a5bf0684f6aa2d0ac161ad5b0eeef356e5c8b56 100644 (file)
@@ -2,7 +2,7 @@ import os
 import re\r
 import datetime\r
 from forum.models import User, Question, Comment, QuestionSubscription, SubscriptionSettings, Answer\r
-from forum.utils.mail import send_email, send_template_email\r
+from forum.utils.mail import send_template_email\r
 from django.utils.translation import ugettext as _\r
 from forum.actions import AskAction, AnswerAction, CommentAction, AcceptAnswerAction, UserJoinsAction, QuestionViewAction\r
 from forum import settings\r
@@ -15,6 +15,14 @@ def create_subscription_if_not_exists(question, user):
         subscription = QuestionSubscription(question=question, user=user)\r
         subscription.save()\r
 \r
+def filter_subscribers(subscribers):\r
+    subscribers = subscribers.exclude(is_active=False)\r
+\r
+    if settings.DONT_NOTIFY_UNVALIDATED:\r
+        return subscribers.exclude(email_isvalid=False)\r
+    else:\r
+        return subscribers\r
+\r
 def question_posted(action, new):\r
     question = action.node\r
 \r
@@ -25,6 +33,8 @@ def question_posted(action, new):
               Q(tag_selections__reason='good'))\r
     ).exclude(id=question.author.id).distinct()\r
 \r
+    subscribers = filter_subscribers(subscribers)\r
+\r
     send_template_email(subscribers, "notifications/newquestion.html", {'question': question})\r
 \r
     if question.author.subscription_settings.questions_asked:\r
@@ -53,6 +63,8 @@ def answer_posted(action, new):
             subscription_settings__subscribed_questions='i'\r
     ).exclude(id=answer.author.id).distinct()\r
 \r
+    subscribers = filter_subscribers(subscribers)\r
+\r
     send_template_email(subscribers, "notifications/newanswer.html", {'answer': answer})\r
 \r
     if answer.author.subscription_settings.questions_answered:\r
@@ -82,6 +94,8 @@ def comment_posted(action, new):
             q_filter, subscription_settings__subscribed_questions='i', subscription_settings__enable_notifications=True\r
     ).exclude(id=comment.user.id).distinct()\r
 \r
+    subscribers = filter_subscribers(subscribers)\r
+\r
 \r
     send_template_email(subscribers, "notifications/newcomment.html", {'comment': comment})\r
 \r
@@ -100,6 +114,8 @@ def answer_accepted(action, new):
             subscription_settings__subscribed_questions='i'\r
     ).exclude(id=action.node.nstate.accepted.by.id).distinct()\r
 \r
+    subscribers = filter_subscribers(subscribers)\r
+\r
     send_template_email(subscribers, "notifications/answeraccepted.html", {'answer': action.node})\r
 \r
 AcceptAnswerAction.hook(answer_accepted)\r
@@ -111,6 +127,8 @@ def member_joined(action, new):
             subscription_settings__member_joins='i'\r
     ).exclude(id=action.user.id).distinct()\r
 \r
+    subscribers = filter_subscribers(subscribers)\r
+\r
     send_template_email(subscribers, "notifications/newmember.html", {'newmember': action.user})\r
 \r
 UserJoinsAction.hook(member_joined)\r