# HG changeset patch # User Brian Neal # Date 1264479011 0 # Node ID e6d4dfdfbc64c793a8d709b431a100e25b6d2ba7 # Parent cf9f9d4c4d547971f9faedd41f7dec68dc0e8f67 Implemented a view to display topics with unanswered posts. This is for ticket #54. diff -r cf9f9d4c4d54 -r e6d4dfdfbc64 gpp/forums/unread.py --- 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 diff -r cf9f9d4c4d54 -r e6d4dfdfbc64 gpp/forums/urls.py --- 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\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'), ) diff -r cf9f9d4c4d54 -r e6d4dfdfbc64 gpp/forums/views.py --- 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.