# HG changeset patch # User Brian Neal # Date 1301705225 0 # Node ID c374bfd5594f878f23cdf95c2903e522740da1c3 # Parent 7e0997b08b500736a940f5ad989fdd9367d77e8d 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. diff -r 7e0997b08b50 -r c374bfd5594f gpp/forums/urls.py --- a/gpp/forums/urls.py Sat Apr 02 00:12:40 2011 +0000 +++ b/gpp/forums/urls.py Sat Apr 02 00:47:05 2011 +0000 @@ -9,6 +9,7 @@ url(r'^new-topic-success/(?P\d+)$', 'new_topic_thanks', name='forums-new_topic_thanks'), url(r'^topic/(?P\d+)/$', 'topic_index', name='forums-topic_index'), url(r'^topic/(?P\d+)/unread/$', 'topic_unread', name='forums-topic_unread'), + url(r'^topic/active/(\d+)/$', 'active_topics', name='forums-active_topics'), url(r'^delete-post/$', 'delete_post', name='forums-delete_post'), url(r'^edit/(?P\d+)/$', 'edit_post', name='forums-edit_post'), url(r'^flag-post/$', 'flag_post', name='forums-flag_post'), diff -r 7e0997b08b50 -r c374bfd5594f gpp/forums/views/main.py --- a/gpp/forums/views/main.py Sat Apr 02 00:12:40 2011 +0000 +++ b/gpp/forums/views/main.py Sat Apr 02 00:47:05 2011 +0000 @@ -863,6 +863,47 @@ context_instance=RequestContext(request)) +def active_topics(request, num): + """Displays the last num topics that have been posted to.""" + + # sanity check num + num = min(50, max(10, int(num))) + + public_forum_ids = Forum.objects.public_forum_ids() + + # MySQL didn't do this query very well unfortunately... + #topics = Topic.objects.filter(forum__in=public_forum_ids).select_related( + # 'forum', 'user', 'last_post', 'last_post__user').order_by( + # '-update_date')[:num] + topic_ids = list(Topic.objects.filter(forum__in=public_forum_ids).order_by( + '-update_date').values_list('id', flat=True)[:num]) + topics = Topic.objects.filter(id__in=topic_ids).select_related( + 'forum', 'user', 'last_post', 'last_post__user').order_by( + '-update_date')[:num] + + 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}) + + title = 'Last %d Active Topics' % num + + return render_to_response('forums/topic_list.html', { + 'title': title, + 'page': page, + 'page_nav': page_nav, + 'unread': False, + }, + context_instance=RequestContext(request)) + + @login_required def my_posts(request): """Displays a list of posts the requesting user made.""" diff -r 7e0997b08b50 -r c374bfd5594f gpp/templates/forums/forum_query.html --- a/gpp/templates/forums/forum_query.html Sat Apr 02 00:12:40 2011 +0000 +++ b/gpp/templates/forums/forum_query.html Sat Apr 02 00:47:05 2011 +0000 @@ -1,7 +1,10 @@ {% load url from future %}