From 3cd48523a1dd8ab899030417b0e762a5c32fedf3 Mon Sep 17 00:00:00 2001 From: Franke Date: Wed, 8 Jul 2026 09:12:09 +0000 Subject: [PATCH] Sitzplan-Editor: Namen per Drag & Drop auf Plaetze ziehen + Nachrichtenfeld pro Platz + Speichern (noch ohne ESP32-Anbindung) --- Projekt/app.py | 48 ++++++----- Projekt/sitzplan.json | 37 +++------ Projekt/templates/index.html | 155 +++++++++++++++++++++++++++-------- 3 files changed, 160 insertions(+), 80 deletions(-) diff --git a/Projekt/app.py b/Projekt/app.py index fc73653..c03498d 100644 --- a/Projekt/app.py +++ b/Projekt/app.py @@ -1,21 +1,27 @@ -from flask import Flask, render_template -import json - -app = Flask(__name__) - - -@app.route("/") -def home(): - - # Sitzplan-Datei öffnen - with open("sitzplan.json", "r", encoding="utf-8") as datei: - sitzplan = json.load(datei) - - return render_template( - "index.html", - sitzplan=sitzplan - ) - - -if __name__ == "__main__": - app.run(host="0.0.0.0", port=5000) +from flask import Flask, render_template, request, jsonify +import json, os + +app = Flask(__name__) +DATEI = os.path.join(os.path.dirname(__file__), "sitzplan.json") # relativ zum Skript + + +def lade(): + with open(DATEI, "r", encoding="utf-8") as f: + return json.load(f) + + +@app.route("/") +def home(): + return render_template("index.html", data=lade()) + + +@app.route("/speichern", methods=["POST"]) +def speichern(): + daten = request.get_json() + with open(DATEI, "w", encoding="utf-8") as f: + json.dump(daten, f, ensure_ascii=False, indent=2) + return jsonify({"status": "ok"}) + + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000) diff --git a/Projekt/sitzplan.json b/Projekt/sitzplan.json index 165219c..7868d98 100644 --- a/Projekt/sitzplan.json +++ b/Projekt/sitzplan.json @@ -1,27 +1,10 @@ -[ - { - "platz": "platz01", - "name": "Max", - "nachricht": "" - }, - { - "platz": "platz02", - "name": "Lea", - "nachricht": "" - }, - { - "platz": "platz03", - "name": "Tim", - "nachricht": "" - }, - { - "platz": "platz04", - "name": "Ben", - "nachricht": "" - }, - { - "platz": "platz05", - "name": "Eva", - "nachricht": "" - } -] \ No newline at end of file +{ + "namen": ["Max", "Lea", "Tim", "Ben", "Eva"], + "plaetze": [ + { "nr": 1, "name": "", "nachricht": "" }, + { "nr": 2, "name": "", "nachricht": "" }, + { "nr": 3, "name": "", "nachricht": "" }, + { "nr": 4, "name": "", "nachricht": "" }, + { "nr": 5, "name": "", "nachricht": "" } + ] +} diff --git a/Projekt/templates/index.html b/Projekt/templates/index.html index b4a8978..c166c43 100644 --- a/Projekt/templates/index.html +++ b/Projekt/templates/index.html @@ -1,49 +1,140 @@ - + + + Sitzplan -

Sitzplan

+

Namen aus der Box unten auf die Plätze ziehen · pro Platz eine kurze Nachricht eintippen · dann speichern.

-
- {% for platz in sitzplan %} -
- {{ platz.name }} - {% if platz.nachricht %} -
{{ platz.nachricht }}
- {% endif %} -
- {% endfor %} +
+ +
+
Namen
+
+
+ + ✓ gespeichert +
+ + +