예제 #1
0
파일: blog.py 프로젝트: sh4nks/tardigrade
def view_post(post_id, slug=None):
    post = Post.query.filter_by(id=post_id).first()

    # abort if no post is found
    if not post:
        abort(404)

    # if you do not initialize the form, it will raise an error when user is
    # not registered
    form = None
    # check if the current user is authenticated
    if current_user.is_authenticated():
        # assign the `form` variable the `CommentForm` class
        form = CommentForm()

        # check if the form has any errors and is a `POST` request
        if form.validate_on_submit():
            # save the post
            form.save(current_user, post)
            flash(_("Your comment has been saved!"), "success")

            # and finally redirect to the post
            return redirect(url_for("blog.view_post", post_id=post.id,
                                    slug=post.slug))

    return render_template("blog/post.html", post=post, form=form)
예제 #2
0
파일: blog.py 프로젝트: sh4nks/tardigrade
def new_comment(post_id):
    post = Post.query.filter_by(id=post_id).first()

    if not post:
        abort(404)

    form = CommentForm()
    if form.validate_on_submit():
        form.save(current_user, post)
        flash(_("Your comment has been saved!"), "success")
        return redirect(url_for("blog.view_post", post_id=post.id,
                                slug=post.slug))

    return render_template("blog/comment_form.html", post=post, form=form,
                           mode="new")