def show_modbus_page(): group_infos = [] if request.method == 'POST': id = int(request.form.get('id', 1)) - 1 pages = int(request.form.get('pages', 10)) page = int(request.form.get('page', 1)) cfg_msg = read_json() basic_config, data, group_infos = read_modbus_config(cfg_msg) config = { 'dev_id': basic_config['dev_id'], 'Coll_Type': basic_config['Coll_Type'], 'host': basic_config['TCP']['host'], 'port': basic_config['TCP']['port'], 'serial': basic_config['RTU']['serial'], 'baud': basic_config['RTU']['baud'], 'data_bit': basic_config['RTU']['data_bit'], 'stop_bit': basic_config['RTU']['stop_bit'], 'parity': basic_config['RTU']['parity'] } if group_infos: pga = paginate(group_infos[id]['tags'], page, pages) return { "paginate": pga, 'group_infos': group_infos, 'basic_config': config } return {"paginate": [], 'group_infos': []} pages = int(request.args.get('pages', 10)) page = int(request.args.get('page', 1)) cfg_msg = read_json() basic_config, data, group_infos = read_modbus_config(cfg_msg) pga = paginate(group_infos, page, pages) config = { 'dev_id': basic_config['dev_id'], 'Coll_Type': basic_config['Coll_Type'], 'host': basic_config['TCP']['host'], 'port': basic_config['TCP']['port'], 'serial': basic_config['RTU']['serial'], 'baud': basic_config['RTU']['baud'], 'data_bit': basic_config['RTU']['data_bit'], 'stop_bit': basic_config['RTU']['stop_bit'], 'parity': basic_config['RTU']['parity'] } print(pga['total'], pga['pages']) return render_template('modbus/modbus_show.html', paginate=pga, group_infos=group_infos, basic_config=config, modbus='bg-info')
def index(self, user, data): """ Index HTTP method. Should be called from GET when no key is provided. Processes cursor and num_page URL arguments for pagination support. :param user: (object) caller :param data: (dictionary) :return: results for query """ query = self.model.query() need = Need('index') result = self.model.can(user, need, query=query) if not result: raise need.exception() query = filter_query(result, data, self.model) created_prop = getattr(self.model, 'created', None) if not query.orders and created_prop: logging.info('Adding default ordering by creation time.') query = query.order(-created_prop, self.model.key) page = int(request.args.get('page', 1)) # default page length is 100 num_page = int(request.args.get('num_page', 100)) query_results = paginate(query, page, num_page) add_statistics = request.args.get('stats', False) if add_statistics: query_results['statistics'] = self.statistics() return query_results
def tag(tag): page = request.args.get( 'page', 1, type=int) # URL Argument page wird geholt, default zu 1 posts = [] posts_with_tag = PostToTag.query.filter_by( name=tag).all() # Es werden alle PostToTag Objekte aus der DB geholt if not posts_with_tag: flash('Tag does not exist.') # Falls der tag nicht existiert return redirect( url_for('index') ) # Wird ein Fehler angezeigt und auf den Index weitergeleitet for post in posts_with_tag: # Anhand der PostToTag Objekte werden nun Post Objekte anhand der PostID aus der DB geladen post = Post.query.get(int(post.post_id)) posts.append(post) posts = add_author( posts) # Diesen Posts wird nun ein Autor Objekt gematcht posts = paginate(posts, page, 5) # und sie werde in 5er Listen "paginated" next_url = f'/tag/{tag}/?page={posts.next_num()}' if posts.has_next( ) else None prev_url = f'/tag/{tag}/?page={posts.next_num()}' if posts.has_prev( ) else None return render_template('list_posts.html', title=f'{tag} - Tag', posts=posts.items, var=tag, type='Posts with Tag', next_url=next_url, prev_url=prev_url)
def index(self): """ Index HTTP method. Should be called from GET when no key is provided. Processes cursor and num_page URL arguments for pagination support. """ query = self.model.query() need = Need('index') result = self.model.can(session['user'], need, query=query) if not result: return need.api_response() args = self.parse_args(True) query = filter_query(result, args, self.model) created_prop = getattr(self.model, 'created', None) if not query.orders and created_prop: logging.info("Adding default ordering by creation time.") query = query.order(-created_prop) page = int(request.args.get('page', 1)) num_page = request.args.get('num_page', None) query_results = paginate(query, page, num_page) add_statistics = request.args.get('stats', False) if add_statistics: query_results['statistics'] = self.statistics() return create_api_response(200, "success", query_results)
def profile(username): page = request.args.get( 'page', 1, type=int) # URL Argument page wird geholt, default zu 1 if not username: user = current_user else: user = User.query.filter_by(name=username).first( ) # das passende User Objekt zur URL wird aus der DB geladen if not user: flash( 'User does not exist.' ) # Falls der User nicht mit diesem Namen existiert wird eine Fehlernachricht angezeigt return redirect(url_for('index')) # Und auf den Index weitergeleitet posts = add_author( user.posts ) # Alle Posts des Users werden aus der DB geholt, ihnen wird je ein Autor-Objekt gematcht posts = paginate(posts, page, 5) # und in 5er Listen "paginated" next_url = f'/user/{username}/?page={posts.next_num()}' if posts.has_next( ) else None prev_url = f'/user/{username}/?page={posts.prev_num()}' if posts.has_prev( ) else None return render_template('list_posts.html', title=f'{user.name} - Profile', posts=posts.items, var=user.name, type='Profile', next_url=next_url, prev_url=prev_url)
def all_actors(payload): actors_count = Actor.query.count() actors = paginate(flask.request, Actor.query.all(), ITEMS_PER_PAGE) if not actors: flask.abort(404) return flask.jsonify({ "success": True, "actors": [a.format() for a in actors], "total_actors_count": actors_count, })
def all_movies(payload): movies_count = Movie.query.count() movies = paginate(flask.request, Movie.query.all(), ITEMS_PER_PAGE) if not movies: flask.abort(404) return flask.jsonify({ "success": True, "movies": [m.format() for m in movies], "total_movies_count": movies_count, })
def services(): page = request.args.get('page', 1, int) if current_user.rank().level < 2: services = paginate_service_owner_id(current_user.id, page=page, per_page=25) else: services = paginate(Service.query, page=page, per_page=25) return render_template('admin/pages/services/services.html', services=services, amount=amount)
def accounts(): if not current_user.is_staff() or not current_user.is_authenticated: return redirect(url_for('index.index')) page = request.args.get('page', 1, type=int) accounts = paginate(Account.query, page=page, per_page=25) return render_template('admin/pages/accounts/accounts.html', accounts=accounts, find=find_account, amount=amount, ranks=ranks, form=AccountForm())
def list_service(): page = request.args.get('page', 1, int) if current_user.rank().level < 2: services = paginate_service_owner_id(current_user.id, page=page, per_page=25) else: services = paginate(Service.query, page=page, per_page=25) return render_template('splash/actions/services/list.html', services=services, amount=amount, current_page=page)
def log(): logs_list = [] if request.method == 'POST': logs_list = [] log_level = request.form.get('log_level', 'ALL') log_day = request.form.get('log_day', time.strftime('%Y-%m-%d')) log_day_start = log_day+' ' + \ request.form.get('log_day_start', '00:00:00') log_day_end = log_day + ' ' + request.form.get("log_day_end", "23:59:59") pages = int(request.form.get('pages', 10)) page = int(request.form.get('page', 1)) key = request.form.get('key') log_name = log_path + '\\' + '{}.log'.format(log_day) if not all((log_day, log_day_start, log_day_end)): return {'paginate': {}, 'msg': f'请输入查询日期和时间'} try: with open(log_name, 'r', encoding='utf-8') as lg: logs = lg.read().splitlines() except Exception as e: return {'paginate': {}, 'msg': f'OOOPS..[{log_day}]没有日志,被外星人偷走了??'} logs_list = check_day_log(log_day_start, log_day_end, logs, log_level, key) if logs_list: pga = paginate(logs_list, page, pages) return {"paginate": {}, 'msg': f'查询到{pga.total}条日志'} else: return {'paginate': {}, 'msg': f'查询到0条日志'} else: pages = int(request.args.get('pages', 5)) page = int(request.args.get('page', 1)) with open(log_path + '\\' + '{}.log'.format(time.strftime('%Y-%m-%d')), 'r', encoding='utf-8') as lg: logs = lg.read().splitlines() for l in logs: logs_list.append(l.rsplit(' ')) pga = paginate(logs_list, page, pages) return render_template('log/log.html', paginate=pga, log='bg-info')
def pagination2(page): users = paginate(db.session.query(User).order_by(User.LOGIN.desc()), page, per_page=1) for user in users.items: print(u"user = {}".format(user.NAME)) print(u"has_prev = {}, prev_num = {}".format(users.has_prev, users.prev_num)) print( u"has_next = {}, next_num = {}, page/pages = {}/{}, total = {}".format( users.has_next, users.next_num, users.page, users.pages, users.total)) return render_template("/auth/index.html", endpoint="flask_login.pagination2", pages=users)
def index(): page = request.args.get( 'page', 1, type=int) # URL Argument page wird geholt, default zu 1 posts = add_author( Post.query.all() ) # Alle Posts werden aus der DB geholt, ihnen wird je ein Autor-Objekt gematcht posts = paginate(posts, page, 5) # und in 5er Listen "paginated" next_url = url_for('index', page=posts.next_num()) if posts.has_next() else None prev_url = url_for('index', page=posts.prev_num()) if posts.has_prev() else None return render_template('list_posts.html', posts=posts.items, title='DHBW Microblog', var=None, type=None, next_url=next_url, prev_url=prev_url)
def m_tag_search(): """ 查找 """ key = request.args.get('key') # 标签名 slave_id = int(request.args.get('slave_id', 1)) fun_code = int(request.args.get('fun_code', 3)) pages = int(request.args.get('pages', 10)) page = int(request.args.get('page', 1)) cfg_msg = read_json() search_tag_list = [] basic_config, data, group_infos = read_modbus_config(cfg_msg) for gis in group_infos: if gis['slave_id'] == slave_id and gis['fun_code'] == fun_code: tags = gis['tags'] search_tag_list = search_modbus_tag(key, tags, []) pga = paginate(search_tag_list, page, pages) current_app.logger.debug(f'查询位号:%s' % (key)) return {"paginate": pga, 'group_infos': group_infos}