# HG changeset patch # User Brian Neal # Date 1252816395 0 # Node ID 4c33e266db03351049cce0aeadc22bc4c7658fbb # Parent 62eb9cbbcffcb730734971696ae0802396350392 Forums: paginate the topic list inside a forum. diff -r 62eb9cbbcffc -r 4c33e266db03 gpp/forums/templatetags/forum_tags.py --- a/gpp/forums/templatetags/forum_tags.py Sun Sep 13 04:09:08 2009 +0000 +++ b/gpp/forums/templatetags/forum_tags.py Sun Sep 13 04:33:15 2009 +0000 @@ -11,6 +11,6 @@ return {'post': post} -@register.inclusion_tag('forums/post_pagination.html') -def post_navigation(page): +@register.inclusion_tag('forums/pagination.html') +def forum_page_navigation(page): return {'page': page} diff -r 62eb9cbbcffc -r 4c33e266db03 gpp/forums/views.py --- a/gpp/forums/views.py Sun Sep 13 04:09:08 2009 +0000 +++ b/gpp/forums/views.py Sun Sep 13 04:33:15 2009 +0000 @@ -22,10 +22,14 @@ ####################################################################### +TOPICS_PER_PAGE = 50 POSTS_PER_PAGE = 2 -def create_paginator(links): - return DiggPaginator(links, POSTS_PER_PAGE, body=5, tail=2, margin=3, padding=2) +def create_topic_paginator(topics): + return DiggPaginator(topics, TOPICS_PER_PAGE, body=5, tail=2, margin=3, padding=2) + +def create_post_paginator(posts): + return DiggPaginator(posts, POSTS_PER_PAGE, body=5, tail=2, margin=3, padding=2) ####################################################################### @@ -57,10 +61,16 @@ """ forum = get_object_or_404(Forum, slug=slug) topics = forum.topics.select_related() + paginator = create_topic_paginator(topics) + page_num = int(request.GET.get('page', 1)) + try: + page = paginator.page(page_num) + except InvalidPage: + raise Http404 return render_to_response('forums/forum_index.html', { 'forum': forum, - 'topics': topics, + 'page': page, }, context_instance=RequestContext(request)) @@ -74,8 +84,8 @@ topic.save() posts = topic.posts.select_related() - paginator = create_paginator(posts) - page_num = int(request.GET.get('page', '1')) + paginator = create_post_paginator(posts) + page_num = int(request.GET.get('page', 1)) try: page = paginator.page(page_num) except InvalidPage: diff -r 62eb9cbbcffc -r 4c33e266db03 gpp/templates/forums/forum_index.html --- a/gpp/templates/forums/forum_index.html Sun Sep 13 04:09:08 2009 +0000 +++ b/gpp/templates/forums/forum_index.html Sun Sep 13 04:33:15 2009 +0000 @@ -10,7 +10,8 @@
-New Post +New Topic +{% forum_page_navigation page %} @@ -22,8 +23,8 @@ - {% for topic in topics %} - + {% for topic in page.object_list %} + @@ -41,5 +42,6 @@ {% endfor %}

{{ topic.name }}

{{ topic.reply_count }} {{ topic.user.username }}
+{% forum_page_navigation page %}
{% endblock %} diff -r 62eb9cbbcffc -r 4c33e266db03 gpp/templates/forums/last_post_info.html --- a/gpp/templates/forums/last_post_info.html Sun Sep 13 04:09:08 2009 +0000 +++ b/gpp/templates/forums/last_post_info.html Sun Sep 13 04:33:15 2009 +0000 @@ -1,5 +1,5 @@ {% if post %} -{{ post.update_date|date:"M d, Y H:i"}}
+{{ post.update_date|date:"M d, Y H:i"}}
{{ post.user.username }} {% else %} No posts diff -r 62eb9cbbcffc -r 4c33e266db03 gpp/templates/forums/pagination.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/forums/pagination.html Sun Sep 13 04:33:15 2009 +0000 @@ -0,0 +1,24 @@ +
+{% ifequal page.paginator.num_pages 1 %} +Page 1 of 1 +{% else %} +Goto Page: +{% if page.has_previous %} +Previous +{% endif %} +{% for num in page.page_range %} +{% if num %} +{% ifequal num page.number %} +{{ num }} +{% else %} +{{ num }} +{% endifequal %} +{% else %} +… +{% endif %} +{% endfor %} +{% if page.has_next %} +Next +{% endif %} +{% endifequal %} +
diff -r 62eb9cbbcffc -r 4c33e266db03 gpp/templates/forums/post_pagination.html --- a/gpp/templates/forums/post_pagination.html Sun Sep 13 04:09:08 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -
-{% ifequal page.paginator.num_pages 1 %} -Page 1 of 1 -{% else %} -Goto Page: -{% if page.has_previous %} -Previous -{% endif %} -{% for num in page.page_range %} -{% if num %} -{% ifequal num page.number %} -{{ num }} -{% else %} -{{ num }} -{% endifequal %} -{% else %} -… -{% endif %} -{% endfor %} -{% if page.has_next %} -Next -{% endif %} -{% endifequal %} -
diff -r 62eb9cbbcffc -r 4c33e266db03 gpp/templates/forums/topic.html --- a/gpp/templates/forums/topic.html Sun Sep 13 04:09:08 2009 +0000 +++ b/gpp/templates/forums/topic.html Sun Sep 13 04:33:15 2009 +0000 @@ -18,14 +18,14 @@ New Reply • {% endif %} New Topic -{% post_navigation page %} +{% forum_page_navigation page %} {% for post in page.object_list %} {% include 'forums/display_post.html' %} {% endfor %}
-{% post_navigation page %} +{% forum_page_navigation page %} {% if last_page and user.is_authenticated %}