From 4a435037cd7feb94a4abb83d8244e388523c7460 Mon Sep 17 00:00:00 2001 From: miklo Date: Sun, 23 Nov 2025 23:02:41 +0100 Subject: [PATCH] generate new numbers ony by one --- app.py | 44 +++++++++++++++++++++++--------------------- templates/admin.html | 16 ++++++++++------ 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/app.py b/app.py index bf3840f..a49a73a 100644 --- a/app.py +++ b/app.py @@ -66,41 +66,43 @@ def current_api(): # @app.route("/admin", methods=["GET", "POST"]) def admin(): db = get_db() + if request.method == "POST": action = request.form.get("action") - if action == "start": - n = int(request.form.get("count", "0")) - db.execute("DELETE FROM items") - for i in range(1, n + 1): - db.execute( - "INSERT INTO items (number, status) VALUES (?, 'waiting')", - (str(i),), - ) + if action == "add": + # dodaj nowy numer na końcu puli + cur = db.execute("SELECT number FROM items ORDER BY id DESC LIMIT 1").fetchone() + if cur: + try: + last = int(cur["number"]) + except: + last = 0 + new = last + 1 + else: + new = 1 + db.execute("INSERT INTO items (number, status) VALUES (?, 'waiting')", (str(new),)) db.commit() + elif action == "call": num = request.form.get("num") - # mark chosen number as called - db.execute( - "UPDATE items SET status='called' WHERE number=? AND status='waiting'", - (num,), - ) + db.execute("UPDATE items SET status='called' WHERE number=? AND status='waiting'", (num,)) db.commit() + elif action == "done": num = request.form.get("num") - db.execute( - "UPDATE items SET status='done' WHERE number=? AND status='called'", - (num,), - ) - db.commit() - elif action == "reset": - db.execute("DELETE FROM items") + db.execute("UPDATE items SET status='done' WHERE number=? AND status='called'", (num,)) db.commit() + elif action == "return": num = request.form.get("num") if num: - # ustaw ponownie na 'waiting' tylko jeśli aktualnie było 'called' db.execute("UPDATE items SET status='waiting' WHERE number=? AND status='called'", (num,)) db.commit() + + elif action == "reset": + db.execute("DELETE FROM items") + db.commit() + return redirect(url_for("admin")) cur_wait = db.execute( diff --git a/templates/admin.html b/templates/admin.html index 75a8d83..7a011cf 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -22,12 +22,16 @@

Panel admina

-
- - - + +
+ + + +