comparison gpp/forums/signals.py @ 348:d1b11096595b

Fix #168; when nailing a spammer, clear their profile text fields. Guard against topics and forums that don't exist when deleting posts in the signal handler. Make the forum stats template tag only display the latest active users.
author Brian Neal <bgneal@gmail.com>
date Wed, 02 Mar 2011 02:18:28 +0000
parents 3a4bbf9c2cce
children e0523e17ea43
comparison
equal deleted inserted replaced
347:69d0306a6fe7 348:d1b11096595b
2 Signal handlers for the forums application. 2 Signal handlers for the forums application.
3 """ 3 """
4 from django.db.models.signals import post_save 4 from django.db.models.signals import post_save
5 from django.db.models.signals import post_delete 5 from django.db.models.signals import post_delete
6 6
7 from forums.models import Topic, Post 7 from forums.models import Forum, Topic, Post
8 from forums.views.subscriptions import notify_topic_subscribers 8 from forums.views.subscriptions import notify_topic_subscribers
9 9
10 10
11 def on_topic_save(sender, **kwargs): 11 def on_topic_save(sender, **kwargs):
12 if kwargs['created']: 12 if kwargs['created']:
39 39
40 def on_post_delete(sender, **kwargs): 40 def on_post_delete(sender, **kwargs):
41 post = kwargs['instance'] 41 post = kwargs['instance']
42 42
43 # update the topic 43 # update the topic
44 post.topic.post_count_update() 44 try:
45 post.topic.save() 45 post.topic.post_count_update()
46 46 post.topic.save()
47 # update the forum 47 except Topic.DoesNotExist:
48 post.topic.forum.post_count_update() 48 pass
49 post.topic.forum.save() 49 else:
50 # update the forum
51 try:
52 post.topic.forum.post_count_update()
53 post.topic.forum.save()
54 except Forum.DoesNotExist:
55 pass
50 56
51 57
52 post_save.connect(on_topic_save, sender=Topic, dispatch_uid='forums.signals') 58 post_save.connect(on_topic_save, sender=Topic, dispatch_uid='forums.signals')
53 post_delete.connect(on_topic_delete, sender=Topic, dispatch_uid='forums.signals') 59 post_delete.connect(on_topic_delete, sender=Topic, dispatch_uid='forums.signals')
54 60