Exemplo n.º 1
0
def edit_post(post_id):
    post = Post.query.get_or_404(post_id)
    form = PostForm(request.form, post, post_id=post_id)
    if request.method == "POST":
        if not post.owner(current_user):
            not_authorized()
        if form.validate():
            if form.delete.data:
                db.session.delete(post)
                db.session.commit()
                flash("Successfully deleted post")
                return redirect(url_for("members.index"))
            else:
                populate_titletext(form, post)
                db.session.commit()
                flash("Successfully edited post")
                return redirect(url_for("members.post", post_id=post_id))
    return render_template("members/edit_post.html", post=form)
Exemplo n.º 2
0
def edit_post(post_id):
    post = Post.query.get_or_404(post_id)
    form = PostForm(request.form, post, post_id=post_id)
    if request.method == "POST":
        if not post.owner(current_user):
            not_authorized()
        if form.validate():
            if form.delete.data:
                db.session.delete(post)
                db.session.commit()
                flash("Successfully deleted post")
                return redirect(url_for("members.index"))
            else:
                populate_titletext(form, post)
                db.session.commit()
                flash("Successfully edited post")
                return redirect(url_for("members.post", post_id=post_id))
    return render_template("members/edit_post.html", post=form)
Exemplo n.º 3
0
def edit_comment(comment_id):
    comment = Comment.query.get_or_404(comment_id)
    form = CommentForm(request.form)
    post = Post.query.get(comment.post_id)
    if current_user.is_authenticated():
        del form.recaptcha
    if request.method == "POST":
        if not (current_user.is_authenticated() and comment.owner(current_user)):
            return login_manager.unauthorized()
        if form.validate():
            populate_titletext(form, comment)
            db.session.commit()
            flash("Successfully edited comment")
            return redirect(url_for("public.post", post_id = comment.post_id))
        elif form.method.data == "DELETE":
            db.session.delete(comment)
            db.session.commit()
            flash("Successfully deleted comment")
            return redirect(url_for("public.post", post_id=post.id))
        return render_template('edit_comment.html', comment = form)
    return render_template("show_comment.html", post=post, comment=comment)
Exemplo n.º 4
0
def edit_comment(comment_id):
    comment = Comment.query.get_or_404(comment_id)
    form = CommentForm(request.form)
    post = Post.query.get(comment.post_id)
    if current_user.is_authenticated():
        del form.recaptcha
    if request.method == "POST":
        if not (current_user.is_authenticated()
                and comment.owner(current_user)):
            return login_manager.unauthorized()
        if form.validate():
            populate_titletext(form, comment)
            db.session.commit()
            flash("Successfully edited comment")
            return redirect(url_for("public.post", post_id=comment.post_id))
        elif form.method.data == "DELETE":
            db.session.delete(comment)
            db.session.commit()
            flash("Successfully deleted comment")
            return redirect(url_for("public.post", post_id=post.id))
        return render_template('edit_comment.html', comment=form)
    return render_template("show_comment.html", post=post, comment=comment)