def api_comments(*, page='1'): page_index = get_page_index(page) num = yield from Comment.find_number('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 get_blog(id, request): blog = yield from Blog.find(id) comments = yield from Comment.find_all('blog_id=?', [id], orderBy='created_at desc') for c in comments: c.html_content = text2html(c.content) blog.html_content = markdown2.markdown(blog.content) return { '__template__': 'blog.html', 'blog': blog, '__user__': request.__user__, 'comments': comments }