]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/subscriptions.py
merge notification-config -> trunk, previous commits 695, 751 (email debugging inform...
[osqa.git] / forum / subscriptions.py
index 34bbf982c250bdf2e8a525ee685a2f3645b247fa..e897e4eebb486e917a75c776b004156a661bf1a8 100644 (file)
@@ -1,6 +1,7 @@
 import os\r
 import re\r
 import datetime\r
+import logging\r
 from forum.models import User, Question, Comment, QuestionSubscription, SubscriptionSettings, Answer\r
 from forum.utils.mail import send_template_email\r
 from django.utils.translation import ugettext as _\r
@@ -15,6 +16,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,11 +34,12 @@ 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
-        subscription = QuestionSubscription(question=question, user=question.author)\r
-        subscription.save()\r
+    subscription = QuestionSubscription(question=question, user=question.author)\r
+    subscription.save()\r
 \r
     new_subscribers = User.objects.filter(\r
             Q(subscription_settings__all_questions=True) |\r
@@ -53,10 +63,11 @@ 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
-        create_subscription_if_not_exists(question, answer.author)\r
+    create_subscription_if_not_exists(question, answer.author)\r
 \r
 AnswerAction.hook(answer_posted)\r
 \r
@@ -82,11 +93,12 @@ 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
-    if comment.user.subscription_settings.questions_commented:\r
-        create_subscription_if_not_exists(question, comment.user)\r
+    create_subscription_if_not_exists(question, comment.user)\r
 \r
 CommentAction.hook(comment_posted)\r
 \r
@@ -96,9 +108,10 @@ def answer_accepted(action, new):
 \r
     subscribers = question.subscribers.filter(\r
             subscription_settings__enable_notifications=True,\r
-            subscription_settings__notify_accepted=True,\r
             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
@@ -111,6 +124,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
@@ -158,4 +173,4 @@ QuestionViewAction.hook(question_viewed)
 #\r
 #            q_author.message_set.create(message=msg)\r
 #\r
-#post_save.connect(record_answer_event, sender=Answer)
\ No newline at end of file
+#post_save.connect(record_answer_event, sender=Answer)\r