Mercurial > public > sg101
view gpp/forums/signals.py @ 260:3a4bbf9c2cce
Fixing #107. Apparently some signal handlers were getting connected twice (double import?) and thus saving a forum post would cause 2 email notifications to go out to the post topic's subscribers. Use the dispatch_uid parameter in the connect call to work around this issue.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 22 Sep 2010 00:24:59 +0000 |
parents | a46788862737 |
children | d1b11096595b |
line wrap: on
line source
""" Signal handlers for the forums application. """ from django.db.models.signals import post_save from django.db.models.signals import post_delete from forums.models import Topic, Post from forums.views.subscriptions import notify_topic_subscribers def on_topic_save(sender, **kwargs): if kwargs['created']: topic = kwargs['instance'] topic.forum.topic_count_update() topic.forum.save() def on_topic_delete(sender, **kwargs): topic = kwargs['instance'] topic.forum.topic_count_update() topic.forum.save() def on_post_save(sender, **kwargs): if kwargs['created']: post = kwargs['instance'] # update the topic post.topic.post_count_update() post.topic.save() # update the forum post.topic.forum.post_count_update() post.topic.forum.save() # send out any email notifications notify_topic_subscribers(post) def on_post_delete(sender, **kwargs): post = kwargs['instance'] # update the topic post.topic.post_count_update() post.topic.save() # update the forum post.topic.forum.post_count_update() post.topic.forum.save() post_save.connect(on_topic_save, sender=Topic, dispatch_uid='forums.signals') post_delete.connect(on_topic_delete, sender=Topic, dispatch_uid='forums.signals') post_save.connect(on_post_save, sender=Post, dispatch_uid='forums.signals') post_delete.connect(on_post_delete, sender=Post, dispatch_uid='forums.signals')