enne2 2 years ago
parent
commit
0fac050b76
  1. 1
      .gitignore
  2. 15
      README.md
  3. 22
      csvz.py
  4. 25
      db.py
  5. 4
      db/letsswing/.prettierrc
  6. 23
      main.py
  7. BIN
      pages/__pycache__/manager.cpython-311.pyc
  8. 2
      pages/manager.py

1
.gitignore vendored

@ -0,0 +1 @@
db/letsswing

15
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)
- ~~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

22
csvz.py

@ -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 @<name>
data['email'] = row[4] if row[4] else "" # default email if not provided
data['pagamenti'] = []
data['presenze'] = []
json.dump(data, jsonfile)
jsonfile.write('\n')

25
db.py

@ -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)

4
db/letsswing/.prettierrc

@ -1,4 +0,0 @@
{
"tabWidth": 2,
"useTabs": false
}

23
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:

BIN
pages/__pycache__/manager.cpython-311.pyc

Binary file not shown.

2
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):

Loading…
Cancel
Save