async def api_create_comment(id, request, *, content, time): user = request.__user__ check_user(user, check_admin=False) check_string(content=content) blog = await Blog.find(id) if blog is None: raise APIResourceNotFoundError('Blog') comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.lstrip('\n').rstrip()) await comment.save() comments = await Comment.findAll('blog_id = ? and created_at > ?', [id, time], orderBy='created_at desc') for c in comments: c.content = markdown_highlight(c.content) return dict(comments=comments)
async def api_get_blog_comments(id): comments = await Comment.findAll('blog_id = ?', [id], orderBy='created_at desc') for c in comments: c.content = markdown_highlight(c.content) return dict(comments=comments)
def to_json(self, **kw): json_comment = self.copy() if kw.get('marked'): json_comment['content'] = markdown_highlight(self.content) return json_comment