comparison 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
comparison
equal deleted inserted replaced
167:cf9f9d4c4d54 168:e6d4dfdfbc64
74 """ 74 """
75 # check for special forum queries 75 # check for special forum queries
76 query = request.GET.get("query") 76 query = request.GET.get("query")
77 if query == "unread": 77 if query == "unread":
78 return HttpResponseRedirect(reverse('forums-unread_topics')) 78 return HttpResponseRedirect(reverse('forums-unread_topics'))
79 elif query == "unanswered":
80 return HttpResponseRedirect(reverse('forums-unanswered_topics'))
79 81
80 forums = Forum.objects.forums_for_user(request.user) 82 forums = Forum.objects.forums_for_user(request.user)
81 get_forum_unread_status(forums, request.user) 83 get_forum_unread_status(forums, request.user)
82 cats = {} 84 cats = {}
83 for forum in forums: 85 for forum in forums:
641 context_instance=RequestContext(request)) 643 context_instance=RequestContext(request))
642 644
643 645
644 @login_required 646 @login_required
645 def unread_topics(request): 647 def unread_topics(request):
648 """Displays the topics with unread posts for a given user."""
649
646 topics = get_unread_topics(request.user) 650 topics = get_unread_topics(request.user)
647 651
648 paginator = create_topic_paginator(topics) 652 paginator = create_topic_paginator(topics)
649 page_num = get_page_num(request) 653 page_num = get_page_num(request)
650 try: 654 try:
657 # we do this for the template since it is rendered twice 661 # we do this for the template since it is rendered twice
658 page_nav = render_to_string('forums/pagination.html', {'page': page}) 662 page_nav = render_to_string('forums/pagination.html', {'page': page})
659 663
660 return render_to_response('forums/topic_list.html', { 664 return render_to_response('forums/topic_list.html', {
661 'title': 'Topics With Unread Posts', 665 'title': 'Topics With Unread Posts',
666 'page': page,
667 'page_nav': page_nav,
668 },
669 context_instance=RequestContext(request))
670
671
672 def unanswered_topics(request):
673 """Displays the topics with no replies."""
674
675 forum_ids = Forum.objects.forum_ids_for_user(request.user)
676 topics = Topic.objects.filter(forum__id__in=forum_ids,
677 post_count=1).select_related(
678 'forum', 'user', 'last_post', 'last_post__user')
679
680 paginator = create_topic_paginator(topics)
681 page_num = get_page_num(request)
682 try:
683 page = paginator.page(page_num)
684 except InvalidPage:
685 raise Http404
686
687 attach_topic_page_ranges(page.object_list)
688
689 # we do this for the template since it is rendered twice
690 page_nav = render_to_string('forums/pagination.html', {'page': page})
691
692 return render_to_response('forums/topic_list.html', {
693 'title': 'Unanswered Topics',
662 'page': page, 694 'page': page,
663 'page_nav': page_nav, 695 'page_nav': page_nav,
664 }, 696 },
665 context_instance=RequestContext(request)) 697 context_instance=RequestContext(request))
666 698