1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 | from django import template
register = template.Library()
def paginator(context, adjacent=4):
"""
To be used in conjunction with the object_list generic view.
Adds pagination context variables for use in displaying first, adjacent and
last page links in addition to those created by the object_list generic
view.
"""
s = max(1, context["page"] - adjacent - max(0, context["page"]+adjacent-context["pages"]))
page_numbers = range(s, min(context["pages"], s+2*adjacent)+1)
ret_dict =\
{
"page_numbers": page_numbers,
"show_first": 1 not in page_numbers,
"show_last": context["pages"] not in page_numbers,
}
keys = ("hits", "results_per_page", "page", "pages", "next", "previous", "has_next", "has_previous")
for k in keys:
ret_dict.update({k: context[k]})
return ret_dict
register.inclusion_tag("paginator.html", takes_context=True)(paginator)
|
Comments