예제 #1
0
def new_comment(article_id):
    post_data = flask.request.form
    comment = Comment(name=post_data['name'], text=post_data['text'])
    if post_data['location'] is not None:
        comment.location = post_data['location']
    article = Article.query.get(article_id)
    article.comments.append(comment)
    article.content = post_data['content']
    db.session.commit()
    return flask.jsonify(
        content=article.content,
        comments=[c.serialize for c in article.comments.all()])
예제 #2
0
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