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

32 lines
952 B
Python

from django.db.models.signals import post_save
from django.utils import timezone
from djangobb_forum.subscription import notify_topic_subscribers
from djangobb_forum.models import Topic, Post
def post_saved(instance, **kwargs):
created = kwargs.get('created')
post = instance
topic = post.topic
if created:
topic.last_post = post
topic.post_count = topic.posts.count()
topic.updated = timezone.now()
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)
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()
forum.last_post_id = topic.last_post_id
forum.save(force_update=True)