11import datetime
22from django .db .models .signals import post_save
33from forum .models import *
4- from forum .models .base import marked_deleted
5- from forum .models .meta import vote_canceled
4+ from forum .models .base import marked_deleted , mark_canceled
5+ from forum .models .node import node_create
6+ from forum .models .answer import answer_accepted
67from forum .authentication import user_updated
78from forum .const import *
89
9- def record_ask_event (instance , created , ** kwargs ):
10- if created :
11- activity = Activity (user = instance .author , active_at = instance .added_at , content_object = instance , activity_type = TYPE_ACTIVITY_ASK_QUESTION )
12- activity .save ()
13-
14- post_save .connect (record_ask_event , sender = Question )
15-
16-
17- def record_answer_event (instance , created , ** kwargs ):
18- if created :
19- activity = Activity (user = instance .author , active_at = instance .added_at , content_object = instance , activity_type = TYPE_ACTIVITY_ANSWER )
20- activity .save ()
10+ def record_ask_event (instance , ** kwargs ):
11+ activity = Activity (user = instance .author , active_at = instance .added_at , content_object = instance , activity_type = TYPE_ACTIVITY_ASK_QUESTION )
12+ activity .save ()
2113
22- post_save .connect (record_answer_event , sender = Answer )
14+ node_create .connect (record_ask_event , sender = Question )
2315
2416
25- def record_comment_event (instance , created , ** kwargs ):
26- if created :
27- act_type = (instance .content_object .__class__ is Question ) and TYPE_ACTIVITY_COMMENT_QUESTION or TYPE_ACTIVITY_COMMENT_ANSWER
28- activity = Activity (user = instance .user , active_at = instance .added_at , content_object = instance , activity_type = act_type )
29- activity .save ()
17+ def record_answer_event (instance , ** kwargs ):
18+ activity = Activity (user = instance .author , active_at = instance .added_at , content_object = instance , activity_type = TYPE_ACTIVITY_ANSWER )
19+ activity .save ()
3020
31- post_save .connect (record_comment_event , sender = Comment )
21+ node_create .connect (record_answer_event , sender = Answer )
3222
3323
34- def record_question_revision_event (instance , created , ** kwargs ):
35- if created and instance .revision <> 1 :
36- activity = Activity (user = instance .author , active_at = instance .revised_at , content_object = instance , activity_type = TYPE_ACTIVITY_UPDATE_QUESTION )
37- activity .save ()
24+ def record_comment_event (instance , ** kwargs ):
25+ act_type = ( instance .content_object . __class__ is Question ) and TYPE_ACTIVITY_COMMENT_QUESTION or TYPE_ACTIVITY_COMMENT_ANSWER
26+ activity = Activity (user = instance .user , active_at = instance .added_at , content_object = instance , activity_type = act_type )
27+ activity .save ()
3828
39- post_save .connect (record_question_revision_event , sender = QuestionRevision )
29+ node_create .connect (record_comment_event , sender = Comment )
4030
4131
42- def record_answer_revision_event (instance , created , ** kwargs ):
43- if created and instance .revision <> 1 :
44- activity = Activity (user = instance .author , active_at = instance .revised_at , content_object = instance , activity_type = TYPE_ACTIVITY_UPDATE_ANSWER )
32+ def record_revision_event (instance , created , ** kwargs ):
33+ if created and instance .revision <> 1 and instance .node .node_type in ('question' , 'answer' ,):
34+ activity_type = instance .node .node_type == 'question' and TYPE_ACTIVITY_UPDATE_QUESTION or TYPE_ACTIVITY_UPDATE_ANSWER
35+ activity = Activity (user = instance .author , active_at = instance .revised_at , content_object = instance , activity_type = activity_type )
4536 activity .save ()
4637
47- post_save .connect (record_answer_revision_event , sender = AnswerRevision )
38+ post_save .connect (record_revision_event , sender = NodeRevision )
4839
4940
5041def record_award_event (instance , created , ** kwargs ):
@@ -56,13 +47,11 @@ def record_award_event(instance, created, **kwargs):
5647post_save .connect (record_award_event , sender = Award )
5748
5849
59- def record_answer_accepted (instance , created , ** kwargs ):
60- if not created and 'accepted' in instance .get_dirty_fields () and instance .accepted :
61- activity = Activity (user = instance .question .author , active_at = datetime .datetime .now (), \
62- content_object = instance , activity_type = TYPE_ACTIVITY_MARK_ANSWER )
63- activity .save ()
50+ def record_answer_accepted (answer , user , ** kwargs ):
51+ activity = Activity (user = user , active_at = datetime .datetime .now (), content_object = answer , activity_type = TYPE_ACTIVITY_MARK_ANSWER )
52+ activity .save ()
6453
65- post_save .connect (record_answer_accepted , sender = Answer )
54+ answer_accepted .connect (record_answer_accepted )
6655
6756
6857def update_last_seen (instance , ** kwargs ):
@@ -88,7 +77,7 @@ def record_cancel_vote(instance, **kwargs):
8877 activity = Activity (user = instance .user , active_at = datetime .datetime .now (), content_object = instance , activity_type = act_type )
8978 activity .save ()
9079
91- vote_canceled .connect (record_cancel_vote )
80+ mark_canceled .connect (record_cancel_vote , sender = Vote )
9281
9382
9483def record_delete_post (instance , ** kwargs ):
0 commit comments