# HG changeset patch # User Brian Neal # Date 1428455492 18000 # Node ID 5902dc5e58a327a0f4627206ace3662528636a0f # Parent 0b6bf9c5a982d875d5151e3be4a9e0ec3b3772ab Forums app refactor. For Django 1.7.7 upgrade. diff -r 0b6bf9c5a982 -r 5902dc5e58a3 forums/__init__.py --- a/forums/__init__.py Mon Apr 06 20:33:10 2015 -0500 +++ b/forums/__init__.py Tue Apr 07 20:11:32 2015 -0500 @@ -1,2 +1,1 @@ -import signals -import latest +default_app_config = 'forums.apps.ForumsConfig' diff -r 0b6bf9c5a982 -r 5902dc5e58a3 forums/apps.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/forums/apps.py Tue Apr 07 20:11:32 2015 -0500 @@ -0,0 +1,9 @@ +from django.apps import AppConfig + + +class ForumsConfig(AppConfig): + name = 'forums' + + def ready(self): + import forums.receivers + import forums.latest diff -r 0b6bf9c5a982 -r 5902dc5e58a3 forums/receivers.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/forums/receivers.py Tue Apr 07 20:11:32 2015 -0500 @@ -0,0 +1,60 @@ +""" +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 Forum, Topic, Post +import forums.latest + + +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() + forums.latest.notify_topic_delete(topic) + + +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() + + +def on_post_delete(sender, **kwargs): + post = kwargs['instance'] + + # update the topic + try: + post.topic.post_count_update() + post.topic.save() + except Topic.DoesNotExist: + pass + else: + # update the forum + try: + post.topic.forum.post_count_update() + post.topic.forum.save() + except Forum.DoesNotExist: + pass + + +post_save.connect(on_topic_save, sender=Topic, dispatch_uid='forums.receivers') +post_delete.connect(on_topic_delete, sender=Topic, dispatch_uid='forums.receivers') +post_save.connect(on_post_save, sender=Post, dispatch_uid='forums.receivers') +post_delete.connect(on_post_delete, sender=Post, dispatch_uid='forums.receivers') diff -r 0b6bf9c5a982 -r 5902dc5e58a3 forums/signals.py --- a/forums/signals.py Mon Apr 06 20:33:10 2015 -0500 +++ b/forums/signals.py Tue Apr 07 20:11:32 2015 -0500 @@ -1,68 +1,10 @@ """ -Signal handlers & signals for the forums application. +Signals for the forums application. """ -from django.db.models.signals import post_save -from django.db.models.signals import post_delete import django.dispatch -from forums.models import Forum, Topic, Post - -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() - forums.latest.notify_topic_delete(topic) - - -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() - - -def on_post_delete(sender, **kwargs): - post = kwargs['instance'] - - # update the topic - try: - post.topic.post_count_update() - post.topic.save() - except Topic.DoesNotExist: - pass - else: - # update the forum - try: - post.topic.forum.post_count_update() - post.topic.forum.save() - except Forum.DoesNotExist: - pass - - -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') - - -# Signals for the forums application. -# # This signal is sent when a topic has had its textual content (title) changed. # The provided arguments are: # sender - the topic model instance @@ -108,7 +50,3 @@ """ post_content_update.send_robust(post, created=False) - - -# Avoid circular imports -import forums.latest