fix delete

This commit is contained in:
Yannik Schmidt
2021-10-10 13:21:02 +02:00
parent e07eaf4717
commit 639c7b6255
2 changed files with 16 additions and 2 deletions

View File

@@ -49,9 +49,17 @@ def root():
return flask.render_template("index.html", listContent=allFiles)
@app.route("/get-file")
@app.route("/get-file", methods=["GET", "POST", "DELETE"])
def getFile():
return flask.send_from_directory("static/files/", flask.request.args.get("basename"), mimetype="application/pdf")
print(flask.request.args)
if "delete" in flask.request.args:
fp = os.path.join("static/files/", flask.request.args.get("delete"))
print(fp)
os.remove(fp)
return flask.redirect("/")
else:
return flask.send_from_directory("static/files/",
flask.request.args.get("basename"), mimetype="application/pdf")
@app.before_first_request
def init():

View File

@@ -43,6 +43,12 @@
{% endif %}">
{{ bd.customer }}</td>
<td style="line-height: 45px;">{{ bd.pdfDate.strftime("%Y/%m/%d") }}</td>
<td style="line-height: 45px;">
<form onsubmit="return confirm('Wirklich unwideruflich löschen?')"
action="/get-file" method="DELETE">
<button name="delete" value="{{ bd.docName }}">Löschen</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>