changeset 376:6f963e5e7b03

Fixing #156; improve upon the work done in r397. Use the forum last visit record if there is no topic last visit record.
author Brian Neal <bgneal@gmail.com>
date Tue, 08 Mar 2011 01:16:56 +0000
parents fe1896e14c11
children 59aaba88405e
files gpp/forums/views/main.py
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/forums/views/main.py	Tue Mar 08 00:50:33 2011 +0000
+++ b/gpp/forums/views/main.py	Tue Mar 08 01:16:56 2011 +0000
@@ -251,17 +251,25 @@
     topic_url = reverse('forums-topic_index', kwargs={'id': id})
 
     if request.user.is_authenticated():
+        topic = get_object_or_404(Topic.objects.select_related(depth=1), pk=id)
         try:
-            tlv = TopicLastVisit.objects.get(user=request.user, topic=id)
+            tlv = TopicLastVisit.objects.get(user=request.user, topic=topic)
         except TopicLastVisit.DoesNotExist:
-            return HttpResponseRedirect(topic_url)
+            try:
+                flv = ForumLastVisit.objects.get(user=request.user,
+                        forum=topic.forum)
+            except ForumLastVisit.DoesNotExist:
+                return HttpResponseRedirect(topic_url)
+            else:
+                last_visit = flv.begin_date
+        else:
+            last_visit = tlv.last_visit
 
-        posts = Post.objects.filter(topic=id, creation_date__gt=tlv.last_visit)
+        posts = Post.objects.filter(topic=topic, creation_date__gt=last_visit)
         if posts:
             return _goto_post(posts[0])
         else:
             # just go to the last post in the topic
-            topic = get_object_or_404(Topic.objects.select_related('last_post'), pk=id)
             return _goto_post(topic.last_post)
 
     # user isn't authenticated, just go to the topic