annotate forums/receivers.py @ 1089:64fb0d6933a4

Hide podcast logo on small screens.
author Brian Neal <bgneal@gmail.com>
date Sun, 08 May 2016 21:03:09 -0500
parents 5902dc5e58a3
children
rev   line source
bgneal@75 1 """
bgneal@920 2 Signal handlers for the forums application.
bgneal@469 3
bgneal@75 4 """
bgneal@75 5 from django.db.models.signals import post_save
bgneal@75 6 from django.db.models.signals import post_delete
bgneal@181 7
bgneal@348 8 from forums.models import Forum, Topic, Post
bgneal@920 9 import forums.latest
bgneal@75 10
bgneal@75 11
bgneal@75 12 def on_topic_save(sender, **kwargs):
bgneal@75 13 if kwargs['created']:
bgneal@75 14 topic = kwargs['instance']
bgneal@75 15 topic.forum.topic_count_update()
bgneal@75 16 topic.forum.save()
bgneal@75 17
bgneal@75 18
bgneal@75 19 def on_topic_delete(sender, **kwargs):
bgneal@75 20 topic = kwargs['instance']
bgneal@75 21 topic.forum.topic_count_update()
bgneal@75 22 topic.forum.save()
bgneal@522 23 forums.latest.notify_topic_delete(topic)
bgneal@75 24
bgneal@75 25
bgneal@75 26 def on_post_save(sender, **kwargs):
bgneal@75 27 if kwargs['created']:
bgneal@75 28 post = kwargs['instance']
bgneal@75 29
bgneal@75 30 # update the topic
bgneal@75 31 post.topic.post_count_update()
bgneal@75 32 post.topic.save()
bgneal@75 33
bgneal@75 34 # update the forum
bgneal@75 35 post.topic.forum.post_count_update()
bgneal@75 36 post.topic.forum.save()
bgneal@75 37
bgneal@75 38
bgneal@75 39 def on_post_delete(sender, **kwargs):
bgneal@75 40 post = kwargs['instance']
bgneal@75 41
bgneal@75 42 # update the topic
bgneal@348 43 try:
bgneal@348 44 post.topic.post_count_update()
bgneal@348 45 post.topic.save()
bgneal@348 46 except Topic.DoesNotExist:
bgneal@348 47 pass
bgneal@348 48 else:
bgneal@348 49 # update the forum
bgneal@348 50 try:
bgneal@348 51 post.topic.forum.post_count_update()
bgneal@348 52 post.topic.forum.save()
bgneal@348 53 except Forum.DoesNotExist:
bgneal@348 54 pass
bgneal@75 55
bgneal@75 56
bgneal@920 57 post_save.connect(on_topic_save, sender=Topic, dispatch_uid='forums.receivers')
bgneal@920 58 post_delete.connect(on_topic_delete, sender=Topic, dispatch_uid='forums.receivers')
bgneal@920 59 post_save.connect(on_post_save, sender=Post, dispatch_uid='forums.receivers')
bgneal@920 60 post_delete.connect(on_post_delete, sender=Post, dispatch_uid='forums.receivers')