]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/activity.py
fixes osqa-188 - localizes the word 'Login' in openidurl.html
[osqa.git] / forum / activity.py
index 9c27e12fd9ea90dfdc89af14a68f7dd240722126..16877987317bea44a077ae37b8fed03f519d27f1 100644 (file)
@@ -1,50 +1,41 @@
 import datetime\r
 from django.db.models.signals import post_save\r
 from forum.models import *\r
-from forum.models.base import marked_deleted\r
-from forum.models.meta import vote_canceled\r
+from forum.models.base import marked_deleted, mark_canceled\r
+from forum.models.node import node_create\r
+from forum.models.answer import answer_accepted\r
 from forum.authentication import user_updated\r
 from forum.const import *\r
 \r
-def record_ask_event(instance, created, **kwargs):\r
-    if created:\r
-        activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ASK_QUESTION)\r
-        activity.save()\r
-\r
-post_save.connect(record_ask_event, sender=Question)\r
-\r
-\r
-def record_answer_event(instance, created, **kwargs):\r
-    if created:\r
-        activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ANSWER)\r
-        activity.save()\r
+def record_ask_event(instance, **kwargs):\r
+    activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ASK_QUESTION)\r
+    activity.save()\r
 \r
-post_save.connect(record_answer_event, sender=Answer)\r
+node_create.connect(record_ask_event, sender=Question)\r
 \r
 \r
-def record_comment_event(instance, created, **kwargs):\r
-    if created:\r
-        act_type = (instance.content_object.__class__ is Question) and TYPE_ACTIVITY_COMMENT_QUESTION or TYPE_ACTIVITY_COMMENT_ANSWER\r
-        activity = Activity(user=instance.user, active_at=instance.added_at, content_object=instance, activity_type=act_type)\r
-        activity.save()\r
+def record_answer_event(instance, **kwargs):\r
+    activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ANSWER)\r
+    activity.save()\r
 \r
-post_save.connect(record_comment_event, sender=Comment)\r
+node_create.connect(record_answer_event, sender=Answer)\r
 \r
 \r
-def record_question_revision_event(instance, created, **kwargs):\r
-    if created and instance.revision <> 1:\r
-        activity = Activity(user=instance.author, active_at=instance.revised_at, content_object=instance, activity_type=TYPE_ACTIVITY_UPDATE_QUESTION)\r
-        activity.save()\r
+def record_comment_event(instance, **kwargs):\r
+    act_type = (instance.content_object.__class__ is Question) and TYPE_ACTIVITY_COMMENT_QUESTION or TYPE_ACTIVITY_COMMENT_ANSWER\r
+    activity = Activity(user=instance.user, active_at=instance.added_at, content_object=instance, activity_type=act_type)\r
+    activity.save()\r
 \r
-post_save.connect(record_question_revision_event, sender=QuestionRevision)\r
+node_create.connect(record_comment_event, sender=Comment)\r
 \r
 \r
-def record_answer_revision_event(instance, created, **kwargs):\r
-    if created and instance.revision <> 1:\r
-        activity = Activity(user=instance.author, active_at=instance.revised_at, content_object=instance, activity_type=TYPE_ACTIVITY_UPDATE_ANSWER)\r
+def record_revision_event(instance, created, **kwargs):\r
+    if created and instance.revision <> 1 and instance.node.node_type in ('question', 'answer',):\r
+        activity_type = instance.node.node_type == 'question' and TYPE_ACTIVITY_UPDATE_QUESTION or TYPE_ACTIVITY_UPDATE_ANSWER\r
+        activity = Activity(user=instance.author, active_at=instance.revised_at, content_object=instance, activity_type=activity_type)\r
         activity.save()\r
 \r
-post_save.connect(record_answer_revision_event, sender=AnswerRevision)\r
+post_save.connect(record_revision_event, sender=NodeRevision)\r
 \r
 \r
 def record_award_event(instance, created, **kwargs):\r
@@ -56,13 +47,11 @@ def record_award_event(instance, created, **kwargs):
 post_save.connect(record_award_event, sender=Award)\r
 \r
 \r
-def record_answer_accepted(instance, created, **kwargs):\r
-    if not created and 'accepted' in instance.get_dirty_fields() and instance.accepted:\r
-        activity = Activity(user=instance.question.author, active_at=datetime.datetime.now(), \\r
-            content_object=instance, activity_type=TYPE_ACTIVITY_MARK_ANSWER)\r
-        activity.save()\r
+def record_answer_accepted(answer, user, **kwargs):\r
+    activity = Activity(user=user, active_at=datetime.datetime.now(), content_object=answer, activity_type=TYPE_ACTIVITY_MARK_ANSWER)\r
+    activity.save()\r
 \r
-post_save.connect(record_answer_accepted, sender=Answer)\r
+answer_accepted.connect(record_answer_accepted)\r
 \r
 \r
 def update_last_seen(instance, **kwargs):\r
@@ -88,7 +77,7 @@ def record_cancel_vote(instance, **kwargs):
     activity = Activity(user=instance.user, active_at=datetime.datetime.now(), content_object=instance, activity_type=act_type)\r
     activity.save()\r
 \r
-vote_canceled.connect(record_cancel_vote)\r
+mark_canceled.connect(record_cancel_vote, sender=Vote)\r
 \r
 \r
 def record_delete_post(instance, **kwargs):\r