python学习

This commit is contained in:
2019-07-22 17:58:38 +08:00
parent b5cd21d1ae
commit 0ba940441f
5 changed files with 177 additions and 189 deletions

View File

@@ -1,6 +1,54 @@
# -*- coding: utf-8 -*-
from flask import g,render_template
import datetime
'''
自定义分页类
'''
def iPagination( params ):
import math
ret = {
"is_prev":1,
"is_next":1,
"from" :0 ,
"end":0,
"current":0,
"total_pages":0,
"page_size" : 0,
"total" : 0,
"url":params['url'].replace("&p=","")
}
total = int( params['total'] )
page_size = int( params['page_size'] )
page = int( params['page'] )
display = int( params['display'] )
total_pages = int( math.ceil( total / page_size ) )
total_pages = total_pages if total_pages > 0 else 1
if page <= 1:
ret['is_prev'] = 0
if page >= total_pages:
ret['is_next'] = 0
semi = int( math.ceil( display / 2 ) )
if page - semi > 0 :
ret['from'] = page - semi
else:
ret['from'] = 1
if page + semi <= total_pages :
ret['end'] = page + semi
else:
ret['end'] = total_pages
ret['current'] = page
ret['total_pages'] = total_pages
ret['page_size'] = page_size
ret['total'] = total
ret['range'] = range( ret['from'],ret['end'] + 1 )
return ret
'''