Esempio n. 1
0
def api_blogs(*, page='1'):
    page_index = get_page_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)
Esempio n. 2
0
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
    }
Esempio n. 3
0
def index(*, page='1'):
    # summary = 'it is a test!\n这里可以添加文字'
    # blogs = [
    #     Blog(id='1', name='test blog', summary=summary, created_at=time.time()-120),
    #     Blog(id='2', name='测试标题!!', summary=summary, created_at=time.time()-120),
    #     Blog(id='3', name='nice', summary=summary, created_at=time.time()-120),
    #     Blog(id='4', name='哈哈哈哈哈哈哈', summary=summary, created_at=time.time()-120),
    # ]
    # users = yield from User.find_all()
    page_index = get_page_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))
    return {
        '__template__': 'blogs.html',
        'page': page,
        'blogs': blogs
    }
Esempio n. 4
0
def api_delete_blog(request, *, id):
    check_admin(request)
    blog = yield from Blog.find_num(id)
    yield from blog.remove()
    return dict(id=id)