Mercurial > public > sg101
comparison gpp/forums/signals.py @ 75:374b24dd2f9a
First checkin of forums. Have noticed cascading delete behavior. Will try to prevent this next.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 05 Jul 2009 00:03:40 +0000 |
parents | |
children | 500e5875a306 |
comparison
equal
deleted
inserted
replaced
74:df56795771a6 | 75:374b24dd2f9a |
---|---|
1 """ | |
2 Signal handlers for the forums application. | |
3 """ | |
4 from django.db.models.signals import post_save | |
5 from django.db.models.signals import post_delete | |
6 from models import Topic | |
7 from models import Post | |
8 | |
9 | |
10 def on_topic_save(sender, **kwargs): | |
11 if kwargs['created']: | |
12 topic = kwargs['instance'] | |
13 topic.forum.topic_count_update() | |
14 topic.forum.save() | |
15 | |
16 | |
17 def on_topic_delete(sender, **kwargs): | |
18 topic = kwargs['instance'] | |
19 topic.forum.topic_count_update() | |
20 topic.forum.save() | |
21 | |
22 | |
23 def on_post_save(sender, **kwargs): | |
24 if kwargs['created']: | |
25 post = kwargs['instance'] | |
26 | |
27 # update the topic | |
28 post.topic.post_count_update() | |
29 post.topic.save() | |
30 | |
31 # update the forum | |
32 post.topic.forum.post_count_update() | |
33 post.topic.forum.save() | |
34 | |
35 | |
36 def on_post_delete(sender, **kwargs): | |
37 post = kwargs['instance'] | |
38 | |
39 # update the topic | |
40 post.topic.post_count_update() | |
41 post.topic.save() | |
42 | |
43 # update the forum | |
44 post.topic.forum.post_count_update() | |
45 post.topic.forum.save() | |
46 | |
47 | |
48 post_save.connect(on_topic_save, sender=Topic) | |
49 post_delete.connect(on_topic_delete, sender=Topic) | |
50 | |
51 post_save.connect(on_post_save, sender=Post) | |
52 post_delete.connect(on_post_delete, sender=Post) |