-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,52 @@ | |||
from django.dispatch import receiver | |||
from django.db.models.signals import post_save, post_delete, pre_delete | |||
|
|||
from agora.models import ForumThread, ForumReply, ThreadSubscription, UserPostCount | |||
|
|||
|
|||
@receiver(post_save, ForumThread) | |||
def forum_thread_save(sender, instance=None, created=False, **kwargs): | |||
if instance and created: | |||
forum = instance.forum | |||
forum.new_post(instance) | |||
|
|||
# @@@ this next part could be manager method | |||
post_count, created = UserPostCount.objects.get_or_create(user=instance.author) | |||
post_count.count += 1 | |||
post_count.save() | |||
|
|||
|
|||
@receiver(post_save, ForumReply) | |||
def forum_reply_save(sender, instance=None, created=False, **kwargs): | |||
if instance and created: | |||
thread = instance.thread | |||
thread.new_reply(instance) | |||
|
|||
# @@@ this next part could be manager method | |||
post_count, created = UserPostCount.objects.get_or_create(user=instance.author) | |||
post_count.count += 1 | |||
post_count.save() | |||
|
|||
|
|||
@receiver(pre_delete, ForumThread) | |||
def forum_thread_delete(sender, **kwargs): | |||
thread = kwargs["instance"] | |||
if thread.id == thread.forum.last_thread_id: | |||
thread.forum.update_last_thread() | |||
thread.forum.update_view_count() | |||
thread.forum.update_post_count() | |||
|
|||
|
|||
@receiver(pre_delete, ForumReply) | |||
def forum_reply_delete(sender, **kwargs): | |||
reply = kwargs["instance"] | |||
if reply.id == reply.thread.last_reply_id: | |||
reply.thread.update_last_reply() | |||
reply.thread.forum.update_post_count() | |||
|
|||
|
|||
@receiver([post_save, post_delete], ThreadSubscription) | |||
def forum_subscription_update(sender, instance=None, created=False, **kwargs): | |||
if instance and created: | |||
thread = instance.thread | |||
thread.update_subscriber_count() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,15 +1,17 @@ | |||
from django.conf.urls.defaults import * | from django.conf.urls.defaults import * | ||
|
|
||
from agora import receivers | |||
|
|
||
urlpatterns = patterns("", |
|
||
url(r"^$", "agora.views.forums", name="agora_forums"), | urlpatterns = patterns("agora.views", | ||
url(r"^category/(\d+)/$", "agora.views.forum_category", name="agora_category"), | url(r"^$", "forums", name="agora_forums"), | ||
url(r"^forum/(\d+)/$", "agora.views.forum", name="agora_forum"), | url(r"^category/(\d+)/$", "forum_category", name="agora_category"), | ||
url(r"^thread/(\d+)/$", "agora.views.forum_thread", name="agora_thread"), | url(r"^forum/(\d+)/$", "forum", name="agora_forum"), | ||
url(r"^new_post/(\d+)/$", "agora.views.post_create", name="agora_post_create"), | url(r"^thread/(\d+)/$", "forum_thread", name="agora_thread"), | ||
url(r"^reply/(\d+)/$", "agora.views.reply_create", name="agora_reply_create"), | url(r"^new_post/(\d+)/$", "post_create", name="agora_post_create"), | ||
url(r"^post_edit/(thread|reply)/(\d+)/$", "agora.views.post_edit", name="agora_post_edit"), | url(r"^reply/(\d+)/$", "reply_create", name="agora_reply_create"), | ||
url(r"^subscribe/(\d+)/$", "agora.views.subscribe", name="agora_subscribe"), | url(r"^post_edit/(thread|reply)/(\d+)/$", "post_edit", name="agora_post_edit"), | ||
url(r"^unsubscribe/(\d+)/$", "agora.views.unsubscribe", name="agora_unsubscribe"), | url(r"^subscribe/(\d+)/$", "subscribe", name="agora_subscribe"), | ||
url(r"^thread_updates/$", "agora.views.thread_updates", name="agora_thread_updates"), | url(r"^unsubscribe/(\d+)/$", "unsubscribe", name="agora_unsubscribe"), | ||
url(r"^thread_updates/$", "thread_updates", name="agora_thread_updates"), | |||
) | ) |