forumreadmodel.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. from datetime import timedelta
  2. from django.conf import settings
  3. from django.db import models
  4. from django.utils import timezone
  5. from misago.forums.signals import move_forum_content
  6. from misago.threads.signals import move_thread
  7. class ForumRead(models.Model):
  8. user = models.ForeignKey('User')
  9. forum = models.ForeignKey('Forum')
  10. updated = models.DateTimeField()
  11. cleared = models.DateTimeField()
  12. class Meta:
  13. app_label = 'misago'
  14. def get_threads(self):
  15. threads = {}
  16. for thread in ThreadRecord.objects.filter(user=self.user, forum=self.forum, updated__gte=(timezone.now() - timedelta(days=settings.READS_TRACKER_LENGTH))):
  17. threads[thread.thread_id] = thread
  18. return threads
  19. def move_forum_content_handler(sender, **kwargs):
  20. ForumRead.objects.filter(forum=sender).delete()
  21. ForumRead.objects.filter(forum=kwargs['move_to']).delete()
  22. move_forum_content.connect(move_forum_content_handler, dispatch_uid="move_forum_reads")