[extensions-web] paginator: Add ellipses and last page to clarify the paginator's behavior
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] paginator: Add ellipses and last page to clarify the paginator's behavior
- Date: Thu, 8 Dec 2011 17:25:01 +0000 (UTC)
commit 60209689db01a437764efb1fc529425eb66ab501
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Thu Dec 8 12:24:43 2011 -0500
paginator: Add ellipses and last page to clarify the paginator's behavior
sweettooth/extensions/templatetags/paginator.py | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/sweettooth/extensions/templatetags/paginator.py b/sweettooth/extensions/templatetags/paginator.py
index 8b4a100..f234a03 100644
--- a/sweettooth/extensions/templatetags/paginator.py
+++ b/sweettooth/extensions/templatetags/paginator.py
@@ -7,8 +7,9 @@ register = template.Library()
@register.simple_tag
def paginator(page_obj, context=3):
number = page_obj.number
+ num_pages = page_obj.paginator.num_pages
context_left = range(max(number-context, 2), number)
- context_right = range(number+1, min(number+context+1, page_obj.paginator.num_pages+1))
+ context_right = range(number+1, min(number+context, num_pages))
lines = []
@@ -26,6 +27,11 @@ def paginator(page_obj, context=3):
if page_obj.has_next():
for i in context_right:
lines.append(u'<a class="next number" href="?page=%d">%d</a>' % (i, i))
+
+ if num_pages - (number+context) > 2:
+ lines.append(u'<span class="ellipses">...</span>"')
+
+ lines.append(u'<a class="number first" href="?page=%d">%d</a>' % (num_pages, num_pages))
lines.append(u'<a class="number prev" href="?page=%d">Next</a>' % (number+1,))
return mark_safe(u'\n'.join(lines))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]