From 3ae1cd970d3ca84cb2bf3a884985429b60b23231 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Sat, 13 Nov 2021 23:59:07 +0100 Subject: [PATCH] [git fast commit] 13. Nov 2021 - 23:59:07 --- server.py | 60 +++++++++++++++++++++++++++++++++++-------- templates/index.html | 25 +++++++++++++++--- templates/navbar.html | 8 +++++- 3 files changed, 78 insertions(+), 15 deletions(-) diff --git a/server.py b/server.py index f8fd664..ec48f1e 100755 --- a/server.py +++ b/server.py @@ -3,6 +3,7 @@ import flask import argparse import glob +import json import os from data import BlowerdoorData import datetime @@ -23,8 +24,9 @@ db = SQLAlchemy(app) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False -class DocumentStatus(): - documentName = Column(String) +class DocumentStatus(db.Model): + __tablename__ = "document_status" + documentName = Column(String, primary_key=True) done = Column(Boolean) @app.route("/", methods=["GET", "POST"]) @@ -61,22 +63,47 @@ def root(): if f.inDocumentDate <= duplicateCheckMap[key].inDocumentDate: f.outdated = True - return flask.render_template("index.html", listContent=allFiles) + # get done status # + statusList = db.session.query(DocumentStatus).all() + statusDict = dict() + for docStatus in statusList: + statusDict.update({ docStatus.documentName : docStatus.done }) + for bd in allFiles: + if bd.docName in statusDict: + bd.done = statusDict[bd.docName] + + # filter which documents to show based on status # + showStatusArg = flask.request.args.get("showstatus") + if showStatusArg == "done": + allFiles = list(filter(lambda bd: not bd.done, allFiles)) + elif showStatusArg == "notdone": + allFiles = list(filter(lambda bd: bd.done, allFiles)) + + return flask.render_template("index.html", listContent=allFiles, statusDict=statusDict) @app.route("/document-status", methods=["GET", "POST", "DELETE"]) def documentStatus(): - documentName = flask.request.form.documentName + 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) + status = db.session.query(DocumentStatus).filter( + DocumentStatus.documentName == documentName).first() + + if status: + status.done = not status.done + db.session.add(status) + db.session.commit() + else: + status = DocumentStatus() + status.documentName = documentName + status.done = True + db.session.add(status) + db.session.commit() + + return flask.redirect("/") elif flask.request.method == "DELETE": status = db.session.query(DocumentStatus).filter( DocumentStatus.documentName == documentName).first() @@ -90,9 +117,22 @@ def documentStatus(): def getFile(): print(flask.request.args) if "delete" in flask.request.args: + + # delete main file # fp = os.path.join("static/files/", flask.request.args.get("delete")) print(fp) os.remove(fp) + + # delete assotiated files # + # TODO + + # delete the done status # + status = db.session.query(DocumentStatus).filter( + DocumentStatus.documentName == flask.request.args.get("delete")).first() + if status: + db.session.delete(status) + db.session.commit() + return flask.redirect("/") else: return flask.send_from_directory("static/files/", diff --git a/templates/index.html b/templates/index.html index 8ffb501..7850588 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,8 +6,9 @@ {% include 'navbar.html' %} -
-
+
+ @@ -22,11 +23,13 @@ Bauherr Dokument Erstellungsdatum (Jahr/Monat/Tag) + Sonstige Dateien {% for bd in listContent %} - + {% set done = bd.docName in statusDict and statusDict[bd.docName] %} + {{ bd.docName }} {% if bd.outdated %}

(neueres Dokument verfügbar: {{ bd.inDocumentDate.strftime("%d.%m.%Y") }})

{% endif %} @@ -49,10 +52,24 @@ action="/get-file" method="DELETE"> + {% if done %} +
+ +
+ {% else %}
- +
+ {% endif %} + + + + energieberechnung.pdf
+ andereszeug.pdf
{% endfor %} diff --git a/templates/navbar.html b/templates/navbar.html index 7f30e7a..519187c 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -12,7 +12,13 @@