diff --git a/suit/templatetags/suit_list.py b/suit/templatetags/suit_list.py
index 89a3d432..48cc40e7 100644
--- a/suit/templatetags/suit_list.py
+++ b/suit/templatetags/suit_list.py
@@ -9,32 +9,31 @@
from django.contrib.admin.templatetags.admin_list import result_list
from django.contrib.admin.views.main import ALL_VAR, PAGE_VAR
from django.utils.html import escape
+from django.utils.html import format_html
from suit.compat import tpl_context_class
register = template.Library()
-DOT = '.'
-
@register.simple_tag
def paginator_number(cl, i):
"""
Generates an individual page index link in a paginated list.
"""
- if i == DOT:
- return mark_safe(
- '
..'
- '.')
+ if i == cl.paginator.ELLIPSIS:
+ return format_html(
+ '{}'
+ '', cl.paginator.ELLIPSIS)
elif i == cl.page_num:
- return mark_safe(
- '%d ' % (i + 1))
+ return format_html(
+ '{} ', i)
else:
- return mark_safe('%d ' % (
+ return format_html('{} ',
escape(cl.get_query_string({PAGE_VAR: i})),
- (i == cl.paginator.num_pages - 1 and ' class="end"' or ''),
- i + 1))
+ (' class="end"' if i == cl.paginator.num_pages else ''),
+ i)
@register.simple_tag
@@ -47,7 +46,8 @@ def paginator_info(cl):
entries_to = paginator.count
else:
entries_from = (
- (paginator.per_page * cl.page_num) + 1) if paginator.count > 0 else 0
+ # (paginator.per_page * cl.page_num) + 1) if paginator.count > 0 else 0
+ (paginator.per_page * (cl.page_num - 1)) + 1) if paginator.count > 0 else 0
entries_to = entries_from - 1 + paginator.per_page
if paginator.count < entries_to:
entries_to = paginator.count
@@ -58,42 +58,11 @@ def paginator_info(cl):
@register.inclusion_tag('admin/pagination.html')
def pagination(cl):
"""
- Generates the series of links to the pages in a paginated list.
+ Generate the series of links to the pages in a paginated list.
"""
paginator, page_num = cl.paginator, cl.page_num
-
- pagination_required = (not cl.show_all or not cl.can_show_all) \
- and cl.multi_page
- if not pagination_required:
- page_range = []
- else:
- ON_EACH_SIDE = 3
- ON_ENDS = 2
-
- # If there are 10 or fewer pages, display links to every page.
- # Otherwise, do some fancy
- if paginator.num_pages <= 8:
- page_range = range(paginator.num_pages)
- else:
- # Insert "smart" pagination links, so that there are always ON_ENDS
- # links at either end of the list of pages, and there are always
- # ON_EACH_SIDE links at either end of the "current page" link.
- page_range = []
- if page_num > (ON_EACH_SIDE + ON_ENDS):
- page_range.extend(range(0, ON_EACH_SIDE - 1))
- page_range.append(DOT)
- page_range.extend(range(page_num - ON_EACH_SIDE, page_num + 1))
- else:
- page_range.extend(range(0, page_num + 1))
- if page_num < (paginator.num_pages - ON_EACH_SIDE - ON_ENDS - 1):
- page_range.extend(
- range(page_num + 1, page_num + ON_EACH_SIDE + 1))
- page_range.append(DOT)
- page_range.extend(
- range(paginator.num_pages - ON_ENDS, paginator.num_pages))
- else:
- page_range.extend(range(page_num + 1, paginator.num_pages))
-
+ pagination_required = (not cl.show_all or not cl.can_show_all) and cl.multi_page # NEW
+ page_range = cl.paginator.get_elided_page_range(cl.page_num) if pagination_required else [] # NEW
need_show_all_link = cl.can_show_all and not cl.show_all and cl.multi_page
return {
'cl': cl,