2009-05-24 18:50:57 +03:00
from datetime import datetime
2009-12-24 17:24:39 +02:00
2009-05-24 18:50:57 +03:00
from django . db . models . signals import post_save , pre_save , post_delete
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-12-24 17:24:39 +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
2009-12-24 17:24:39 +02:00
topic = post . topic
2009-05-24 22:51:42 +03:00
2009-12-24 17:24:39 +02:00
if created :
topic . last_post = post
topic . post_count = topic . posts . count ( )
2009-12-29 16:32:14 +02:00
topic . updated = datetime . 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 )
2009-05-24 18:50:57 +03:00
notify_topic_subscribers ( post )
2009-12-24 17:24:39 +02:00
topic . save ( force_update = True )
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 ) :
created = kwargs . get ( ' created ' )
topic = instance
2009-12-24 17:24:39 +02:00
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
2009-12-24 17:24:39 +02:00
forum . save ( force_update = True )
2009-05-24 18:50:57 +03:00
2009-01-19 19:50:01 +02:00
post_save . connect ( post_saved , sender = Post )
2009-05-24 18:50:57 +03:00
post_save . connect ( topic_saved , sender = Topic )