def showMain2(): dataset = request.args.get('dataset') method = request.args.get('method') # method filter if method == None: methods_compare_list = sorted( [x for x in os.listdir('static/' + dataset) if 'DS_' not in x]) else: methods_compare_list = method.split(',') # all the datasets datasets = sorted([ x for x in os.listdir('static') if x != 'assets' and os.path.isdir(os.path.join('static', x)) ]) # all the mtehods methods = sorted([ x for x in os.listdir('static/' + dataset) if os.path.isdir(os.path.join('static/' + dataset, x)) ]) # get the input image list images = sorted([ x for x in os.listdir('static/' + dataset + '/input') if '.png' in x or '.jpg' in x ]) # get all the images from current setting. pagex = Pagination(request.args.get("page", 1), len(images), request.path, request.args, per_page_count=1) index_list = images[pagex.start:pagex.end] html = pagex.page_html() return render_template('method.html', images=index_list, filter_methods=methods_compare_list, html=html, datasets=datasets, methods=methods, dataset=dataset)
def list(): pagination = Pagination(request) filter_form = ReportFilterForm(request.args) if filter_form.validate(): if request_wants_json(): r = get_reports(filter_form, pagination) else: list_table_rows, report_count = \ reports_list_table_rows_cache(filter_form, pagination) return render_template("reports/list.html", list_table_rows=list_table_rows, report_count=report_count, filter_form=filter_form, pagination=pagination) else: r = [] if request_wants_json(): return jsonify(dict(reports=r)) return render_template("reports/list.html", reports=r, report_count=len(r), filter_form=filter_form, pagination=pagination)
def list(): pagination = Pagination(request) filter_form = ProblemFilterForm(request.args) if filter_form.validate(): if request_wants_json(): p = get_problems(filter_form, pagination) else: list_table_rows, problem_count = \ problems_list_table_rows_cache(filter_form, pagination) return render_template("problems/list.html", list_table_rows=list_table_rows, problem_count=problem_count, filter_form=filter_form, pagination=pagination) else: p = [] if request_wants_json(): return jsonify(dict(problems=p)) return render_template("problems/list.html", problems=p, problem_count=len(p), filter_form=filter_form, pagination=pagination)
def index(page=1): p = Pagination(per_page=4, current_page=page) timeline = MemeTimeline.find_paginated(p) return flask.render_template('index.html', timeline=timeline, pagination=p, isForm=False)
def getEntry(self, slug): if slug: entry = web.ctx.orm.query(Entry).filter_by(slug=slug).first() i = web.input(page=1) commentCount = web.ctx.orm.query(Comment).filter_by( entry_id=entry.id).count() p = Pagination(int(commentCount), 5, int(i.page)) entry.comments = web.ctx.orm.query(Comment).filter_by( entry_id=entry.id)[p.start:p.limit] return (entry, p)
def GET(self): i = web.input(page=1) try: page = int(i.page) except: page = 1 entryCount = web.ctx.orm.query(Entry).count() p = Pagination(entryCount, pageCount, page) entries = web.ctx.orm.query(Entry).order_by( 'entries.created_time DESC')[int(p.start):int(p.start + p.limit)] d['p'] = p d['entries'] = entries return render.entry_list(**d)
def GET(self): page = web.input(page=1) try: page = int(page.page) except: page = 1 linkCount = web.ctx.orm.query(Link).count() p = Pagination(linkCount, pageCount, page) links = web.ctx.orm.query(Link).order_by( 'links.name ASC')[int(p.start):int(p.start + p.limit)] d['p'] = p d['links'] = links return render.link_list(**d)
def GET(self, slug): i = web.input(page=1) try: page = int(i.page) except: page = 1 tag = web.ctx.orm.query(Tag).filter_by(name=slug).first() p = Pagination(len(tag.entries), 20, page) entries = tag.entries[::-1][p.start:p.limit] d['tag'] = tag d['p'] = p d['entries'] = entries d['usedTime'] = time.time() - d['startTime'] return render.tag(**d)
def get(self, page): user = self.current_user messages = [] cursor = self.db.message.find().sort([{"timestamp": 1}]) for document in (yield cursor.to_list(length=100)): messages.append(document) all_count = len(messages) # 计算新闻总数 obj = Pagination.Pagination(page, all_count) # 实例化pagination对象 result = messages[obj.start:obj.start + 5] # 从每页开始向下取10条,即每页显示10条新闻 str_page = obj.string_pager('/index/') #获取页码的字符串格式html # self.render('home/index.html', str_page=str_page, news_list=result) # self.render("index.html", messages=ChatSocketHandler.cache, clients=ChatSocketHandler.waiters, username= "******" % ChatSocketHandler.client_id) self.render("index.html", user=user, str_page=str_page, news_list=result)
def GET(self): # 读取当前页的文章 i = web.input(page=1) ids = [int(one.id) for one in web.ctx.orm.query(Entry.id).all()] if len(ids) < 5: randomEntries = web.ctx.orm.query(Entry).all() else: randomEntries = web.ctx.orm.query(Entry).filter( Entry.id.in_(random.sample(ids, 5))) entryCount = web.ctx.orm.query(Entry).count() p = Pagination(entryCount, 5, int(i.page)) d['entries'] = web.ctx.orm.query(Entry).order_by( 'entries.created_time DESC')[p.start:p.start + p.limit] d['p'] = p d['usedTime'] = time.time() - d['startTime'] d['randomEntries'] = randomEntries return render.index(**d)
def index(): keyword = request.args.get('keyword', None) page = int(request.args.get('page', 1)) PER_PAGE = 8 if not keyword: movies = Movie.query.all() else: movies = Movie.query.filter(Movie.title.like('%' + keyword + '%')).all() pagination = Pagination(page, PER_PAGE, len(movies)) tmp = (page - 1) * PER_PAGE movies = movies[tmp:tmp + PER_PAGE] if current_user.is_authenticated: for movie in movies: movie.can_watche = False consume_records = ConsumeRecord.query.filter_by( consumer=current_user).all() bought_moveis = [record.movie for record in consume_records] print(bought_moveis) for movie in movies: if movie in bought_moveis: movie.can_watched = True current_path = request.url.split('page')[0] if current_path.endswith('/'): current_path += '?' return render_template('index.html', user=current_user, movies=movies, keyword=keyword, current_path=current_path, current_page=page, pagination=pagination)
def get(self, page): user = self.current_user _user = yield self.db.user.find_one({'email': self.current_user}) friends = [] for friend in _user['friends']: cur = yield self.db.user.find_one({'_id': friend}) friends.append({ 'username': cur['username'], 'email': cur['email'] }) all_count = len(friends) # 计算新闻总数 obj = Pagination.Pagination(page, all_count) # 实例化pagination对象 result = friends[obj.start:obj.start + 5] # 从每页开始向下取10条,即每页显示10条新闻 str_page = obj.string_pager('/friends/') # 获取页码的字符串格式html # self.render('home/index.html', str_page=str_page, news_list=result) # self.render("index.html", messages=ChatSocketHandler.cache, clients=ChatSocketHandler.waiters, username= "******" % ChatSocketHandler.client_id) self.render("users_list.html", user=user, str_page=str_page, news_list=result, error=u'')
def custom_records(): page = int(request.args.get('page', 1)) PER_PAGE = 3 consume_records = ConsumeRecord.query.filter_by( consumer=current_user).all() pagination = Pagination(page, PER_PAGE, len(consume_records)) tmp = (page - 1) * PER_PAGE consume_records = consume_records[tmp:tmp + PER_PAGE] current_path = request.url.split('page')[0] + '?' return render_template( 'consume_history.html', user=current_user, consume_records=consume_records, pagination=pagination, current_page=page, current_path=current_path, )