view gpp/forums/signals.py @ 198:7e3ed3eb9b99

Fix #71: problems with editing existing gcalendar dates; the date format wasn't what the datepicker expected.
author Brian Neal <bgneal@gmail.com>
date Sun, 11 Apr 2010 17:58:09 +0000
parents 500e5875a306
children a46788862737
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.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)
post_delete.connect(on_topic_delete, sender=Topic)

post_save.connect(on_post_save, sender=Post)
post_delete.connect(on_post_delete, sender=Post)