1
1
import datetime
2
2
from django .db .models .signals import post_save
3
3
from 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
6
7
from forum .authentication import user_updated
7
8
from forum .const import *
8
9
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 ()
21
13
22
- post_save .connect (record_answer_event , sender = Answer )
14
+ node_create .connect (record_ask_event , sender = Question )
23
15
24
16
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 ()
30
20
31
- post_save .connect (record_comment_event , sender = Comment )
21
+ node_create .connect (record_answer_event , sender = Answer )
32
22
33
23
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 ()
38
28
39
- post_save .connect (record_question_revision_event , sender = QuestionRevision )
29
+ node_create .connect (record_comment_event , sender = Comment )
40
30
41
31
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 )
45
36
activity .save ()
46
37
47
- post_save .connect (record_answer_revision_event , sender = AnswerRevision )
38
+ post_save .connect (record_revision_event , sender = NodeRevision )
48
39
49
40
50
41
def record_award_event (instance , created , ** kwargs ):
@@ -56,13 +47,11 @@ def record_award_event(instance, created, **kwargs):
56
47
post_save .connect (record_award_event , sender = Award )
57
48
58
49
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 ()
64
53
65
- post_save .connect (record_answer_accepted , sender = Answer )
54
+ answer_accepted .connect (record_answer_accepted )
66
55
67
56
68
57
def update_last_seen (instance , ** kwargs ):
@@ -88,7 +77,7 @@ def record_cancel_vote(instance, **kwargs):
88
77
activity = Activity (user = instance .user , active_at = datetime .datetime .now (), content_object = instance , activity_type = act_type )
89
78
activity .save ()
90
79
91
- vote_canceled .connect (record_cancel_vote )
80
+ mark_canceled .connect (record_cancel_vote , sender = Vote )
92
81
93
82
94
83
def record_delete_post (instance , ** kwargs ):
0 commit comments