generate new numbers ony by one
This commit is contained in:
parent
d5da62d800
commit
4a435037cd
44
app.py
44
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(
|
||||
|
|
|
|||
|
|
@ -22,12 +22,16 @@
|
|||
<body>
|
||||
<h2>Panel admina</h2>
|
||||
|
||||
<form method="post" style="margin-bottom:12px">
|
||||
<label>Start — liczba numerów:
|
||||
<input name="count" type="number" min="1" value="20" style="width:80px;margin-left:6px">
|
||||
</label>
|
||||
<button class="btn" name="action" value="start">Start</button>
|
||||
<button class="btn" name="action" value="reset">Reset</button>
|
||||
<form method="post" style="margin-bottom:18px">
|
||||
<div style="display:flex;flex-direction:column;gap:10px;max-width:220px">
|
||||
<button class="btn" name="action" value="add" style="background:#4caf50;color:#fff;border:none;padding:8px 12px;border-radius:6px">
|
||||
Dodaj numer
|
||||
</button>
|
||||
|
||||
<button class="btn" name="action" value="reset" style="background:#e53935;color:#fff;border:none;padding:8px 12px;border-radius:6px">
|
||||
Reset — usuń wszystkie
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="grid">
|
||||
|
|
|
|||
Loading…
Reference in New Issue