def api_comments(*, page='1'): page_index = Page.get_index(page) num = yield from Comment.find_num('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, comments=()) comments = yield from Comment.find_all(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, comments=comments)
def api_blogs(*, page='1'): page_index = Page.get_index(page) num = yield from Blog.find_num('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, blogs=()) blogs = yield from Blog.find_all(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, blogs=blogs)
def api_get_users(*, page='1'): page_index = Page.get_index(page) num = yield from User.find_num('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, users=()) users = yield from User.find_all(orderBy='created_at desc', limit=(p.offset, p.limit)) for u in users: u.passwd = '******' return dict(page=p, users=users)
async def index(*, page='1'): page_index = get_page_index(page) num = await Blog.findNumber('count(id)') p = Page(num, page_index) # 如果什么都没找到,那blogs内容就是空的,否则,显示所有blogs if num == 0: blogs = [] else: blogs = await Blog.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return {'__template__': 'blogs.html', 'page': p, 'blogs': blogs}
def api_get_users(*, page='1'): page_index = get_page_index(page) num = yield from User.findNumber('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, users=()) users = yield from User.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) for u in users: u.passwd = '******' return dict(page=p, users=users)
def api_comments_anonymous(request, *, page='1'): '''get all comments.''' check_admin(request) page_index = get_page_index(page) num = yield from CommentAnonymous.find_number('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, comments=()) comments = yield from CommentAnonymous.find_all(order_by='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, comments=comments)
async def api_get_users(*, page="1"): page_index = get_page_index(page) num = await User.findNumber("count(id)") p = Page(num, page_index) if num == 0: return dict(page=p, users=()) users = await User.findAll(orderBy="created_at desc", limit=(p.offset, p.limit)) for u in users: u.passwd = "******" return dict(page=p, users=users)
def index(*, page='1'): page_index = get_page_index(page) num = yield from Blog.findNumber('count(id)') page = Page(num) if num == 0: blogs = [] else: blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(page.offset, page.limit)) return { '__template__': 'index.html', }
async def index(request, *, page='1'): if not check_admin(request): return Response.NO_AUTH() logging.info('this request is %s', request.__user__.name) page_index = get_page_index(page) num = await Blog.findNumber('count(id)') page = Page(num) if num == 0: blogs = [] else: blogs = await Blog.findAll(orderBy='created_at desc', limit=(page.offset, page.limit)) return Response.success(blogs)
def api_get_users(): ''' 获取用户API ''' total = User.count_all() page = Page(total, _get_page_index()) users = User.find_by('order by created_at desc limit ?,?', page.offset, page.limit) for u in users: u.password = '******' return dict(users=users, page=page)
async def api_get_users(*, page="1"): page_index = get_page_index(page) num = await User.findCount('id') p = Page(num, page_index) if num == 0: return dict(page=p, users=()) users = await User.findAll(orderby='create_time desc', limit=(p.offset, p.limit)) for u in users: u.passwd = '******' return dict(page=p, users=users)
async def index(*, page='1'): # 传入page表示要获取第几页的blog信息 page_index = get_page_index(page) num = await Blog.findNumber('count(id)') # 计算出一共有多少博客 p = Page(num, page_index) # 创建分页对象,不传入page_size则默认page_size=6,即一页显示6条记录 if num == 0: blogs = [] else: # 筛选出blogs表中对应位置的记录,并按找注册时间(最新的在前)排序 blogs = await Blog.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return {'__template__': 'blogs.html', 'page': p, 'blogs': blogs}
def personal_get_study_plane_history(*, user_id, page='1'): page_index = get_page_index(page) num = yield from Study_plane.findNumber('count(*)', where="user_id='" + user_id + "' and plane_state!='ing'") p = Page(num, page_index, 10) planes = yield from Study_plane.findAll(where="user_id='" + user_id + "' and plane_state!='ing'", orderBy="created_at desc", limit=(p.offset, p.limit)) return dict(planes=planes, page=p)
def api_blogs(*, page='1'): page_index = get_page_index(page) num = yield from Blog.findNumber('count(id)') # num为博客总数 p = Page(num, page_index) # 创建page对象 if num == 0: return dict(page=p, blogs=()) # 博客书不为0就从数据库中抓取博客 # limit强制select返回指定的记录数 blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, blogs=blogs) # 返回dict,以供response的中间件处理
def personal_get_sub_video(*, parent_video_id, page='1'): page_index = get_page_index(page) num = yield from Sub_video.findNumber('count(*)', where="parent_video_id='" + parent_video_id + "'") p = Page(num, page_index, 10) sub_videos = yield from Sub_video.findAll(where="parent_video_id='" + parent_video_id + "'", orderBy="num", limit=(p.offset, p.limit)) return dict(sub_videos=sub_videos, page=p)
async def index(*, page='1'): page_index = get_page_index(page) print(page) num = await Blog.findNumber('count(id)') page = Page(item_count=num, page_index=page_index, page_size=4) if num == 0: blogs = [] else: blogs = await Blog.findAll(orderBy=' created_at desc', limit=(page.offset, page.limit)) return {'__template__': 'blogs.html', 'page': page, 'blogs': blogs}
async def index(*, page="1"): page_index = get_page_index(page) num = await Blog.findNumber("count(id)") if (not num) and num == 0: logger.info("the type of num is : %s" % type(num)) blogs = [] else: page = Page(num, page_index) blogs = await Blog.findAll(orderBy="created_at desc", limit=(page.offset, page.limit)) return {"__template__": "blogs.html", "page": page, "blogs": blogs}
def testing(paper_id, index='1'): index_index = get_page_index(index) num = Item.select().where(Item.paper == paper_id) if not num: error = '暂无题目' return render_template("error.html", error=error) p = Page(len(num), index_index, 1) items = Item.select().where((Item.paper == paper_id) & (Item.index == index)) item = items[0] return render_template("items.html", item=item, page=p)
async def api_comments(*, page='1'): page_index = get_page_index(page) num = await Comment.findNumber('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, comments=()) comments = await Comment.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) logging.info('api comments p: %s, has previous: %s, has_next: %s' % (str(p), p.has_previous, p.has_next)) return dict(page=p, comments=comments)
async def api_blogs(*, page='1'): page_index = get_page_index(page) num = await Blog.findNumber('count(id)') # 获取博客总数 p = Page(num, page_index) # 创建Page对象(Page对象在apis.py中定义) if num == 0: return dict(page=p, blogs=()) # 博客总数不为0,则从数据库中抓取博客 # limit使select语句返回指定的记录数,前一个参数为偏移量,后一个参数为每页的记录数目 blogs = await Blog.findAll(orderby='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, blogs=blogs) # 返回字典,以供response中间件处理
def api_blogs(*, page="1"): page_index = get_page_index(page) num = yield from Blog.findNumber("count(id)") p = Page(num, page_index) if num == 0: return dict(page=p, blogs=()) blogs = yield from Blog.findall(orderBy="created_at desc", limit=(p.offset, p.limit)) return dict(page=p, blogs=blogs)
def api_blogs(*, page='1'): page_index = get_page_index(page) num = yield from Blog.findNumber('count(id)') # num为博客总数 p = Page(num, page_index) # 创建page对象 if num == 0: return dict(page=p, blogs=()) # 若博客数为0,返回字典,将被app.py的response中间件再处理 # 博客总数不为0,则从数据库中抓取博客 # limit强制select语句返回指定的记录数,前一个参数为偏移量,后一个参数为记录的最大数目 blogs = yield from Blog.findAll(orderBy="created_at desc", limit=(p.offset, p.limit)) return dict(page=p, blogs=blogs) # 返回字典,以供response中间件处理
def api_comments(*, page="1"): page_index = get_page_index(page) num = yield from Comment.findNumber('count(id)') # num为评论总数 p = Page(num, page_index) # 创建page对象, 保存页面信息 if num == 0: return dict(page=p, comments=()) # 若评论数0,返回字典,将被app.py的response中间件再处理 # 博客总数不为0,则从数据库中抓取博客 # limit强制select语句返回指定的记录数,前一个参数为偏移量,后一个参数为记录的最大数目 comments = yield from Comment.findAll(orderBy="created_at desc", limit=(p.offset, p.limit)) return dict(page=p, comments=comments) # 返回字典,以供response中间件处理
async def api_landscape(*, page='1'): page_index = get_page_index(page) num = await Blog.findNumber('count(id)', where='tag', regexp="'landscape'") p = Page(num, page_index) if num == 0: return dict(page=p, blogs=()) blogs = await Blog.findAll(where='tag', regexp="'landscape'", orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, blogs=blogs)
def api_get_users(*, page="1"): page_index = get_page_index(page) num = yield from User.findNumber("count(id)") p = Page(num, page_index) if num == 0: return dict(page=p, users=()) users = yield from User.findAll(orderBy="created_at desc") for u in users: u.passwd = "*****" # 以dict形式返回,并且未指定__template__,将被app.py的response factory处理为json return dict(page=p, users=users)
async def blogs(*, page='1'): '''Blog首页''' page_index = get_page_index(page) num = await Blog.findNumber('count(id)') page = Page(num) if num == 0: blogs = [] else: blogs = await Blog.findAll(orderBy='created_at desc', limit=(page.offset, page.limit)) return {'__template__': 'blogs.html', 'page': page, 'blogs': blogs}
def api_comments(*, page='1'): #获取页面索引,默认为1: page_index = get_page_index(page) #查询数据库中Comment表中评论总数: num = yield from Comment.findNumber('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, comments=()) comments = yield from Comment.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, comments=comments)
async def api_get_users(*, page='1'): page_index = get_page_index(page) num = await User.findNumber('count(id)') page = Page(num, page_index) if num == 0: return dict(page=page, users=()) users = await User.findAll(orderBy='created_at desc', limit=(page.offset, page.limit)) for user in users: user.password = '******' return dict(page=page, users=users)
def api_blogs(*, page='1'): page_index = get_page_index(page) num = yield from Blog.findNumber( 'count(id)' ) # Mysql函数: count(列名)---只包括列名指定列,返回指定列的记录数,这里返回的就是id这一列的行数,也就是blog的数量 p = Page(num, page_index) if num == 0: return dict(page=p, blogs=()) blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, blogs=blogs)
def api_blogs(*, page='1'): # page由html传入 page_index = get_page_index(page) num = yield from Blog.findNumber('count(id)') # num为博客总数 p = Page(num, page_index) # 创建Page对象(Page对象在apis.py中定义) if num == 0: return dict(page_obj=p, blogs=()) # 若博客数为0, 则手动创建页面对象和空的博客tuple # 博客总数不为0,则从数据库中抓取博客 # limit强制select语句返回指定的记录数,前一个参数为偏移量,后一个参数为该页显示的最大数目,limit由第offset+1开始显示 blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page_obj=p, blogs=blogs)
async def api_sorts(*, page='1'): page_index = get_page_index(page) num = await Sort.findNumber('count(id)') logging.info('num ::%s' % (num)) p = Page(num, page_index) if num == 0: return dict(page=p, sorts=()) sorts = await Sort.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) logging.info('sort sort ::%s' % (sorts)) return dict(page=p, sorts=sorts)
async def api_equipmentsOnLoan(request, *, page='1'): user = request.__user__ page_index = get_page_index(page) num = await Equipment.findNumber('count(id)', where='`user_id`!=\'\'') p = Page(num, page_index) if num == 0: return dict(user=user, page=p, equipments=()) equipments = await Equipment.findAll(where='`user_id`!=\'\'', orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(user=user, page=p, equipments=equipments)
async def api_comments(*, page='1'): page_index = get_page_index(page) num = await Comment.findNumber('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, comments=()) comments = await Comment.findAll( orderBy='created_at desc', limit=(p.offset, p.limit) ) return dict(page=p, comments=comments)
def index(*, page='1'): page_index = Page.get_index(page) num = yield from Blog.find_num('count(id)') page = Page(num, page_index) if num == 0: blogs = [] else: blogs = yield from Blog.find_all(orderBy='created_at desc', limit=(page.offset, page.limit)) for blog in blogs: # blog.summary = markdown_highlight(blog.summary) blog.html_content = markdown_highlight(blog.content) return { '__template__': 'bootstrap-blogs.html', 'page': page, 'blogs': blogs }
def manage_blogs(*, page='1'): return { '__template__': 'manage_blogs.html', 'page_index': Page.get_index(page) }