summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-03-15 12:29:15 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-03-15 12:29:15 -0400
commit7a29062bb51b582c1ff8547e8bff66d28066d2d4 (patch)
treea20aab087a10cd9188cf2c1f39ebb50bfa0ff8f1
parent02db3adeadf391c374203ad66ada0535182963eb (diff)
downloadaskbot-7a29062bb51b582c1ff8547e8bff66d28066d2d4.tar.gz
askbot-7a29062bb51b582c1ff8547e8bff66d28066d2d4.tar.bz2
askbot-7a29062bb51b582c1ff8547e8bff66d28066d2d4.zip
in the middle of adding support for celery
-rw-r--r--askbot/models/__init__.py68
-rw-r--r--askbot/tasks.py71
2 files changed, 85 insertions, 54 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 60d0e380..9122a376 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -2020,7 +2020,7 @@ def calculate_gravatar_hash(instance, **kwargs):
def record_post_update_activity(
post,
- newly_mentioned_users = list(),
+ newly_mentioned_users = None,
updated_by = None,
timestamp = None,
created = False,
@@ -2031,54 +2031,19 @@ def record_post_update_activity(
"""
assert(timestamp != None)
assert(updated_by != None)
-
- #todo: take into account created == True case
- (activity_type, update_object) = post.get_updated_activity_data(created)
-
- update_activity = Activity(
- user = updated_by,
- active_at = timestamp,
- content_object = post,
- activity_type = activity_type,
- question = post.get_origin_post()
- )
- update_activity.save()
-
- #what users are included depends on the post type
- #for example for question - all Q&A contributors
- #are included, for comments only authors of comments and parent
- #post are included
- recipients = post.get_response_receivers(
- exclude_list = [updated_by, ]
- )
-
- update_activity.add_recipients(recipients)
-
- assert(updated_by not in recipients)
-
- for user in set(recipients) | set(newly_mentioned_users):
- user.increment_response_count()
- user.save()
-
- #todo: weird thing is that only comments need the recipients
- #todo: debug these calls and then uncomment in the repo
- #argument to this call
- notification_subscribers = post.get_instant_notification_subscribers(
- potential_subscribers = recipients,
- mentioned_users = newly_mentioned_users,
- exclude_list = [updated_by, ]
- )
- #todo: fix this temporary spam protection plug
- if created:
- if not (updated_by.is_administrator() or updated_by.is_moderator()):
- if updated_by.reputation < 15:
- notification_subscribers = \
- [u for u in notification_subscribers if u.is_administrator()]
- send_instant_notifications_about_activity_in_post(
- update_activity = update_activity,
- post = post,
- recipients = notification_subscribers,
- )
+ if newly_mentioned_users is None:
+ newly_mentioned_users = list()
+
+ from askbot.tasks import record_post_update_task
+
+ record_post_update_task.delay(
+ post_id = post.id,
+ post_content_type_id = ContentType.objects.get_for_model(post).id,
+ newly_mentioned_user_id_list = [u.id for u in newly_mentioned_users],
+ updated_by_id = updated_by.id,
+ timestamp = timestamp,
+ created = created,
+ )
def record_award_event(instance, created, **kwargs):
@@ -2388,7 +2353,6 @@ signals.post_updated.connect(
signals.site_visited.connect(record_user_visit)
#todo: wtf??? what is x=x about?
-signals = signals
Question = Question
QuestionRevision = QuestionRevision
@@ -2400,10 +2364,6 @@ Answer = Answer
AnswerRevision = AnswerRevision
AnonymousAnswer = AnonymousAnswer
-Tag = Tag
-Comment = Comment
-Vote = Vote
-MarkedTag = MarkedTag
BadgeData = BadgeData
Award = Award
diff --git a/askbot/tasks.py b/askbot/tasks.py
new file mode 100644
index 00000000..e230be31
--- /dev/null
+++ b/askbot/tasks.py
@@ -0,0 +1,71 @@
+from django.contrib.contenttypes.models import ContentType
+from celery.decorators import task
+from askbot.models import Activity
+from askbot.models import User
+from askbot.models import send_instant_notifications_about_activity_in_post
+
+@task(ignore_results = True)
+def record_post_update_task(
+ post_id,
+ post_content_type_id,
+ newly_mentioned_user_id_list = None,
+ updated_by_id = None,
+ timestamp = None,
+ created = False,
+ ):
+
+ updated_by = User.objects.get(id = updated_by_id)
+ post_content_type = ContentType.objects.get(id = post_content_type_id)
+ post = post_content_type.get_object_for_this_type(id = post_id)
+
+ #todo: take into account created == True case
+ (activity_type, update_object) = post.get_updated_activity_data(created)
+
+ update_activity = Activity(
+ user = updated_by,
+ active_at = timestamp,
+ content_object = post,
+ activity_type = activity_type,
+ question = post.get_origin_post()
+ )
+ update_activity.save()
+
+ #what users are included depends on the post type
+ #for example for question - all Q&A contributors
+ #are included, for comments only authors of comments and parent
+ #post are included
+ recipients = post.get_response_receivers(
+ exclude_list = [updated_by, ]
+ )
+
+ update_activity.add_recipients(recipients)
+
+ assert(updated_by not in recipients)
+
+ newly_mentioned_users = User.objects.filter(
+ id__in = newly_mentioned_user_id_list
+ )
+
+ for user in set(recipients) | set(newly_mentioned_users):
+ user.increment_response_count()
+ user.save()
+
+ #todo: weird thing is that only comments need the recipients
+ #todo: debug these calls and then uncomment in the repo
+ #argument to this call
+ notification_subscribers = post.get_instant_notification_subscribers(
+ potential_subscribers = recipients,
+ mentioned_users = newly_mentioned_users,
+ exclude_list = [updated_by, ]
+ )
+ #todo: fix this temporary spam protection plug
+ if created:
+ if not (updated_by.is_administrator() or updated_by.is_moderator()):
+ if updated_by.reputation < 15:
+ notification_subscribers = \
+ [u for u in notification_subscribers if u.is_administrator()]
+ send_instant_notifications_about_activity_in_post(
+ update_activity = update_activity,
+ post = post,
+ recipients = notification_subscribers,
+ )