1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 22:01:06 +00:00

Using django paginator in group discuss

This commit is contained in:
zhengxie
2013-03-19 11:49:52 +08:00
parent f3d0e46d42
commit 0808a7c654
3 changed files with 53 additions and 53 deletions

18
utils/paginator.py Normal file
View File

@@ -0,0 +1,18 @@
from django.core.paginator import Paginator as DefaultPaginator
class Paginator(DefaultPaginator):
def get_page_range(self, current_page=1):
"""
Returns custom range of pages.
"""
first_page = 1
total_page = self.num_pages
if total_page <= 10:
last_page = total_page
else:
if current_page < 6:
last_page = 10
else:
first_page = current_page - 5
last_page = current_page + 4 if current_page + 4 < total_page else total_page
return range(first_page, last_page + 1)