def edit_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) # check if the user has the right permissions to edit this post if not can_modify(post, current_user): flash(_("You are not allowed to delete this post."), "danger") return redirect(url_for("blog.index")) form = PostForm() if form.validate_on_submit(): # this will update the changed attributes form.populate_obj(post) post.save() flash(_("This post has been edited"), "success") return redirect(url_for("blog.view_post", post_id=post.id, slug=post.slug)) else: form.title.data = post.title form.content.data = post.content return render_template("blog/post_form.html", post=post, form=form, mode="edit")
def delete_bin(bin_id, slug=None): pastebin = Bin.query.filter_by(id=bin_id).first() if not pastebin: abort(404) if not can_modify(pastebin, current_user): flash(_("You are not allowed to delete this Paste-Bin."), "danger") return redirect(url_for("paste.index")) pastebin.delete() flash(_("This bin has been deleted"), "success") return redirect(url_for("paste.index"))
def delete_post(post_id, slug=None): post = Post.query.filter_by(id=post_id).first() if not post: abort(404) if not can_modify(post, current_user): flash(_("You are not allowed to delete this post."), "danger") return redirect(url_for("blog.index")) post.delete() flash(_("This post has been deleted", "success")) return redirect(url_for("blog.index"))
def delete_comment(comment_id): comment = Comment.query.filter_by(id=comment_id).first() if not comment: abort(404) if not can_modify(comment, current_user): flash(_("You are not allowed to delete this post"), "danger") return redirect(url_for("blog.view_post", post_id=comment.post.id, slug=comment.post.slug)) post = comment.post comment.delete() flash(_("Your comment has been edited."), "success") return redirect(url_for("blog.view_post", post_id=post.id, slug=post.slug))
def edit_comment(comment_id): comment = Comment.query.filter_by(id=comment_id).first() if not comment: abort(404) if not can_modify(comment, current_user): flash(_("You are not allowed to edit this comment"), "danger") return redirect(url_for("blog.view_post", post_id=comment.post.id, slug=comment.post.slug)) form = CommentForm() if form.validate_on_submit(): form.populate_obj(comment) comment.save() flash(_("Your comment has been edited."), "success") return redirect(url_for("blog.view_post", post_id=comment.post.id, slug=comment.post.slug)) else: form.content.data = comment.content return render_template("blog/comment_form.html", form=form, mode="edit")