def upvote_reply(name, title, reply_id): """ Route that handles upvoting a reply as the current user. """ reply = reply_service.get_reply(reply_id) if reply: reply_service.upvote_reply(reply_id, current_user.id) return redirect(request.referrer) else: abort(404)
def delete_reply(name, title, reply_id): """ Route that handles deleting a reply. """ reply = reply_service.get_reply(reply_id) if reply: if reply.user_id != current_user.id: return redirect(url_for("post.post", name=name, title=title)) reply_service.delete_reply(reply) flash("Successfully deleted reply.", "primary") return redirect(url_for("post.post", name=name, title=title)) else: abort(404)
def update_reply(name, title, reply_id): """ Route for updating a reply. On a GET request, it returns the reply update form. On a POST request, it handles updating a reply. """ reply = reply_service.get_reply(reply_id) if reply: if reply.user_id != current_user.id: return redirect(url_for("post.post", name=name, title=title)) form = ReplyForm() if form.validate_on_submit(): reply_service.update_reply(reply, form.reply.data) flash("Successfully updated reply.", "primary") return redirect(url_for("post.post", name=name, title=title)) form.reply.data = reply.reply return render_template("update_reply.jinja2", name=name, title=title, reply_id=reply_id, form=form) else: abort(404)