def update_post(id): body = request.form["body"] title = request.form["title"] title_pic = request.form["title_pic"] published = bool(int(request.form["published"])) post = Post.at(id).getone() published_old = bool(int(post.published)) if not post.published: # only non-published posts update this field post.published = published post.body = body post.title = title post.title_pic = title_pic rows_affected = post.save() if rows_affected >= 0: if not published_old and published: # published flashx.success("Published successfully") return redirect(url_for("post", id=post.id)) else: flashx.success("Saved successfully") if post.published: return redirect(url_for("post", id=post.id)) else: flashx.error("Something wrong when updating post") return redirect(url_for("edit", id=post.id))
def edit(id): post = Post.findone(id=id) if post is None: flashx.error("Request post not found") abort(404) return render_template("edit.html", post=post, active_tab="eidt")
def delete(id): query = Post.at(id).delete() rows_affected = query.execute() if rows_affected <= 0: flashx.error("Something wrong when deleting post") return redirect(url_for("edit", id=id)) else: flashx.success("Delete post successfully") return redirect(url_for("write"))