changeset 529:7388cdf61b25

For #241, add a URL to view the last post in a forum topic.
author Brian Neal <bgneal@gmail.com>
date Thu, 22 Dec 2011 02:10:27 +0000
parents 311c926dd218
children 06baec10cd20
files gpp/forums/latest.py gpp/forums/models.py gpp/forums/urls.py gpp/forums/views/main.py
diffstat 4 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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
--- 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<tid>\d+)$', 'new_topic_thanks', name='forums-new_topic_thanks'),
     url(r'^topic/(?P<id>\d+)/$', 'topic_index', name='forums-topic_index'),
     url(r'^topic/(?P<id>\d+)/unread/$', 'topic_unread', name='forums-topic_unread'),
+    url(r'^topic/(?P<id>\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<id>\d+)/$', 'edit_post', name='forums-edit_post'),
--- 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):
     """