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 4956af0..fe89765 100644 Binary files a/pages/__pycache__/manager.cpython-311.pyc and b/pages/__pycache__/manager.cpython-311.pyc differ diff --git a/pages/manager.py b/pages/manager.py index cdb29d0..9006c9a 100644 --- a/pages/manager.py +++ b/pages/manager.py @@ -6,7 +6,7 @@ from montydb.database import MontyDatabase class Manager: def __init__(self): - self.current_time = datetime.now() + self.current_time = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(seconds=1) self.current_index = 0 def main(self, db: MontyDatabase, sede, livello):