def assets(): _cnt = models.get_asset_count() _max_page_num = int(math.ceil(_cnt * 1.0 / gconf.PAGE_SIZE)) _machine_rooms = models.get_machine_rooms() params = request.args if request.method == 'GET' else request.form _query = params.get('query', '') # 分页信息 _page_num = params.get('pageNum', 1) _limit = params.get('pageSize', gconf.PAGE_SIZE) _page_num = int(_page_num) if str(_page_num).isdigit() else 1 _page_num = 1 if _page_num <= 0 else _page_num _page_num = _max_page_num if _page_num > _max_page_num else _page_num _offset = (_page_num - 1) * gconf.PAGE_SIZE _limit = _limit if str(_limit).isdigit() else gconf.PAGE_SIZE _assets = models.get_assets(_query, _offset, _limit) _start_page_num = _page_num - 2 if _page_num - 2 > 0 else 1 _end_page_num = _max_page_num if _start_page_num + 4 > _max_page_num else _start_page_num + 4 return render_template('assets.html', machineRooms=_machine_rooms, assets=_assets, query=_query, pageSize=gconf.PAGE_SIZE, pageNum=_page_num, maxPageNum=_max_page_num, startPageNum=_start_page_num, endPageNum=_end_page_num)
def asset_list(): assets = models.get_assets() return json.dumps({'data' : assets})
def asset(): params = request.args if request.method == 'GET' else request.form _query = params.get('query', '') _assets = models.get_assets(_query) return render_template('asset.html',assets = _assets, query = _query)