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)
Esempio n. 2
0
async def api_blogs(*, page='1'):
    page_index = get_page_index(page)
    num = await Blog.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, blogs=())
    blogs = await Blog.findAll(orderBy='create_at desc',
                               limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
Esempio n. 3
0
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='create_at desc',
                               limit=(p.offset, p.limit))
    return dict(page=p, users=users)
Esempio n. 4
0
async def index(*, request, page='1'):
    logging.info('<handler get> index(%s)' % str(request))
    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='create_at desc',
                                   limit=(page.offset, page.limit))
    return {
        '__template__': 'blogs.html',
        'page': page,
        'blogs': blogs
    }
Esempio n. 5
0
async def index(*, page='1', category='1'):
    # summary = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
    # blogs = [
    #     Blog(id='1', name='Test Blog', summary=summary, created_at=time.time()-120),
    #     Blog(id='2', name='Something New', summary=summary, created_at=time.time()-3600),
    #     Blog(id='3', name='Learn Swift', summary=summary, created_at=time.time()-7200)
    # ]
    # return {
    #     '__template__': 'blogs.html',
    #     'blogs': blogs
    # }
    page_index = get_page_index(page)
    num = await Blog.findNumber('count(id)', 'category_id=' + category)
    page = Page(num, page_index)

    if num == 0:
        blogs = []
    else:
        blogs = await Blog.findAll('category_id=' + category,
                                   None,
                                   orderBy='created_at desc',
                                   limit=(page.offset, page.limit))
    return {'__template__': 'blogs.html', 'page': page, 'blogs': blogs}
Esempio n. 6
0
def manage_users(*, page='1'):
    return {
        '__template__': 'manage_users.html',
        'page_index': get_page_index(page)
    }