]> git.openstreetmap.org Git - osqa.git/blob - forum/activity.py
I forgot to add the default value for the faq page
[osqa.git] / forum / activity.py
1 import datetime\r
2 from django.db.models.signals import post_save\r
3 from forum.models import *\r
4 from forum.models.base import marked_deleted, mark_canceled\r
5 from forum.models.node import node_create\r
6 from forum.models.answer import answer_accepted\r
7 from forum.authentication import user_updated\r
8 from forum.const import *\r
9 \r
10 def record_ask_event(instance, **kwargs):\r
11     activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ASK_QUESTION)\r
12     activity.save()\r
13 \r
14 node_create.connect(record_ask_event, sender=Question)\r
15 \r
16 \r
17 def record_answer_event(instance, **kwargs):\r
18     activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ANSWER)\r
19     activity.save()\r
20 \r
21 node_create.connect(record_answer_event, sender=Answer)\r
22 \r
23 \r
24 def record_comment_event(instance, **kwargs):\r
25     act_type = (instance.content_object.__class__ is Question) and TYPE_ACTIVITY_COMMENT_QUESTION or TYPE_ACTIVITY_COMMENT_ANSWER\r
26     activity = Activity(user=instance.user, active_at=instance.added_at, content_object=instance, activity_type=act_type)\r
27     activity.save()\r
28 \r
29 node_create.connect(record_comment_event, sender=Comment)\r
30 \r
31 \r
32 def record_revision_event(instance, created, **kwargs):\r
33     if created and instance.revision <> 1 and instance.node.node_type in ('question', 'answer',):\r
34         activity_type = instance.node.node_type == 'question' and TYPE_ACTIVITY_UPDATE_QUESTION or TYPE_ACTIVITY_UPDATE_ANSWER\r
35         activity = Activity(user=instance.author, active_at=instance.revised_at, content_object=instance, activity_type=activity_type)\r
36         activity.save()\r
37 \r
38 post_save.connect(record_revision_event, sender=NodeRevision)\r
39 \r
40 \r
41 def record_award_event(instance, created, **kwargs):\r
42     if created:\r
43         activity = Activity(user=instance.user, active_at=instance.awarded_at, content_object=instance,\r
44             activity_type=TYPE_ACTIVITY_PRIZE)\r
45         activity.save()\r
46 \r
47 post_save.connect(record_award_event, sender=Award)\r
48 \r
49 \r
50 def record_answer_accepted(answer, user, **kwargs):\r
51     activity = Activity(user=user, active_at=datetime.datetime.now(), content_object=answer, activity_type=TYPE_ACTIVITY_MARK_ANSWER)\r
52     activity.save()\r
53 \r
54 answer_accepted.connect(record_answer_accepted)\r
55 \r
56 \r
57 def update_last_seen(instance, **kwargs):\r
58     user = instance.user\r
59     user.last_seen = datetime.datetime.now()\r
60     user.save()\r
61 \r
62 post_save.connect(update_last_seen, sender=Activity)\r
63 \r
64 \r
65 def record_vote(instance, created, **kwargs):\r
66     if created:\r
67         act_type = (instance.vote == 1) and TYPE_ACTIVITY_VOTE_UP or TYPE_ACTIVITY_VOTE_DOWN\r
68 \r
69         activity = Activity(user=instance.user, active_at=instance.voted_at, content_object=instance, activity_type=act_type)\r
70         activity.save()\r
71 \r
72 post_save.connect(record_vote, sender=Vote)\r
73 \r
74 \r
75 def record_cancel_vote(instance, **kwargs):\r
76     act_type = (instance.vote == 1) and TYPE_ACTIVITY_CANCEL_VOTE_UP or TYPE_ACTIVITY_CANCEL_VOTE_DOWN\r
77     activity = Activity(user=instance.user, active_at=datetime.datetime.now(), content_object=instance, activity_type=act_type)\r
78     activity.save()\r
79 \r
80 mark_canceled.connect(record_cancel_vote, sender=Vote)\r
81 \r
82 \r
83 def record_delete_post(instance, **kwargs):\r
84     act_type = (instance.__class__ is Question) and TYPE_ACTIVITY_DELETE_QUESTION or TYPE_ACTIVITY_DELETE_ANSWER\r
85     activity = Activity(user=instance.deleted_by, active_at=datetime.datetime.now(), content_object=instance, activity_type=act_type)\r
86     activity.save()\r
87 \r
88 marked_deleted.connect(record_delete_post, sender=Question)\r
89 marked_deleted.connect(record_delete_post, sender=Answer)\r
90 \r
91 \r
92 def record_update_tags(instance, created, **kwargs):\r
93     if not created and 'tagnames' in instance.get_dirty_fields():\r
94         activity = Activity(user=instance.author, active_at=datetime.datetime.now(), content_object=instance, activity_type=TYPE_ACTIVITY_UPDATE_TAGS)\r
95         activity.save()\r
96 \r
97 post_save.connect(record_update_tags, sender=Question)\r
98 \r
99 \r
100 def record_mark_offensive(instance, created, **kwargs):\r
101     if created:\r
102         activity = Activity(user=instance.user, active_at=datetime.datetime.now(), content_object=instance.content_object, activity_type=TYPE_ACTIVITY_MARK_OFFENSIVE)\r
103         activity.save()\r
104 \r
105 post_save.connect(record_mark_offensive, sender=FlaggedItem)\r
106 \r
107 \r
108 def record_favorite_question(instance, created, **kwargs):\r
109     if created:\r
110         activity = Activity(user=instance.user, active_at=datetime.datetime.now(), content_object=instance, activity_type=TYPE_ACTIVITY_FAVORITE)\r
111         activity.save()\r
112 \r
113 post_save.connect(record_favorite_question, sender=FavoriteQuestion)\r
114 \r
115 \r
116 def record_user_full_updated(instance, **kwargs):\r
117     activity = Activity(user=instance, active_at=datetime.datetime.now(), content_object=instance, activity_type=TYPE_ACTIVITY_USER_FULL_UPDATED)\r
118     activity.save()\r
119 \r
120 user_updated.connect(record_user_full_updated, sender=User)\r
121 \r