diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c4489e3..48221cf 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,8 @@ - - + + @@ -32,8 +32,8 @@ - - + + @@ -41,63 +41,41 @@ + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -176,8 +154,8 @@ @@ -218,87 +196,26 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - + + + + + + + @@ -403,7 +320,14 @@ @@ -417,6 +341,7 @@ + @@ -557,13 +482,6 @@ - - - - - - - @@ -591,13 +509,6 @@ - - - - - - - @@ -742,20 +653,6 @@ - - - - - - - - - - - - - - @@ -770,28 +667,26 @@ - - + + + - + - - + + - + - - - - - + + @@ -802,14 +697,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + diff --git a/common/libs/Helper.py b/common/libs/Helper.py index 72aea9b..acb2d5c 100644 --- a/common/libs/Helper.py +++ b/common/libs/Helper.py @@ -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 ''' diff --git a/config/base_setting.py b/config/base_setting.py index 0c861c4..434d3e8 100644 --- a/config/base_setting.py +++ b/config/base_setting.py @@ -13,4 +13,7 @@ IGNORE_URLS = [ IGNORE_CHECK_LOGIN_URLS = [ "^/static", "^/favicon.ico" -] \ No newline at end of file +] + +PAGE_SIZE = 50 +PAGE_DISPLAY = 10 \ No newline at end of file diff --git a/web/controllers/account/Account.py b/web/controllers/account/Account.py index 1acef2c..280a73f 100644 --- a/web/controllers/account/Account.py +++ b/web/controllers/account/Account.py @@ -1,15 +1,33 @@ # -*- coding: utf-8 -*- -from flask import Blueprint -from common.libs.Helper import ops_render +from flask import Blueprint,request,redirect +from common.libs.Helper import ops_render,iPagination from common.models.User import User route_account = Blueprint( 'account_page',__name__ ) - +from application import app,db @route_account.route( "/index" ) def index(): - resp_data={} - list = User.query.order_by(User.uid.desc()).all() - resp_data['list']=list - return ops_render( "account/index.html" ,resp_data) + resp_data = {} + req = request.values + page = int(req['p']) if ('p' in req and req['p']) else 1 + query = User.query + + page_params = { + 'total': query.count(), + 'page_size': app.config['PAGE_SIZE'], + 'page': page, + 'display': app.config['PAGE_DISPLAY'], + 'url': '/account/index' + } + + pages = iPagination(page_params) + offset = (page - 1) * app.config['PAGE_SIZE'] + limit = app.config['PAGE_SIZE'] * page + + list = query.order_by(User.uid.desc()).all()[offset:limit] + + resp_data['list'] = list + resp_data['pages'] = pages + return ops_render("account/index.html", resp_data) @route_account.route( "/info" ) def info(): diff --git a/web/templates/account/index.html b/web/templates/account/index.html index 7dcb1c7..82f787d 100644 --- a/web/templates/account/index.html +++ b/web/templates/account/index.html @@ -91,14 +91,8 @@ -
-
- 共1条记录 | 每页50条 -
    -
  • 1
  • -
-
-
+ + {% include 'common/pagenation.html' %} {% endblock %}