From 7805b98ec0dcb30758e76fe46f87b4146bb45ddd Mon Sep 17 00:00:00 2001 From: Alexander Malzkuhn Date: Thu, 1 May 2025 11:42:33 +0200 Subject: [PATCH] Feiertage in Adminauswertung --- admin.py | 43 ++++++++++++++++++++++++++++++++++---- settings.json | 3 ++- users.py | 37 ++++++++++++++++++++++++++++++-- users/testuser1/2025-5.txt | 2 ++ web_ui.py | 10 --------- 5 files changed, 78 insertions(+), 17 deletions(-) create mode 100644 users/testuser1/2025-5.txt diff --git a/admin.py b/admin.py index 227bbf5..bf48431 100644 --- a/admin.py +++ b/admin.py @@ -455,9 +455,7 @@ Dies kann nicht rückgägig gemacht werden!''') def save_admin_settings(): output_dict = { } output_dict["admin_user"] = admin_user.value - print(admin_password.value) if admin_password.value != "": - print("Passwort neu gesetzt") output_dict["admin_password"] = hash_password(admin_password.value) else: output_dict["admin_password"] = data["admin_password"] @@ -466,8 +464,6 @@ Dies kann nicht rückgägig gemacht werden!''') json_dict = json.dumps(output_dict, indent=4) with open(f"{scriptpath}/{usersettingsfilename}", "w") as outputfile: outputfile.write(json_dict) - print(old_port) - print(int(port.value)) if old_port != int(port.value): with ui.dialog() as dialog, ui.card(): ui.markdown("Damit die Porteinstellungen wirksam werden, muss der Server neu gestartet werden.") @@ -491,6 +487,45 @@ Dies kann nicht rückgägig gemacht werden!''') port = ui.input() old_port = data["port"] port.value = old_port + + @ui.refreshable + def holiday_section(): + with ui.card(): + ui.markdown('**Feiertage:**') + holidays = data["holidays"] + holidays.sort() + + year_list = [ ] + + # Jahresliste erzeugen + for i in holidays: + i_split = i.split("-") + year = int(i_split[0]) + year_list.append(year) + + year_list = list(set(year_list)) + year_dict = { } + + # Jahresdictionary konstruieren + for i in year_list: + year_dict[i] = [ ] + + for i in holidays: + i_split = i.split("-") + year = int(i_split[0]) + month = int(i_split[1]) + day = int(i_split[2]) + date_dt = datetime.datetime(year, month, day) + year_dict[year].append(date_dt) + + for year_entry in year_list: + with ui.row(): + ui.markdown(f"{str(year_entry)}:") + for entry in year_dict[year_entry]: + date_label = entry.strftime("%d.%m.%Y") + ui.button(date_label) + holiday_section() + ui.button("Speichern", on_click=save_admin_settings) with ui.tab_panel(users): diff --git a/settings.json b/settings.json index 22c8ed7..1097177 100644 --- a/settings.json +++ b/settings.json @@ -2,5 +2,6 @@ "admin_user": "admin", "admin_password": "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92", "port": "8090", - "secret": "ftgzuhjikg,mt5jn46uzer8sfi9okrmtzjhndfierko5zltjhdgise" + "secret": "ftgzuhjikg,mt5jn46uzer8sfi9okrmtzjhndfierko5zltjhdgise", + "holidays": [ "2024-01-01", "2024-12-25", "2025-01-01", "2025-05-01"] } \ No newline at end of file diff --git a/users.py b/users.py index f8c1466..5f9c953 100644 --- a/users.py +++ b/users.py @@ -83,9 +83,14 @@ class user: with open(f"{self.get_stamp_file()}.txt", 'r') as file: # Zähle die Zeilen lines = file.readlines() - file.close() except FileNotFoundError: - print(f"Die Datei {file} wurde nicht gefunden.") + print(f"Die Datei {self.get_stamp_file()} wurde nicht gefunden.") + print("Lege die Datei an.") + with open(f'{self.get_stamp_file()}.txt', 'w') as file: + file.write("") + with open(f"{self.get_stamp_file()}.txt", 'r') as file: + # Zähle die Zeilen + lines = file.readlines() if len(lines)== 0: print(f"Keine Einträge") elif len(lines) % 2 == 0: @@ -290,6 +295,23 @@ class user: workhour_entries.sort() day_to_check = datetime.datetime(int(year), int(month), int(day)) + # Fertage prüfen + settings = load_adminsettings() + holidays = settings["holidays"] + + today_dt = datetime.datetime(int(year), int(month), int(day)) + check_date_list = [ ] + for i in holidays: + i_split = i.split("-") + check_year = int(i_split[0]) + check_month = int(i_split[1]) + check_day = int(i_split[2]) + check_dt = datetime.datetime(check_year, check_month, check_day) + check_date_list.append(check_dt) + if today_dt in check_date_list: + return 0 + + # Wochenarbeitszeit durchsuchen for entry in reversed(workhour_entries): entry_split = entry.split("-") @@ -361,3 +383,14 @@ def list_users(): users.sort() return users +# Admineinstellungen auslesen +def load_adminsettings(): + # Settingsdatei einlesen + try: + with open(f"{scriptpath}/{usersettingsfilename}") as json_file: + data = json.load(json_file) + json_file.close() + return(data) + except: + return(-1) + diff --git a/users/testuser1/2025-5.txt b/users/testuser1/2025-5.txt new file mode 100644 index 0000000..36ee3bc --- /dev/null +++ b/users/testuser1/2025-5.txt @@ -0,0 +1,2 @@ +1746090493 +1746090500 diff --git a/web_ui.py b/web_ui.py index d12227a..c4b76e6 100644 --- a/web_ui.py +++ b/web_ui.py @@ -29,16 +29,6 @@ def cookie_hash(user, password): def hash_password(password): return hashlib.sha256(bytes(password, 'utf-8')).hexdigest() -def load_adminsettings(): - # Settingsdatei einlesen - try: - with open(f"{scriptpath}/{usersettingsfilename}") as json_file: - data = json.load(json_file) - json_file.close() - return(data) - except: - return(-1) - class login_mask: def __init__(self, target="/"): data = load_adminsettings()