From f655943898a937a0c9d6406751202b3bfc6c3a12 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 23 Sep 2020 22:10:24 -0700 Subject: [PATCH] add deletes --- suchwow/routes/post.py | 18 ++++++++++++++++++ suchwow/templates/post/read.html | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/suchwow/routes/post.py b/suchwow/routes/post.py index 1c62af6..4c764e3 100644 --- a/suchwow/routes/post.py +++ b/suchwow/routes/post.py @@ -92,6 +92,24 @@ def create(): return redirect(url_for("post.read", id=post.id)) return render_template("post/create.html") +@bp.route("/post//delete") +@login_required +def delete(id): + filtered = Post.filter(id=id) + user = session["auth"]["preferred_username"] + if filtered: + post = filtered.first() + if user == post.submitter: + post.delete_instance() + flash("Deleted that shit, brah!") + return redirect(url_for("index")) + else: + flash("You can't delete a meme you don't own, brah") + return redirect(url_for("post.read", id=post.id)) + else: + flash("No meme there, brah") + return redirect(url_for("index")) + @bp.route("/uploads/") def uploaded_file(filename): file_path = path.join(current_app.config["DATA_FOLDER"], "uploads") diff --git a/suchwow/templates/post/read.html b/suchwow/templates/post/read.html index 5e31542..70c4f32 100644 --- a/suchwow/templates/post/read.html +++ b/suchwow/templates/post/read.html @@ -58,6 +58,12 @@ + + + {% if session.auth.preferred_username == post.submitter %} +
+ {% endif %} +