Browse Source

Update threads read data when threads are moved to other forums

Ralfp 12 years ago
parent
commit
1be443b5d9
1 changed files with 15 additions and 1 deletions
  1. 15 1
      misago/readstracker/models.py

+ 15 - 1
misago/readstracker/models.py

@@ -2,6 +2,8 @@ from datetime import timedelta
 from django.conf import settings
 from django.db import models
 from django.utils import timezone
+from misago.forums.signals import move_forum_content
+from misago.threads.signals import move_thread
 
 class ThreadRecord(models.Model):
     user = models.ForeignKey('users.User')
@@ -20,4 +22,16 @@ class ForumRecord(models.Model):
         threads = {}
         for thread in ThreadRecord.objects.filter(user=self.user, forum=self.forum, updated__gte=(timezone.now() - timedelta(days=settings.READS_TRACKER_LENGTH))):
             threads[thread.thread_id] = thread
-        return threads
+        return threads
+
+
+def move_forum_content_handler(sender, **kwargs):
+    ForumRecord.objects.filter(forum=sender).delete()
+
+move_forum_content.connect(move_forum_content_handler, dispatch_uid="move_forum_threads_reads")
+
+
+def move_thread_handler(sender, **kwargs):
+    ThreadRecord.objects.filter(thread=sender).delete()
+
+move_thread.connect(move_thread_handler, dispatch_uid="move_thread_reads")