This repository has been archived on 2025-05-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
s2forums/djangobb_forum/signals.py

33 lines
952 B
Python
Raw Permalink Normal View History

2011-08-11 17:15:08 +03:00
from django.db.models.signals import post_save
2013-01-30 19:15:52 -05:00
from django.utils import timezone
2009-05-24 18:50:57 +03:00
2010-10-30 09:03:50 +03:00
from djangobb_forum.subscription import notify_topic_subscribers
from djangobb_forum.models import Topic, Post
2009-01-19 19:50:01 +02:00
2009-01-19 19:50:01 +02:00
def post_saved(instance, **kwargs):
2009-05-24 18:50:57 +03:00
created = kwargs.get('created')
post = instance
topic = post.topic
2009-05-24 22:51:42 +03:00
if created:
topic.last_post = post
topic.post_count = topic.posts.count()
2013-01-30 19:15:52 -05:00
topic.updated = timezone.now()
2009-10-23 13:12:35 +03:00
profile = post.user.forum_profile
profile.post_count = post.user.posts.count()
profile.save(force_update=True)
topic.save(force_update=True)
if created:
notify_topic_subscribers(post)
2009-05-24 18:50:57 +03:00
2009-10-19 17:23:36 +03:00
2009-05-24 18:50:57 +03:00
def topic_saved(instance, **kwargs):
topic = instance
forum = topic.forum
forum.topic_count = forum.topics.count()
forum.updated = topic.updated
forum.post_count = forum.posts.count()
2010-11-28 09:56:40 +02:00
forum.last_post_id = topic.last_post_id
forum.save(force_update=True)