From 0fac050b76c11586637bcef8815ce981cdd33e8d Mon Sep 17 00:00:00 2001 From: enne2 Date: Tue, 19 Sep 2023 13:18:51 +0200 Subject: [PATCH] 1.1 --- .gitignore | 1 + README.md | 15 ++++++++----- csvz.py | 22 ------------------- db.py | 25 ---------------------- db/letsswing/.prettierrc | 4 ---- main.py | 23 +++++++++++++++++--- pages/__pycache__/manager.cpython-311.pyc | Bin 12816 -> 12969 bytes pages/manager.py | 2 +- 8 files changed, 32 insertions(+), 60 deletions(-) create mode 100644 .gitignore delete mode 100644 csvz.py delete mode 100644 db.py delete mode 100644 db/letsswing/.prettierrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a5b694 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +db/letsswing diff --git a/README.md b/README.md index c3cf62b..2ae98dd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # TO-DO -- pagina aggiungi/modifica utente -- scelta sede-livello -- login e autenticazione user-password -- ? Tasti indietro -- aggiungre campi email e data tesseramento al db (ce li siamo dimenticati) \ No newline at end of file +- ~~pagina aggiungi/modifica utente~~ +- ~~scelta sede-livello~~ +- ~~login e autenticazione user-password~~ +- ~~? Tasti indietro~~ +- aggiungre campi ~~email~~ e data tesseramento al db (ce li siamo dimenticati) +- ~~retrdatare current_time al costruttore~~ +- route backup +- gestione account login (?) +- gestione eventi,sedi,livelli +- refactor main.py \ No newline at end of file diff --git a/csvz.py b/csvz.py deleted file mode 100644 index 306b9eb..0000000 --- a/csvz.py +++ /dev/null @@ -1,22 +0,0 @@ -import csv -import json - -csvfile = open('allievi.csv', 'r') -jsonfile = open('file.json', 'w') - -reader = csv.reader(csvfile) -next(reader, None) # skip the headers - -for row in reader: - data = {} - data['nome'] = row[1] - data['cognome'] = row[2] - data['livello'] = int(row[0].split()[1]) # assuming 'Beginner 1' should become 1 - data['sede'] = 0 # static value - data['telefono'] = row[3] - data['instagram'] = '@' + row[1] # assuming Instagram handle is @ - data['email'] = row[4] if row[4] else "" # default email if not provided - data['pagamenti'] = [] - data['presenze'] = [] - json.dump(data, jsonfile) - jsonfile.write('\n') \ No newline at end of file diff --git a/db.py b/db.py deleted file mode 100644 index 4998150..0000000 --- a/db.py +++ /dev/null @@ -1,25 +0,0 @@ -from tinydb import TinyDB, Query - -from tinydb.operations import add - -# Initialize the database -db = TinyDB('db.json') - -# Access the 'users' table -users = db.table('users') - -# Insert a new user -user_id = users.insert({'nome': 'Jim', 'cognome': 'Doe', 'livello': 2, - 'sede': 1, 'telefono': '1234567890', 'instagram': '@johndoe', - 'pagamenti': ['2023-01-01T00:00:00', '2022-02-01T00:00:00'], 'presenze': []}) - -print(user_id) - -# Define the user query -User = Query() - -# Update the 'presenze' field for the newly inserted user -users.update(add('presenze', [{'Country':'USA'}])) -# Print all users -res = users.all() -print(res) diff --git a/db/letsswing/.prettierrc b/db/letsswing/.prettierrc deleted file mode 100644 index 222861c..0000000 --- a/db/letsswing/.prettierrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "tabWidth": 2, - "useTabs": false -} diff --git a/main.py b/main.py index 7e3769c..6b6a80a 100644 --- a/main.py +++ b/main.py @@ -6,8 +6,10 @@ import locale from pages import manager, user import signal import os +import shutil from fastapi.responses import RedirectResponse +from fastapi.responses import FileResponse passwords = {'admin': [0,'sw1ng3rs',0, "Matteo Benedetto"], 'user': [1,'pass',1, "Pippo"]} # Set the locale to Italian @@ -55,8 +57,7 @@ def index_page() -> None: def page(sede): if int(sede) <0: results = db.sedi.find() - ui.button(on_click=lambda: (app.storage.user.clear(), ui.open('/login')), icon='logout').props('outline round') - ui.row().classes("w-full") + ui.button(on_click=lambda: (app.storage.user.clear(), ui.open('/login')), icon='logout').props('outline round').style("positon:absolute") with ui.column().classes("w-full h-screen place-items-center items-center").style(""): ui.row().classes("grow") for result in results: @@ -65,7 +66,7 @@ def index_page() -> None: else: results = db.livelli.find() - with ui.row().classes("w-full"): + with ui.row().classes("w-full").style("positon:absolute"): ui.icon("chevron_left", size="lg").on("click", lambda: page.refresh(-1)) with ui.column().classes("w-full h-screen place-items-center items-center"): ui.row().classes("grow") @@ -134,6 +135,22 @@ def edit_page(userid: str, sede: int, livello: int) -> None: ui.button(text="Salva", on_click=save) ui.row().classes("grow") +@ui.page('/backup/{password}') +def password(password: str) -> None: + if password != "1337swing": + return {'msg':'password errata'} + + # Percorso completo del file zip + filename = "backup_db_" +datetime.now().strftime('%Y%m%d%H%M%S') + zip_path = os.path.join('backup', filename) + + # Crea il file zip + shutil.make_archive(zip_path, 'zip', "db") + + return FileResponse(path=zip_path + '.zip', media_type='application/octet-stream', filename=filename+".zip") + + + @ui.page('/login',title="Let's Swing Admin", favicon="assets/favicon.ico") def login() -> None: diff --git a/pages/__pycache__/manager.cpython-311.pyc b/pages/__pycache__/manager.cpython-311.pyc index 4956af069c75415eab516c1ab7000f67a0b90c2b..fe89765d0459876240481f315adc970316fcf865 100644 GIT binary patch delta 1474 zcmaJ>O>7%Q6!zL{yX)9a<-h#Yan?<7vLEj=U`c6ARa_tV? z_nCZ4@_0VQr#o7B&=t?Byf@b+ocZ@>o=YCh&%fw-H2()tG)V+)R<=yt)&f8z;WMpG z5d_w#mC6i=$t~&KnP<^xdwxwH+dlWf()QBN>FFQS)1OOsvfnN2y!QG|dirj9l~RDQo_M2V9b zqbpP4OMOW+guiJsux*M%Rn>MIQk`~KmXLilvMon?ab5F40$&j4$77F3N&aGN9ItpM z_LbDn=i^)9$8po9Y>~{rkH3M-`NXW$%UR;=z*EFLbHIb;z8_(PEmw zOVF(YS#DB(;nPcRK@Tm22_ghhga?7miAu9pgE{{7(0FxR>vyG{EiQ48N1fVOqau&gT}%jcRb)3u|PbK(HwubvNn*#APIXGh7{hjvU>> zRsP32!`o_Ms~-K!*fex!eYP+))wrxhgC}yL2yg& z$~BEsTS36?!uE2-;vXloovYdRUHB_dsxwz&n_@)kQp0dcHKWB`b%fujm#Pdby2jrC zt6^)0yC22?(I58w7I{Q>!&+FlL7?S2o6-7e>7EA-5MX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