# HG changeset patch # User Brian Neal # Date 1324519827 0 # Node ID 7388cdf61b2593a1c32fd794e4f7f050f22d787b # Parent 311c926dd21884515bddd42b9ab12d5d9d3657f8 For #241, add a URL to view the last post in a forum topic. diff -r 311c926dd218 -r 7388cdf61b25 gpp/forums/latest.py --- a/gpp/forums/latest.py Wed Dec 21 01:25:10 2011 +0000 +++ b/gpp/forums/latest.py Thu Dec 22 02:10:27 2011 +0000 @@ -151,7 +151,7 @@ 'title': post.topic.name, 'author': post.user.username, 'date': topic_score, - 'url': post.get_absolute_url() + 'url': post.topic.get_latest_post_url() } json = simplejson.dumps(topic_content) key = UPDATED_TOPIC_KEY % topic_id diff -r 311c926dd218 -r 7388cdf61b25 gpp/forums/models.py --- a/gpp/forums/models.py Wed Dec 21 01:25:10 2011 +0000 +++ b/gpp/forums/models.py Thu Dec 22 02:10:27 2011 +0000 @@ -198,6 +198,10 @@ def get_absolute_url(self): return ('forums-topic_index', [self.pk]) + @models.permalink + def get_latest_post_url(self): + return ('forums-topic_latest', [self.pk]) + def post_count_update(self): """ Call this function to notify the topic instance that its post count diff -r 311c926dd218 -r 7388cdf61b25 gpp/forums/urls.py --- a/gpp/forums/urls.py Wed Dec 21 01:25:10 2011 +0000 +++ b/gpp/forums/urls.py Thu Dec 22 02:10:27 2011 +0000 @@ -9,6 +9,7 @@ url(r'^new-topic-success/(?P\d+)$', 'new_topic_thanks', name='forums-new_topic_thanks'), url(r'^topic/(?P\d+)/$', 'topic_index', name='forums-topic_index'), url(r'^topic/(?P\d+)/unread/$', 'topic_unread', name='forums-topic_unread'), + url(r'^topic/(?P\d+)/latest/$', 'topic_latest', name='forums-topic_latest'), url(r'^topic/active/(\d+)/$', 'active_topics', name='forums-active_topics'), url(r'^delete-post/$', 'delete_post', name='forums-delete_post'), url(r'^edit/(?P\d+)/$', 'edit_post', name='forums-edit_post'), diff -r 311c926dd218 -r 7388cdf61b25 gpp/forums/views/main.py --- a/gpp/forums/views/main.py Wed Dec 21 01:25:10 2011 +0000 +++ b/gpp/forums/views/main.py Thu Dec 22 02:10:27 2011 +0000 @@ -287,6 +287,19 @@ return HttpResponseRedirect(topic_url) +def topic_latest(request, id): + """ + This view shows the latest (last) post in a given topic. + + """ + topic = get_object_or_404(Topic.objects.select_related(depth=1), pk=id) + + if topic.last_post: + return _goto_post(topic.last_post) + + raise Http404 + + @login_required def new_topic(request, slug): """