mirror of
https://github.com/FAUSheppy/ths-blowerdoor-raven
synced 2025-12-10 08:48:32 +01:00
[git fast commit] 13. Nov 2021 - 20:47:27
This commit is contained in:
44
server.py
44
server.py
@@ -9,9 +9,23 @@ import datetime
|
|||||||
import os.path
|
import os.path
|
||||||
import werkzeug.utils
|
import werkzeug.utils
|
||||||
|
|
||||||
|
from sqlalchemy import Column, Integer, String, Boolean, or_, and_
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
import sqlalchemy
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
import eg_geiss_bauherren as parserBackend
|
import eg_geiss_bauherren as parserBackend
|
||||||
|
|
||||||
app = flask.Flask("THS-Raven")
|
app = flask.Flask("THS-Raven")
|
||||||
|
db = SQLAlchemy(app)
|
||||||
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
|
||||||
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
|
|
||||||
|
class DocumentStatus():
|
||||||
|
documentName = Column(String)
|
||||||
|
done = Column(Boolean)
|
||||||
|
|
||||||
@app.route("/", methods=["GET", "POST"])
|
@app.route("/", methods=["GET", "POST"])
|
||||||
def root():
|
def root():
|
||||||
@@ -31,7 +45,8 @@ def root():
|
|||||||
try:
|
try:
|
||||||
loaded = parserBackend.load(filename)
|
loaded = parserBackend.load(filename)
|
||||||
except Exception:
|
except Exception:
|
||||||
loaded = BlowerdoorData(os.path.basename(filename), os.path.basename(filename), "Fehler", "Fehler", datetime.datetime.now(), datetime.datetime.now())
|
loaded = BlowerdoorData(os.path.basename(filename), os.path.basename(filename),
|
||||||
|
"Fehler", "Fehler", datetime.datetime.now(), datetime.datetime.now())
|
||||||
allFiles.append(loaded)
|
allFiles.append(loaded)
|
||||||
|
|
||||||
# check duplicates
|
# check duplicates
|
||||||
@@ -46,9 +61,31 @@ def root():
|
|||||||
if f.inDocumentDate <= duplicateCheckMap[key].inDocumentDate:
|
if f.inDocumentDate <= duplicateCheckMap[key].inDocumentDate:
|
||||||
f.outdated = True
|
f.outdated = True
|
||||||
|
|
||||||
|
|
||||||
return flask.render_template("index.html", listContent=allFiles)
|
return flask.render_template("index.html", listContent=allFiles)
|
||||||
|
|
||||||
|
@app.route("/document-status", methods=["GET", "POST", "DELETE"])
|
||||||
|
def documentStatus():
|
||||||
|
documentName = flask.request.form.documentName
|
||||||
|
if flask.request.method == "GET":
|
||||||
|
status = db.session.query(DocumentStatus).filter(
|
||||||
|
DocumentStatus.documentName == documentName).first()
|
||||||
|
return flask.Response(json.dumps(status), 200, mimetype="application/json")
|
||||||
|
elif flask.request.method == "POST":
|
||||||
|
status = DocumentStatus()
|
||||||
|
status.documentName = documentName
|
||||||
|
status.done = flask.request.form.done
|
||||||
|
db.session.add(status)
|
||||||
|
db.session.commit()
|
||||||
|
return flask.Response("", 200)
|
||||||
|
elif flask.request.method == "DELETE":
|
||||||
|
status = db.session.query(DocumentStatus).filter(
|
||||||
|
DocumentStatus.documentName == documentName).first()
|
||||||
|
db.session.delete(status)
|
||||||
|
db.session.commit()
|
||||||
|
return flask.Response("", 200)
|
||||||
|
else:
|
||||||
|
return ("Bad Request Method", 405)
|
||||||
|
|
||||||
@app.route("/get-file", methods=["GET", "POST", "DELETE"])
|
@app.route("/get-file", methods=["GET", "POST", "DELETE"])
|
||||||
def getFile():
|
def getFile():
|
||||||
print(flask.request.args)
|
print(flask.request.args)
|
||||||
@@ -63,7 +100,8 @@ def getFile():
|
|||||||
|
|
||||||
@app.before_first_request
|
@app.before_first_request
|
||||||
def init():
|
def init():
|
||||||
pass
|
app.config["DB"] = db
|
||||||
|
db.create_all()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='Start THS-Raven', \
|
parser = argparse.ArgumentParser(description='Start THS-Raven', \
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
<button name="delete" value="{{ bd.docName }}">Löschen</button>
|
<button name="delete" value="{{ bd.docName }}">Löschen</button>
|
||||||
</form>
|
</form>
|
||||||
<form onsubmit="return confirm('Wirklich als erledigt markieren?')"
|
<form onsubmit="return confirm('Wirklich als erledigt markieren?')"
|
||||||
action="/mark-done" method="PATCH">
|
action="/document-status" method="POST">
|
||||||
<button name="done" value="{{ bd.docName }}">Erledigt</button>
|
<button name="done" value="{{ bd.docName }}">Erledigt</button>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user