# HG changeset patch # User Brian Neal # Date 1299547016 0 # Node ID 6f963e5e7b03ed76a0a6fb055dbadcb05f322366 # Parent fe1896e14c11c8d8a20cba457017edece373c306 Fixing #156; improve upon the work done in r397. Use the forum last visit record if there is no topic last visit record. diff -r fe1896e14c11 -r 6f963e5e7b03 gpp/forums/views/main.py --- 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