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
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
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
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
)\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
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