root/trunk/common/templatetags/pagination.py

Revision 61, 1.0 kB (checked in by nobu, 9 months ago)
  • ページャーのトータルカウントが表示されていないのを修正。
Line 
1 # vim: encoding=utf-8 :
2
3 from django.template import Library
4
5 register = Library()
6
7 @register.inclusion_tag('common/_pagination.html')
8 def pagination(page_obj, path=''):
9     """
10     Create pagination.
11     """
12     paginator = page_obj.paginator
13     page = page_obj.number
14     num_pages = paginator.num_pages
15     if page <= 5 and page >= num_pages - 4:
16         startwith = 1
17         endwith = num_pages + 1
18     elif page <= 5 and page < num_pages - 4:
19         startwith = 1
20         if num_pages > 9:
21             endwith = 10
22         else:
23             endwith = num_pages + 1
24     elif page > 5 and page >= num_pages - 4:
25         if num_pages < 9:
26             startwith = 1
27         else:
28             startwith = num_pages - 8
29         endwith = num_pages + 1
30     else:
31         startwith = page - 4
32         endwith = page + 5
33    
34     return {
35         'PATH_INFO': path,
36         'hits': paginator.count,
37         'num_pages': num_pages,
38         'page': page,
39         'page_counter': range(startwith, endwith),
40         'page_obj': page_obj,
41     }
Note: See TracBrowser for help on using the browser.