threadstracker.py 996 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from ..threads.models import Post
  2. from ..threads.permissions import exclude_invisible_posts
  3. from .dates import get_cutoff_date
  4. def make_read_aware(user, user_acl, threads):
  5. if not threads:
  6. return
  7. if not hasattr(threads, "__iter__"):
  8. threads = [threads]
  9. make_read(threads)
  10. if user.is_anonymous:
  11. return
  12. categories = [t.category for t in threads]
  13. queryset = (
  14. Post.objects.filter(thread__in=threads, posted_on__gt=get_cutoff_date(user))
  15. .values_list("thread", flat=True)
  16. .distinct()
  17. )
  18. queryset = queryset.exclude(id__in=user.postread_set.values("post"))
  19. queryset = exclude_invisible_posts(user_acl, categories, queryset)
  20. unread_threads = list(queryset)
  21. for thread in threads:
  22. if thread.pk in unread_threads:
  23. thread.is_read = False
  24. thread.is_new = True
  25. def make_read(threads):
  26. for thread in threads:
  27. thread.is_read = True
  28. thread.is_new = False