annotate gpp/forums/signals.py @ 170:6f14970b103a

Implement #52 Forums RSS feeds.
author Brian Neal <bgneal@gmail.com>
date Thu, 11 Feb 2010 02:29:03 +0000
parents 374b24dd2f9a
children 500e5875a306
rev   line source
bgneal@75 1 """
bgneal@75 2 Signal handlers for the forums application.
bgneal@75 3 """
bgneal@75 4 from django.db.models.signals import post_save
bgneal@75 5 from django.db.models.signals import post_delete
bgneal@75 6 from models import Topic
bgneal@75 7 from models import Post
bgneal@75 8
bgneal@75 9
bgneal@75 10 def on_topic_save(sender, **kwargs):
bgneal@75 11 if kwargs['created']:
bgneal@75 12 topic = kwargs['instance']
bgneal@75 13 topic.forum.topic_count_update()
bgneal@75 14 topic.forum.save()
bgneal@75 15
bgneal@75 16
bgneal@75 17 def on_topic_delete(sender, **kwargs):
bgneal@75 18 topic = kwargs['instance']
bgneal@75 19 topic.forum.topic_count_update()
bgneal@75 20 topic.forum.save()
bgneal@75 21
bgneal@75 22
bgneal@75 23 def on_post_save(sender, **kwargs):
bgneal@75 24 if kwargs['created']:
bgneal@75 25 post = kwargs['instance']
bgneal@75 26
bgneal@75 27 # update the topic
bgneal@75 28 post.topic.post_count_update()
bgneal@75 29 post.topic.save()
bgneal@75 30
bgneal@75 31 # update the forum
bgneal@75 32 post.topic.forum.post_count_update()
bgneal@75 33 post.topic.forum.save()
bgneal@75 34
bgneal@75 35
bgneal@75 36 def on_post_delete(sender, **kwargs):
bgneal@75 37 post = kwargs['instance']
bgneal@75 38
bgneal@75 39 # update the topic
bgneal@75 40 post.topic.post_count_update()
bgneal@75 41 post.topic.save()
bgneal@75 42
bgneal@75 43 # update the forum
bgneal@75 44 post.topic.forum.post_count_update()
bgneal@75 45 post.topic.forum.save()
bgneal@75 46
bgneal@75 47
bgneal@75 48 post_save.connect(on_topic_save, sender=Topic)
bgneal@75 49 post_delete.connect(on_topic_delete, sender=Topic)
bgneal@75 50
bgneal@75 51 post_save.connect(on_post_save, sender=Post)
bgneal@75 52 post_delete.connect(on_post_delete, sender=Post)