add deletes
This commit is contained in:
parent
783b482a0a
commit
f655943898
|
@ -92,6 +92,24 @@ def create():
|
|||
return redirect(url_for("post.read", id=post.id))
|
||||
return render_template("post/create.html")
|
||||
|
||||
@bp.route("/post/<id>/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/<path:filename>")
|
||||
def uploaded_file(filename):
|
||||
file_path = path.join(current_app.config["DATA_FOLDER"], "uploads")
|
||||
|
|
|
@ -58,6 +58,12 @@
|
|||
|
||||
<a href="{{ url_for('comment.create', post_id=post.id) }}"><button class="btn btn-warning">Leave a Comment</button></a>
|
||||
|
||||
|
||||
|
||||
{% if session.auth.preferred_username == post.submitter %}
|
||||
<hr><a href="{{ url_for('post.delete', id=post.id) }}"><button class="btn btn-danger">Delete Post</button></a>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue