Mercurial > public > sg101
comparison gpp/forums/views/main.py @ 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 | dd673fae508d |
children | a1b03de20345 |
comparison
equal
deleted
inserted
replaced
375:fe1896e14c11 | 376:6f963e5e7b03 |
---|---|
249 | 249 |
250 """ | 250 """ |
251 topic_url = reverse('forums-topic_index', kwargs={'id': id}) | 251 topic_url = reverse('forums-topic_index', kwargs={'id': id}) |
252 | 252 |
253 if request.user.is_authenticated(): | 253 if request.user.is_authenticated(): |
254 topic = get_object_or_404(Topic.objects.select_related(depth=1), pk=id) | |
254 try: | 255 try: |
255 tlv = TopicLastVisit.objects.get(user=request.user, topic=id) | 256 tlv = TopicLastVisit.objects.get(user=request.user, topic=topic) |
256 except TopicLastVisit.DoesNotExist: | 257 except TopicLastVisit.DoesNotExist: |
257 return HttpResponseRedirect(topic_url) | 258 try: |
258 | 259 flv = ForumLastVisit.objects.get(user=request.user, |
259 posts = Post.objects.filter(topic=id, creation_date__gt=tlv.last_visit) | 260 forum=topic.forum) |
261 except ForumLastVisit.DoesNotExist: | |
262 return HttpResponseRedirect(topic_url) | |
263 else: | |
264 last_visit = flv.begin_date | |
265 else: | |
266 last_visit = tlv.last_visit | |
267 | |
268 posts = Post.objects.filter(topic=topic, creation_date__gt=last_visit) | |
260 if posts: | 269 if posts: |
261 return _goto_post(posts[0]) | 270 return _goto_post(posts[0]) |
262 else: | 271 else: |
263 # just go to the last post in the topic | 272 # just go to the last post in the topic |
264 topic = get_object_or_404(Topic.objects.select_related('last_post'), pk=id) | |
265 return _goto_post(topic.last_post) | 273 return _goto_post(topic.last_post) |
266 | 274 |
267 # user isn't authenticated, just go to the topic | 275 # user isn't authenticated, just go to the topic |
268 return HttpResponseRedirect(topic_url) | 276 return HttpResponseRedirect(topic_url) |
269 | 277 |