Mercurial > public > sg101
changeset 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 | 7e0997b08b50 |
children | fabdee634c9e |
files | gpp/forums/urls.py gpp/forums/views/main.py gpp/templates/forums/forum_query.html |
diffstat | 3 files changed, 45 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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<tid>\d+)$', 'new_topic_thanks', name='forums-new_topic_thanks'), url(r'^topic/(?P<id>\d+)/$', 'topic_index', name='forums-topic_index'), url(r'^topic/(?P<id>\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<id>\d+)/$', 'edit_post', name='forums-edit_post'), url(r'^flag-post/$', 'flag_post', name='forums-flag_post'),
--- 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."""
--- 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 %} <form action="." method="get" id="forum-query-form"> <select id="forum-query-select"> + {% if user.is_authenticated %} <option value="{% url 'forums-unread_topics' %}">Show topics with unread posts</option> + {% endif %} + <option value="{% url 'forums-active_topics' 30 %}">Show active topics</option> <option value="{% url 'forums-unanswered_topics' %}">Show unanswered topics</option> {% if user.is_authenticated %} <option value="{% url 'forums-my_posts' %}">Show my posts</option>