X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/d0c5ac2cb8bee88ff425ecbb3db3921c4e83ea18..4b20a67ddb4ebea2c6e09d51ee48da5a856edef8:/forum/subscriptions.py?ds=sidebyside diff --git a/forum/subscriptions.py b/forum/subscriptions.py index b361823..7a5bf06 100644 --- a/forum/subscriptions.py +++ b/forum/subscriptions.py @@ -2,7 +2,7 @@ import os import re import datetime from forum.models import User, Question, Comment, QuestionSubscription, SubscriptionSettings, Answer -from forum.utils.mail import send_email, send_template_email +from forum.utils.mail import send_template_email from django.utils.translation import ugettext as _ from forum.actions import AskAction, AnswerAction, CommentAction, AcceptAnswerAction, UserJoinsAction, QuestionViewAction from forum import settings @@ -15,6 +15,14 @@ def create_subscription_if_not_exists(question, user): subscription = QuestionSubscription(question=question, user=user) subscription.save() +def filter_subscribers(subscribers): + subscribers = subscribers.exclude(is_active=False) + + if settings.DONT_NOTIFY_UNVALIDATED: + return subscribers.exclude(email_isvalid=False) + else: + return subscribers + def question_posted(action, new): question = action.node @@ -25,6 +33,8 @@ def question_posted(action, new): Q(tag_selections__reason='good')) ).exclude(id=question.author.id).distinct() + subscribers = filter_subscribers(subscribers) + send_template_email(subscribers, "notifications/newquestion.html", {'question': question}) if question.author.subscription_settings.questions_asked: @@ -53,6 +63,8 @@ def answer_posted(action, new): subscription_settings__subscribed_questions='i' ).exclude(id=answer.author.id).distinct() + subscribers = filter_subscribers(subscribers) + send_template_email(subscribers, "notifications/newanswer.html", {'answer': answer}) if answer.author.subscription_settings.questions_answered: @@ -82,6 +94,8 @@ def comment_posted(action, new): q_filter, subscription_settings__subscribed_questions='i', subscription_settings__enable_notifications=True ).exclude(id=comment.user.id).distinct() + subscribers = filter_subscribers(subscribers) + send_template_email(subscribers, "notifications/newcomment.html", {'comment': comment}) @@ -100,6 +114,8 @@ def answer_accepted(action, new): subscription_settings__subscribed_questions='i' ).exclude(id=action.node.nstate.accepted.by.id).distinct() + subscribers = filter_subscribers(subscribers) + send_template_email(subscribers, "notifications/answeraccepted.html", {'answer': action.node}) AcceptAnswerAction.hook(answer_accepted) @@ -111,6 +127,8 @@ def member_joined(action, new): subscription_settings__member_joins='i' ).exclude(id=action.user.id).distinct() + subscribers = filter_subscribers(subscribers) + send_template_email(subscribers, "notifications/newmember.html", {'newmember': action.user}) UserJoinsAction.hook(member_joined)