Beispiel #1
0
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)
Beispiel #2
0
def index(*, page='1'):
    page_index = get_page_index(page)
    num = yield from Blog.findNumber('count(id)')
    page = Page(num, page_index)
    if num == 0:
        blogs = []
    else:
        blogs = yield from Blog.findAll(orderBy='created_at desc',
                                        limit=(page.offset, page.limit))
    #     blogs = [
    #     Blog(id='1', name='Test Blog', summary='<h1>Index</h1>', created_at=time.time()-120),
    #     Blog(id='2', name='Something New', summary='<h1>Index</h1>', created_at=time.time()-3600),
    #     Blog(id='3', name='Learn Swift', summary='<h1>Index</h1>', created_at=time.time()-7200)
    # ]
    return {'__template__': 'blogs.html', 'page': page, 'blogs': blogs}