1 Star 0 Fork 7

xiaooooooooo/WebBlog

forked from thanatosx/WebBlog 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
base.py 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
thanatosx 提交于 2015-06-22 10:17 +08:00 . Thanatos Victoria
__author__ = 'thanatos'
class Dict(dict):
"""
Simple dict but support access as x.y style.
"""
def __init__(self, names=(), values=(), **kw):
super(Dict, self).__init__(**kw)
for k, v in zip(names, values):
self[k] = v
def __getattr__(self, key):
try:
return self[key]
except KeyError:
return None
def __setattr__(self, key, value):
self[key] = value
_PAGE_NAVIGATE = 5
class Page(Dict):
"""
a common page domain
"""
def __init__(self, current, page_size, records, data):
super().__init__()
self.current = current
self.page_size = page_size
self.records = records
self.data = data
self.page_count = (records + page_size - 1) // page_size
if self.page_count <= _PAGE_NAVIGATE:
self.begin_index = 1
self.end_index = self.page_count
elif current <= _PAGE_NAVIGATE // 2:
self.begin_index = 1
self.end_index = _PAGE_NAVIGATE
elif current + _PAGE_NAVIGATE // 2 > self.page_count:
self.begin_index = self.page_count - _PAGE_NAVIGATE + 1
self.end_index = self.page_count
else:
self.begin_index = current - _PAGE_NAVIGATE // 2
self.end_index = current - _PAGE_NAVIGATE // 2
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xiaooooooooo/WebBlog.git
git@gitee.com:xiaooooooooo/WebBlog.git
xiaooooooooo
WebBlog
WebBlog
master

搜索帮助