X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/2e9d59591e9cfc93c24a96b9dc51ce5dd2ce5a03..0ad5d07da08894c96caf49e05e9cf649e58d6554:/forum/subscriptions.py diff --git a/forum/subscriptions.py b/forum/subscriptions.py index 34bbf98..e897e4e 100644 --- a/forum/subscriptions.py +++ b/forum/subscriptions.py @@ -1,6 +1,7 @@ import os import re import datetime +import logging from forum.models import User, Question, Comment, QuestionSubscription, SubscriptionSettings, Answer from forum.utils.mail import send_template_email from django.utils.translation import ugettext as _ @@ -15,6 +16,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,11 +34,12 @@ 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: - subscription = QuestionSubscription(question=question, user=question.author) - subscription.save() + subscription = QuestionSubscription(question=question, user=question.author) + subscription.save() new_subscribers = User.objects.filter( Q(subscription_settings__all_questions=True) | @@ -53,10 +63,11 @@ 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: - create_subscription_if_not_exists(question, answer.author) + create_subscription_if_not_exists(question, answer.author) AnswerAction.hook(answer_posted) @@ -82,11 +93,12 @@ 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}) - if comment.user.subscription_settings.questions_commented: - create_subscription_if_not_exists(question, comment.user) + create_subscription_if_not_exists(question, comment.user) CommentAction.hook(comment_posted) @@ -96,9 +108,10 @@ def answer_accepted(action, new): subscribers = question.subscribers.filter( subscription_settings__enable_notifications=True, - subscription_settings__notify_accepted=True, 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}) @@ -111,6 +124,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) @@ -158,4 +173,4 @@ QuestionViewAction.hook(question_viewed) # # q_author.message_set.create(message=msg) # -#post_save.connect(record_answer_event, sender=Answer) \ No newline at end of file +#post_save.connect(record_answer_event, sender=Answer)