1 Star 0 Fork 13

玛丽1号/rainbond-console

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tools.py 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding: utf8 -*-
from django.core.paginator import Paginator
import logging
logger = logging.getLogger('default')
class JuncheePaginator(Paginator):
def __init__(self, object_list, per_page, range_num=5, orphans=0, allow_empty_first_page=True):
Paginator.__init__(self, object_list, per_page, orphans, allow_empty_first_page)
self.range_num = range_num
def page(self, number):
self.page_num = number
return super(JuncheePaginator, self).page(number)
def _page_range_ext(self):
num_count = 2 * self.range_num + 1
if self.num_pages <= num_count:
return list(range(1, self.num_pages + 1))
num_list = []
num_list.append(self.page_num)
for i in range(1, self.range_num + 1):
if self.page_num - i <= 0:
num_list.append(num_count + self.page_num - i)
else:
num_list.append(self.page_num - i)
if self.page_num + i <= self.num_pages:
num_list.append(self.page_num + i)
else:
num_list.append(self.page_num + i - num_count)
num_list.sort()
return num_list
page_range_ext = property(_page_range_ext)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mary-no1/rainbond-console.git
git@gitee.com:mary-no1/rainbond-console.git
mary-no1
rainbond-console
rainbond-console
main

搜索帮助