From 8d91c63a12c555ad791107fd5fa6f89ccfbc1bde Mon Sep 17 00:00:00 2001 From: Anika Date: Wed, 20 Mar 2024 13:28:19 +0100 Subject: [PATCH] cleanup and bug fixed upload saved the key of the dict as int not str --- app.py | 3 +-- templates/index.html | 22 ++++++---------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/app.py b/app.py index 82c4243..bed4d35 100644 --- a/app.py +++ b/app.py @@ -128,8 +128,7 @@ def upload(): content = alarm["message"] global alarmIndex alarmIndex += 1 - activeAlarms[alarmIndex] = {'datetime':datetime.strftime(time,"%d.%m.%Y %H:%M"),'message':content} - + activeAlarms[str(alarmIndex)] = {'datetime':datetime.strftime(time,"%d.%m.%Y %H:%M"),'message':content} # ja, wir schreiben einfach das ganze File neu, ist aber einfacher with open('alarms.json', 'w') as f: json.dump(activeAlarms, f, indent=2) diff --git a/templates/index.html b/templates/index.html index 66d67ef..997baa3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -67,28 +67,17 @@ method: "POST", body: body, }); - fetch("/processAlarm", { - method: "GET" - }).then(response => { - return response.text(); - }) - .then(html => { - upcomingAlarms.innerHTML = html - }) - fetch("/processpAlarm", { - method: "GET" - }).then(response => { - return response.text(); - }) - .then(html => { - previousAlarms.innerHTML = html - }) + reloadAlarms(); } async function deleteAlarm(id){ const response = await fetch("http://127.0.0.1:5000/deletealarm", { method: "POST", body: id, }); + reloadAlarms(); + } + + function reloadAlarms(){ fetch("/processAlarm", { method: "GET" }).then(response => { @@ -105,6 +94,7 @@ .then(html => { previousAlarms.innerHTML = html }) + } function checkAlarms(){