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_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_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)
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) }