changeset 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
files gpp/forums/unread.py gpp/forums/urls.py gpp/forums/views.py
diffstat 3 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/forums/unread.py	Sun Jan 24 22:33:11 2010 +0000
+++ b/gpp/forums/unread.py	Tue Jan 26 04:10:11 2010 +0000
@@ -221,7 +221,8 @@
         else:
             flv = flvs[forum.id]
             topics |= Topic.objects.filter(forum=forum,
-                update_date__gt=flv.begin_date).order_by('-update_date').select_related()
+                update_date__gt=flv.begin_date).order_by('-update_date').select_related(
+                    'forum', 'user', 'last_post', 'last_post__user')
 
     if topics is not None:
         # get all topic last visit records for the topics of interest
--- a/gpp/forums/urls.py	Sun Jan 24 22:33:11 2010 +0000
+++ b/gpp/forums/urls.py	Tue Jan 26 04:10:11 2010 +0000
@@ -22,6 +22,7 @@
     url(r'^post/(\d+)/$', 'goto_post', name='forums-goto_post'),
     url(r'^post/new/(?P<topic_id>\d+)/$', 'new_post', name='forums-new_post'),
     url(r'^quick-reply/$', 'quick_reply_ajax', name='forums-quick_reply'),
+    url(r'^unanswered/$', 'unanswered_topics', name='forums-unanswered_topics'),
     url(r'^unread/$', 'unread_topics', name='forums-unread_topics'),
 )
 
--- 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.