comparison gpp/forums/views/main.py @ 409:c374bfd5594f

Fixing #177; added a view to display the last x active topics (where x is between 10 and 50). Added a link to the view on the forum query drop down.
author Brian Neal <bgneal@gmail.com>
date Sat, 02 Apr 2011 00:47:05 +0000
parents 957955279a15
children 538a1bd2f1f4
comparison
equal deleted inserted replaced
408:7e0997b08b50 409:c374bfd5594f
861 'unread': False, 861 'unread': False,
862 }, 862 },
863 context_instance=RequestContext(request)) 863 context_instance=RequestContext(request))
864 864
865 865
866 def active_topics(request, num):
867 """Displays the last num topics that have been posted to."""
868
869 # sanity check num
870 num = min(50, max(10, int(num)))
871
872 public_forum_ids = Forum.objects.public_forum_ids()
873
874 # MySQL didn't do this query very well unfortunately...
875 #topics = Topic.objects.filter(forum__in=public_forum_ids).select_related(
876 # 'forum', 'user', 'last_post', 'last_post__user').order_by(
877 # '-update_date')[:num]
878 topic_ids = list(Topic.objects.filter(forum__in=public_forum_ids).order_by(
879 '-update_date').values_list('id', flat=True)[:num])
880 topics = Topic.objects.filter(id__in=topic_ids).select_related(
881 'forum', 'user', 'last_post', 'last_post__user').order_by(
882 '-update_date')[:num]
883
884 paginator = create_topic_paginator(topics)
885 page_num = get_page_num(request)
886 try:
887 page = paginator.page(page_num)
888 except InvalidPage:
889 raise Http404
890
891 attach_topic_page_ranges(page.object_list)
892
893 # we do this for the template since it is rendered twice
894 page_nav = render_to_string('forums/pagination.html', {'page': page})
895
896 title = 'Last %d Active Topics' % num
897
898 return render_to_response('forums/topic_list.html', {
899 'title': title,
900 'page': page,
901 'page_nav': page_nav,
902 'unread': False,
903 },
904 context_instance=RequestContext(request))
905
906
866 @login_required 907 @login_required
867 def my_posts(request): 908 def my_posts(request):
868 """Displays a list of posts the requesting user made.""" 909 """Displays a list of posts the requesting user made."""
869 return _user_posts(request, request.user, request.user, 'My Posts') 910 return _user_posts(request, request.user, request.user, 'My Posts')
870 911