commit
ce1b09ea0e
3 changed files with 72 additions and 0 deletions
Binary file not shown.
@ -0,0 +1,72 @@ |
|||||||
|
from nicegui import ui |
||||||
|
import sqlite3 |
||||||
|
import signal |
||||||
|
import os |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def dict_factory(cursor, row): |
||||||
|
d = {} |
||||||
|
for idx, col in enumerate(cursor.description): |
||||||
|
d[col[0]] = row[idx] |
||||||
|
return d |
||||||
|
|
||||||
|
def read_data(query): |
||||||
|
try: |
||||||
|
cursor.execute(query) |
||||||
|
rows = cursor.fetchall() |
||||||
|
return rows |
||||||
|
except sqlite3.Error as e: |
||||||
|
ui.notify("{e}") |
||||||
|
return None |
||||||
|
|
||||||
|
def registra_presenza(id, flag): |
||||||
|
|
||||||
|
try: |
||||||
|
cursor.execute("UPDATE users SET presenze = ? WHERE id = ?", (1 if flag==True else 0, id) ) |
||||||
|
conn.commit() |
||||||
|
|
||||||
|
finally: |
||||||
|
tabellaUtenti.refresh() |
||||||
|
os.kill(os.getpid(), signal.SIGUSR1) |
||||||
|
|
||||||
|
@ui.refreshable |
||||||
|
def tabellaUtenti(): |
||||||
|
rows = read_data("SELECT u.*, (SELECT data FROM pagamenti WHERE user_id=u.id AND date(data) = '2021-05-31' ORDER BY id DESC LIMIT 1) as pagamenti FROM users as u;") |
||||||
|
for row in rows: |
||||||
|
with ui.row().classes("w-full"): |
||||||
|
with ui.column().classes("grow"): |
||||||
|
ui.label(f"{row['nome']} {row['cognome'][0].upper()}.").style('color:'+("black" if row['pagamenti'] else "red")) |
||||||
|
with ui.column(): |
||||||
|
if row["presenze"] == 1: |
||||||
|
ui.button(color="primary", text= "presente", on_click= lambda: registra_presenza(row["id"], False)) |
||||||
|
else: |
||||||
|
ui.button(color="secondary", text= "assente", on_click= lambda: registra_presenza(row["id"], True)) |
||||||
|
|
||||||
|
ui.separator() |
||||||
|
|
||||||
|
def onSignal(signum, frame): |
||||||
|
tabellaUtenti.refresh() |
||||||
|
|
||||||
|
signal.signal(signal.SIGUSR1, onSignal) |
||||||
|
|
||||||
|
# START |
||||||
|
|
||||||
|
conn = sqlite3.connect('letsswing.db') |
||||||
|
conn.row_factory = dict_factory |
||||||
|
cursor = conn.cursor() |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
with ui.row().classes("w-full"): |
||||||
|
with ui.column().classes("grow"): |
||||||
|
ui.label("Beginner a matera") |
||||||
|
with ui.column(): |
||||||
|
ui.icon("thumb_up") |
||||||
|
|
||||||
|
tabellaUtenti() |
||||||
|
|
||||||
|
|
||||||
|
ui.run(host="0.0.0.0") |
||||||
|
|
||||||
Loading…
Reference in new issue