diff gpp/forums/unread.py @ 408:7e0997b08b50

Fixes for #200; fix bug in deciding which forums have unread posts.
author Brian Neal <bgneal@gmail.com>
date Sat, 02 Apr 2011 00:12:40 +0000
parents 42a4e66972d5
children c06d836c8b84
line wrap: on
line diff
--- a/gpp/forums/unread.py	Fri Apr 01 01:18:44 2011 +0000
+++ b/gpp/forums/unread.py	Sat Apr 02 00:12:40 2011 +0000
@@ -7,7 +7,6 @@
 import logging
 
 from django.db import IntegrityError
-from django.db.models import Q
 
 from forums.models import ForumLastVisit, TopicLastVisit, Topic, Forum
 
@@ -85,8 +84,10 @@
 
             topics = Topic.objects.filter(forum=forum,
                     creation_date__gt=flv.begin_date)
-            tracked_topics = TopicLastVisit.objects.filter(user=user,
-                    topic__forum=forum, last_visit__gt=flv.begin_date)
+            tracked_topics = TopicLastVisit.objects.filter(
+                    user=user,
+                    topic__forum=forum,
+                    last_visit__gt=flv.begin_date).select_related('topic')
 
             # If the number of topics created since our window was started 
             # is greater than the tracked topic records, then there are new
@@ -95,7 +96,7 @@
                 forum.has_unread = True
                 continue
 
-            tracked_dict = dict([(t.id, t) for t in tracked_topics])
+            tracked_dict = dict((t.topic.id, t) for t in tracked_topics)
 
             for topic in topics:
                 if topic.id in tracked_dict: