DjangoBB

Django based forum engine

  • You are not logged in.

#1 Aug. 11, 2011 20:59:23

LuckyB
Registered: 2011-08-11
Posts: 1
Reputation: +  0  -
Profile   Send e-mail  

Topic Pagination in forum view

Hello all, thought this might be useful for some people, I added per topic pagination to my forum on the forum view.

Here's the templatetag to do it:

from django.core.paginator import Paginator, EmptyPage, InvalidPage
@register.inclusion_tag('forum/pagination.html')
def topic_pagination(topic, adjacent_pages=7):
"""
Return the list of A tags with links to pages.
"""
paginator = Paginator(topic.posts.all(), forum_settings.TOPIC_PAGE_SIZE)
num_pages = paginator.num_pages
page_range = range(1, min(num_pages, 1 + adjacent_pages) + 1)
previous = None
next = None

last_post = topic.last_post

if not 1 in page_range:
page_range.insert(0,1)
if not 2 in page_range:
page_range.insert(1,'.')


if not num_pages in page_range:
if not num_pages - 1 in page_range:
page_range.append('.')
page_range.append(num_pages)

get_params = topic.get_absolute_url()+'?'

return {
'get_params': get_params,
'previous': None,
'next': None,
'page': None,
'pages': num_pages,
'page_range': page_range,
'results_per_page': paginator.per_page,
'is_paginated': paginator.num_pages > 1,
}

In the default forum template (forum/forum.html) I just added this html to div.tclcon:
<div class="pagelink">{% topic_pagination topic 5 %}</div>

And finally to the base.css:
.tcl .pagelink {
margin: 2px 0 0 2px;
color: #999;

}
.tcl .pagelink a {
text-decoration: none;
font-size: 10px;
color: #777;
margin-right 1px;
padding: 1px 2px;
}

.tcl .pagelink a:hover {
background: #333;
color: #F8F8F8;
}

Edited LuckyB (Aug. 11, 2011 21:02:33)

Offline

Board footer

Moderator control

Powered by DjangoBB

Lo-Fi Version