X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/1a949f7c97dc2f34c135f5cdf088df2927d3d652..c5248fba11755939b9b03aa996db697f8fd4b099:/forum/subscriptions.py diff --git a/forum/subscriptions.py b/forum/subscriptions.py index fb2eae9..4966ec6 100644 --- a/forum/subscriptions.py +++ b/forum/subscriptions.py @@ -3,6 +3,7 @@ import re import datetime from forum.models import User, Question, Comment, QuestionSubscription, SubscriptionSettings, Answer from forum.models.user import activity_record +from forum.models.node import node_create from forum.utils.mail import send_email from forum.views.readers import question_view from django.utils.translation import ugettext as _ @@ -25,8 +26,8 @@ def apply_default_filters(queryset, excluded_id): def create_recipients_dict(usr_list): return [(s['username'], s['email'], {'username': s['username']}) for s in usr_list] -def question_posted(sender, instance, **kwargs): - question = instance.content_object +def question_posted(instance, **kwargs): + question = instance subscribers = User.objects.values('email', 'username').filter( Q(subscription_settings__enable_notifications=True, subscription_settings__new_question='i') | @@ -55,11 +56,11 @@ def question_posted(sender, instance, **kwargs): for user in new_subscribers: create_subscription_if_not_exists(question, user) -activity_record.connect(question_posted, sender=const.TYPE_ACTIVITY_ASK_QUESTION, weak=False) +node_create.connect(question_posted, sender=Question) -def answer_posted(sender, instance, **kwargs): - answer = instance.content_object +def answer_posted(instance, **kwargs): + answer = instance question = answer.question subscribers = question.subscribers.values('email', 'username').filter( @@ -78,11 +79,11 @@ def answer_posted(sender, instance, **kwargs): if answer.author.subscription_settings.questions_answered: create_subscription_if_not_exists(question, answer.author) -activity_record.connect(answer_posted, sender=const.TYPE_ACTIVITY_ANSWER, weak=False) +node_create.connect(answer_posted, sender=Answer) -def comment_posted(sender, instance, **kwargs): - comment = instance.content_object +def comment_posted(instance, **kwargs): + comment = instance post = comment.content_object if post.__class__ == Question: @@ -103,7 +104,7 @@ def comment_posted(sender, instance, **kwargs): ) subscribers = subscribers.filter( - q_filter, subscription_settings__subscribed_questions='i', subscription_settings__enable_notifications=True + q_filter, subscription_settings__subscribed_questions='i', subscription_settings__enable_notifications=True ).exclude(id=comment.user.id).distinct() recipients = create_recipients_dict(subscribers) @@ -118,8 +119,7 @@ def comment_posted(sender, instance, **kwargs): if comment.user.subscription_settings.questions_commented: create_subscription_if_not_exists(question, comment.user) -activity_record.connect(comment_posted, sender=const.TYPE_ACTIVITY_COMMENT_QUESTION, weak=False) -activity_record.connect(comment_posted, sender=const.TYPE_ACTIVITY_COMMENT_ANSWER, weak=False) +node_create.connect(comment_posted, sender=Comment) def answer_accepted(instance, created, **kwargs):