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