def api_create_comment(id, request, *, content): blog=yield from Blog.findAll(id) print(blog) print(content) comment=Comment(blog_id=id,user_id='0015302547958723f7da9d783434468901251428ea85d4c000',user_name='xuehh',user_image='http://www.gravatar.com/avatar/067bf298c6244dd085d9b4b7d9f3e0ba?d=mm&s=120',content=content.strip()) yield from comment.save() return comment
def api_create_comment(id, request, *, content): user = request.__user__ if user is None: raise APIPermissionError('Please signin first.') if not content or not content.strip(): raise APIValueError('content') blog = yield from 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.strip()) yield from comment.save() return comment
def api_create_comment(id, request, *, content): user = request.__user__ if user is None: raise APIPermissionError('Please signin first.') if not content or not content.strip(): raise APIValueError('content') blog = yield from 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.strip()) yield from comment.save() return comment
def apiCreateComment(id, request, *, content): user = request.__user__ if user is None: raise APIPermissionError('请先登录') if not content or not content.strip(): raise APIValueError('内容为空') blog = yield from Blog.find(id) if blog is None: raise APIResourceNotFoundError('文章不存在') comment = Comment(blogId=blog.id, userId=user.id, userName=user.name, userImage=user.image, content=content.strip()) yield from Comment.save(comment) return content
def api_create_comment(id, request, *, content): #获取请求中的用户信息: user = request.__user__ #用户信息为None则抛出异常: if user is None: raise APIPermissionError('Please signin first.') #参数中内容信息为空,抛出异常: if not content or not content.strip(): raise APIValueError('content') #数据库Blog表中查询指定文章信息: blog = yield from Blog.find(id) #查询无结果则抛出异常: if blog is None: raise APIResourceNotFoundError('Blog') #创建comment实例: comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip()) #将Comment信息存储到数据库: yield from comment.save() return comment