diff gpp/forums/views.py @ 168:e6d4dfdfbc64

Implemented a view to display topics with unanswered posts. This is for ticket #54.
author Brian Neal <bgneal@gmail.com>
date Tue, 26 Jan 2010 04:10:11 +0000
parents cf9f9d4c4d54
children 7071b196ddd5
line wrap: on
line diff
--- a/gpp/forums/views.py	Sun Jan 24 22:33:11 2010 +0000
+++ b/gpp/forums/views.py	Tue Jan 26 04:10:11 2010 +0000
@@ -76,6 +76,8 @@
     query = request.GET.get("query")
     if query == "unread":
         return HttpResponseRedirect(reverse('forums-unread_topics'))
+    elif query == "unanswered":
+        return HttpResponseRedirect(reverse('forums-unanswered_topics'))
 
     forums = Forum.objects.forums_for_user(request.user)
     get_forum_unread_status(forums, request.user)
@@ -643,6 +645,8 @@
 
 @login_required
 def unread_topics(request):
+    """Displays the topics with unread posts for a given user."""
+
     topics = get_unread_topics(request.user)
 
     paginator = create_topic_paginator(topics)
@@ -665,6 +669,34 @@
         context_instance=RequestContext(request))
 
 
+def unanswered_topics(request):
+    """Displays the topics with no replies."""
+
+    forum_ids = Forum.objects.forum_ids_for_user(request.user)
+    topics = Topic.objects.filter(forum__id__in=forum_ids,
+            post_count=1).select_related(
+                    'forum', 'user', 'last_post', 'last_post__user')
+
+    paginator = create_topic_paginator(topics)
+    page_num = get_page_num(request)
+    try:
+        page = paginator.page(page_num)
+    except InvalidPage:
+        raise Http404
+
+    attach_topic_page_ranges(page.object_list)
+
+    # we do this for the template since it is rendered twice
+    page_nav = render_to_string('forums/pagination.html', {'page': page})
+
+    return render_to_response('forums/topic_list.html', {
+        'title': 'Unanswered Topics',
+        'page': page,
+        'page_nav': page_nav,
+        },
+        context_instance=RequestContext(request))
+
+
 def _can_moderate(forum, user):
     """
     Determines if a user has permission to moderate a given forum.