add upload button

This commit is contained in:
Yannik Schmidt
2021-10-10 01:18:58 +02:00
parent f1d1b50aac
commit bfdb673202
3 changed files with 26 additions and 2 deletions

17
server.py Normal file → Executable file
View File

@@ -1,3 +1,5 @@
#!/usr/bin/python3
import flask
import argparse
import glob
@@ -5,13 +7,24 @@ import os
from data import BlowerdoorData
import datetime
import os.path
import werkzeug.utils
import eg_geiss_bauherren as parserBackend
app = flask.Flask("THS-Raven")
@app.route("/")
@app.route("/", methods=["GET", "POST"])
def root():
if flask.request.method == 'POST':
fileObj = flask.request.files['file']
fname = werkzeug.utils.secure_filename(fileObj.filename)
fullpath = os.path.join('static/files/', fname)
if not fname.endswith(".pdf"):
return (405, "Datei ist kein PDF")
else:
fileObj.save(fullpath)
return flask.redirect("/")
allFiles = []
loaded = None
for filename in glob.glob("static/files/*.pdf"):
@@ -55,4 +68,4 @@ if __name__ == "__main__":
args = parser.parse_args()
app.run(host=args.interface, port=args.port)
app.run(host=args.interface, port=args.port)

6
static/site.css Normal file
View File

@@ -0,0 +1,6 @@
.form-border{
padding: 10px;
border-width: 2px;
border-style: solid;
border-color: #8c8080;
}

View File

@@ -7,6 +7,11 @@
<body>
{% include 'navbar.html' %}
<div style="font-size: 16px; font-weight: 300;" class="container mt-5 mb-3" role="main">
<form class="my-3 form-border" action="/" method="POST" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="Upload"/>
</form>
<hr class="my-2">
<table id="tableMain" class="table table-striped table-bordered table-sm"
cellspacing="0">
<thead>