mirror of
https://github.com/FAUSheppy/ths-blowerdoor-raven
synced 2025-12-10 00:38:33 +01:00
[git fast commit] 13. Nov 2021 - 23:59:07
This commit is contained in:
60
server.py
60
server.py
@@ -3,6 +3,7 @@
|
|||||||
import flask
|
import flask
|
||||||
import argparse
|
import argparse
|
||||||
import glob
|
import glob
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
from data import BlowerdoorData
|
from data import BlowerdoorData
|
||||||
import datetime
|
import datetime
|
||||||
@@ -23,8 +24,9 @@ db = SQLAlchemy(app)
|
|||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
|
||||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
|
|
||||||
class DocumentStatus():
|
class DocumentStatus(db.Model):
|
||||||
documentName = Column(String)
|
__tablename__ = "document_status"
|
||||||
|
documentName = Column(String, primary_key=True)
|
||||||
done = Column(Boolean)
|
done = Column(Boolean)
|
||||||
|
|
||||||
@app.route("/", methods=["GET", "POST"])
|
@app.route("/", methods=["GET", "POST"])
|
||||||
@@ -61,22 +63,47 @@ 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)
|
# 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"])
|
@app.route("/document-status", methods=["GET", "POST", "DELETE"])
|
||||||
def documentStatus():
|
def documentStatus():
|
||||||
documentName = flask.request.form.documentName
|
documentName = flask.request.form["documentName"]
|
||||||
if flask.request.method == "GET":
|
if flask.request.method == "GET":
|
||||||
status = db.session.query(DocumentStatus).filter(
|
status = db.session.query(DocumentStatus).filter(
|
||||||
DocumentStatus.documentName == documentName).first()
|
DocumentStatus.documentName == documentName).first()
|
||||||
return flask.Response(json.dumps(status), 200, mimetype="application/json")
|
return flask.Response(json.dumps(status), 200, mimetype="application/json")
|
||||||
elif flask.request.method == "POST":
|
elif flask.request.method == "POST":
|
||||||
status = DocumentStatus()
|
status = db.session.query(DocumentStatus).filter(
|
||||||
status.documentName = documentName
|
DocumentStatus.documentName == documentName).first()
|
||||||
status.done = flask.request.form.done
|
|
||||||
db.session.add(status)
|
if status:
|
||||||
db.session.commit()
|
status.done = not status.done
|
||||||
return flask.Response("", 200)
|
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":
|
elif flask.request.method == "DELETE":
|
||||||
status = db.session.query(DocumentStatus).filter(
|
status = db.session.query(DocumentStatus).filter(
|
||||||
DocumentStatus.documentName == documentName).first()
|
DocumentStatus.documentName == documentName).first()
|
||||||
@@ -90,9 +117,22 @@ def documentStatus():
|
|||||||
def getFile():
|
def getFile():
|
||||||
print(flask.request.args)
|
print(flask.request.args)
|
||||||
if "delete" in flask.request.args:
|
if "delete" in flask.request.args:
|
||||||
|
|
||||||
|
# delete main file #
|
||||||
fp = os.path.join("static/files/", flask.request.args.get("delete"))
|
fp = os.path.join("static/files/", flask.request.args.get("delete"))
|
||||||
print(fp)
|
print(fp)
|
||||||
os.remove(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("/")
|
return flask.redirect("/")
|
||||||
else:
|
else:
|
||||||
return flask.send_from_directory("static/files/",
|
return flask.send_from_directory("static/files/",
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
{% include 'navbar.html' %}
|
{% include 'navbar.html' %}
|
||||||
<div style="font-size: 16px; font-weight: 300;" class="container mt-5 mb-3" role="main">
|
<div style="font-size: 16px; font-weight: 300;" class="ml-2 mr-3 mt-5 mb-3" role="main">
|
||||||
<form class="my-3 form-border" action="/" method="POST" enctype="multipart/form-data">
|
<form style="max-width: 800px;" class="my-3 form-border"
|
||||||
|
action="/" method="POST" enctype="multipart/form-data">
|
||||||
<input type="file" name="file" />
|
<input type="file" name="file" />
|
||||||
<input type="submit" value="Upload"/>
|
<input type="submit" value="Upload"/>
|
||||||
</form>
|
</form>
|
||||||
@@ -22,11 +23,13 @@
|
|||||||
<th class="th-sm font-weight-bold">Bauherr</th>
|
<th class="th-sm font-weight-bold">Bauherr</th>
|
||||||
<th data-sorter="datesSorter" class="th-sm font-weight-bold">Dokument Erstellungsdatum (Jahr/Monat/Tag)</th>
|
<th data-sorter="datesSorter" class="th-sm font-weight-bold">Dokument Erstellungsdatum (Jahr/Monat/Tag)</th>
|
||||||
<th class="th-sm font-weight-bold"></th>
|
<th class="th-sm font-weight-bold"></th>
|
||||||
|
<th class="th-sm font-weight-bold">Sonstige Dateien</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for bd in listContent %}
|
{% for bd in listContent %}
|
||||||
<tr>
|
{% set done = bd.docName in statusDict and statusDict[bd.docName] %}
|
||||||
|
<tr{% if done %} style="background-color: lightgreen;" {% endif %}>
|
||||||
<td style="line-height: 45px;"><a target="_blank" href="/get-file?basename={{ bd.docName }}">{{ bd.docName }}</a>
|
<td style="line-height: 45px;"><a target="_blank" href="/get-file?basename={{ bd.docName }}">{{ bd.docName }}</a>
|
||||||
{% if bd.outdated %}<p style="color: red;">(neueres Dokument verfügbar: {{ bd.inDocumentDate.strftime("%d.%m.%Y") }})</p>{% endif %}
|
{% if bd.outdated %}<p style="color: red;">(neueres Dokument verfügbar: {{ bd.inDocumentDate.strftime("%d.%m.%Y") }})</p>{% endif %}
|
||||||
</td>
|
</td>
|
||||||
@@ -49,10 +52,24 @@
|
|||||||
action="/get-file" method="DELETE">
|
action="/get-file" method="DELETE">
|
||||||
<button name="delete" value="{{ bd.docName }}">Löschen</button>
|
<button name="delete" value="{{ bd.docName }}">Löschen</button>
|
||||||
</form>
|
</form>
|
||||||
|
{% if done %}
|
||||||
|
<form onsubmit="return confirm('Wirklich als NICHT erledigt markieren?')"
|
||||||
|
action="/document-status" method="POST">
|
||||||
|
<button name="documentName" value="{{ bd.docName }}">Nicht Erledigt</button>
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
<form onsubmit="return confirm('Wirklich als erledigt markieren?')"
|
<form onsubmit="return confirm('Wirklich als erledigt markieren?')"
|
||||||
action="/document-status" method="POST">
|
action="/document-status" method="POST">
|
||||||
<button name="done" value="{{ bd.docName }}">Erledigt</button>
|
<button name="documentName" value="{{ bd.docName }}">Erledigt</button>
|
||||||
</form>
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
<button onclick="addAssotiatedFile()">
|
||||||
|
Zugehörige Datei hinzufügen
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
<td style="line-height: 45px;">
|
||||||
|
energieberechnung.pdf<br>
|
||||||
|
andereszeug.pdf<br>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -12,7 +12,13 @@
|
|||||||
<ul class="navbar-nav mr-auto">
|
<ul class="navbar-nav mr-auto">
|
||||||
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/">Home</a>
|
<a class="nav-link" href="/">Alle Dokumente</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item ml-2">
|
||||||
|
<a class="nav-link" href="/?showstatus=done">Unrledigte</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item ml-2">
|
||||||
|
<a class="nav-link" href="/?showstatus=notdone">Erledigte</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user