diff --git a/README.md b/README.md index 3e1203c..0e6f352 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ Das Projekt ermöglicht es einfach zu dokumentieren WANN, WER im Einsatz (oder Das Projekt kann auf jedem Linux Server per Systemd oder ähnlichem gehostet werden. Standard Einstellung ist Port 9000. ##### Hardware: - -Linux Container mit 4GB RAM. +* 2 Kerne +* Linux Container mit 4GB RAM. Deployment: diff --git a/data/data_api.py b/data/data_api.py index 14e3514..8587293 100644 --- a/data/data_api.py +++ b/data/data_api.py @@ -10,7 +10,6 @@ def add_data_to_einsaetze(name, location, date, time, etype, device): data = (name, location, date, time, etype, device) cursor.execute(sql_query, data) - print("DB geschrieben") connection.commit() connection.close() @@ -39,7 +38,9 @@ def get_entrys(): ''') data = cursor.fetchall() connection.close() - return [dict(row) for row in data] + d = [dict(row) for row in data] + print (d) + return d # ATS Träger aus DB Löschen ODER einfügen.abs @@ -61,3 +62,8 @@ def get_ats_with_id(): def delete_entry(entry_id): + connection = sqlite3.connect(DB_NAME) + cursor = connection.cursor() + + cursor.execute("DELETE FROM entrys WHERE id = ?", (entry_id,)) + connection.commit() diff --git a/data/database.py b/data/database.py index 725a0f9..9456188 100644 --- a/data/database.py +++ b/data/database.py @@ -6,7 +6,9 @@ def initialize_db(): connection = sqlite3.connect(DB_NAME) cursor = connection.cursor() - # --- Tabelle 1: Die Liste für dein Dropdown --- + cursor.execute("PRAGMA foreign_keys = ON") + + # --- Tabelle 1: BA Träger --- cursor.execute(''' CREATE TABLE IF NOT EXISTS ba_wearer ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -15,7 +17,16 @@ def initialize_db(): ) ''') - # --- Tabelle 2: Das Logbuch (jetzt mit Ort) --- + # --- Tabelle 2: BA Geräte (muss VOR entrys erstellt werden!) --- + cursor.execute(''' + CREATE TABLE IF NOT EXISTS ba_devices ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT UNIQUE, + code TEXT UNIQUE + ) + ''') + + # --- Tabelle 3: Das Logbuch --- cursor.execute(''' CREATE TABLE IF NOT EXISTS entrys ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -24,21 +35,13 @@ def initialize_db(): date TEXT, time INTEGER, etype TEXT, - device TEXT, + device_id INTEGER, + wearer_id INTEGER, FOREIGN KEY (wearer_id) REFERENCES ba_wearer(id) ON DELETE SET NULL, FOREIGN KEY (device_id) REFERENCES ba_devices(id) ON DELETE SET NULL ) ''') - cursor.execute(''' - CREATE TABLE IF NOT EXISTS ba_devices ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT UNIQUE, - code TEXT UNIQUE - - ) - ''') - # Optional: Ein paar Test-ats anlegen, falls die Tabelle leer ist cursor.execute("SELECT count(*) FROM ats") if cursor.fetchone()[0] == 0: diff --git a/gui/__pycache__/main_gui.cpython-312.pyc b/gui/__pycache__/main_gui.cpython-312.pyc index 183224d..1fc23e5 100644 Binary files a/gui/__pycache__/main_gui.cpython-312.pyc and b/gui/__pycache__/main_gui.cpython-312.pyc differ diff --git a/gui/admin_gui.py b/gui/admin_gui.py index 1d986b4..2aa5819 100644 --- a/gui/admin_gui.py +++ b/gui/admin_gui.py @@ -26,9 +26,7 @@ def setup_route(): rows = data_api.get_entrys() def delete_entry(entry_id: int): - """Hier deinen SQL DELETE Aufruf einfügen.""" data_api.delete_entry(entry_id) - print(f"Lösche Eintrag mit ID: {entry_id}") table.update() table = ui.table(columns=columns, rows= rows, row_key='id').classes('w-full') diff --git a/gui/main_gui.py b/gui/main_gui.py index 1b9a3ae..bdb24d2 100644 --- a/gui/main_gui.py +++ b/gui/main_gui.py @@ -64,12 +64,12 @@ def setup_route(): time = input_time.value etype = input_type.value device = input_device.value + # Hinweis: database Aufruf ist hier korrekt, sofern importiert data_api.add_data_to_einsaetze(name, location, date, time, etype, device) einsaetze_table.rows = data_api.get_entrys() einsaetze_table.update() ui.notify("Eintrag in Datenbank erstellt.") - ClearForm() @@ -96,7 +96,6 @@ def setup_route(): {'name': 'etype', 'label': 'Art', 'field': 'etype', "sortable": True}, {'name': 'device', 'label': 'Gerät', 'field': 'device', "sortable": True}, ] - # Die Tabelle selbst bekommt auch h-full, damit sie die Karte ausfüllt einsaetze_table = ui.table( columns = collums, rows = data_api.get_entrys(),