Update a post if the current user is the author.
(id)
| 86 | @bp.route("/<int:id>/update", methods=("GET", "POST")) |
| 87 | @login_required |
| 88 | def update(id): |
| 89 | """Update a post if the current user is the author.""" |
| 90 | post = get_post(id) |
| 91 | |
| 92 | if request.method == "POST": |
| 93 | title = request.form["title"] |
| 94 | body = request.form["body"] |
| 95 | error = None |
| 96 | |
| 97 | if not title: |
| 98 | error = "Title is required." |
| 99 | |
| 100 | if error is not None: |
| 101 | flash(error) |
| 102 | else: |
| 103 | db = get_db() |
| 104 | db.execute( |
| 105 | "UPDATE post SET title = ?, body = ? WHERE id = ?", (title, body, id) |
| 106 | ) |
| 107 | db.commit() |
| 108 | return redirect(url_for("blog.index")) |
| 109 | |
| 110 | return render_template("blog/update.html", post=post) |
| 111 | |
| 112 | |
| 113 | @bp.route("/<int:id>/delete", methods=("POST",)) |
nothing calls this directly
no test coverage detected
searching dependent graphs…