예제 #1
0
def add_comment(post_id):
    from models import Comment
    from forms import CommentForm
    comment = CommentForm(request.form)
    #
    # if not Post.query.get(post_id):  # КАК СДЕЛАТЬ ВАЛИДАТОР ПО ЛЮДСКИ??
    #     flash('No such Post! Nothing to comment')
    #     return render_template('flash_page.html'), 403

    if comment.validate():
        comment = Comment(**comment.data)
        comment.post_id = post_id
        db.session.add(comment)
        db.session.commit()
        flash('A very good Comment was added for Post number {}'.format(comment.post_id))
        return render_template('flash_page.html'), 200
    else:
        flash('Something wrong! {}'.format(str(comment.errors)))
        return render_template('flash_page.html'), 403