Example #1
0
def index():

    # 实现分页 1, 2, 3, 4 。。。
    page = request.args.get("page", 1)

    offset = POSTS_PER_PAGE*(int(page)-1)
    postList = PostService.get_posts_page(offset, POSTS_PER_PAGE)
    pager = generate_page(PostService.get_posts_count(), POSTS_PER_PAGE, int(page))

    # 超出页面,
    if int(page)>pager['sumPage'] and pager['sumPage']!=0:
        abort(404)

    comCount = [CommentService.get_comments_count(post['id']) for post in postList]

    postsZip = zip(postList, comCount)

    posts_recent = PostService.get_posts_recent(4, 'desc')

    return render_template('web/index.html', posts=postsZip, pager=pager, postR = posts_recent)
Example #2
0
def show_posts(page = 1):

    #posts = PostService.get_posts()
    #posts, nav = PostService.get_posts_paginate(page, POSTS_PER_PAGE, False)

    #return  render_template('admin/posts.html', posts = posts, nav=nav, username=session['admin_uid'])

        # 实现分页 1, 2, 3, 4 。。。
    page = request.args.get("page", 1)

    offset = POSTS_PER_PAGE*(int(page)-1)
    postList = PostService.get_posts_page(offset, POSTS_PER_PAGE_BACK)
    pager = generate_page(PostService.get_posts_count(), POSTS_PER_PAGE_BACK, int(page))


    # 超出页面,
    if int(page)>pager['sumPage'] and pager['sumPage']!=0:
        abort(404)

    #comCount = [CommentService.get_comments_count(post['id']) for post in postList]
    return render_template('admin/posts.html', posts=postList, pager=pager)