From cb757ac6b694f45c40c40f108ad076a327a5def4 Mon Sep 17 00:00:00 2001 From: Alexander Malzkuhn Date: Wed, 23 Apr 2025 14:27:12 +0200 Subject: [PATCH] Vorbereitung Monatsarchivierung --- users.py | 27 +++++++++-- users/testuser1/2025-3.json | 4 ++ users/testuser1/2025-4.txt | 13 +++--- users/testuser1/settings.json | 2 +- users/testuser10/2025-4.json | 4 ++ users/testuser10/2025-4.txt | 14 ++++++ users/{testuser5 => testuser10}/photo.jpg | Bin users/testuser10/settings.json | 17 +++++++ users/testuser3/settings.json | 18 ++------ users/testuser5/2025-4.txt | 12 ----- users/testuser5/settings.json | 37 --------------- web_ui.py | 53 +++++++++++++--------- 12 files changed, 103 insertions(+), 98 deletions(-) create mode 100644 users/testuser1/2025-3.json create mode 100644 users/testuser10/2025-4.json create mode 100644 users/testuser10/2025-4.txt rename users/{testuser5 => testuser10}/photo.jpg (100%) create mode 100644 users/testuser10/settings.json delete mode 100644 users/testuser5/2025-4.txt delete mode 100644 users/testuser5/settings.json diff --git a/users.py b/users.py index 9cea0fc..5be1841 100644 --- a/users.py +++ b/users.py @@ -35,14 +35,13 @@ class user: def get_stamp_file(self): year = str(datetime.datetime.now().year) month = str(datetime.datetime.now().month) - completepath = f"{self.userfolder}/{year}-{month}.txt" + completepath = f"{self.userfolder}/{year}-{month}" return completepath def timestamp(self, stamptime=-1): - filename = self.get_stamp_file() + filename = f"{self.get_stamp_file()}.txt" if stamptime == -1: stamptime = time.time() - print(stamptime) timestamp = int(stamptime) try: @@ -57,10 +56,24 @@ class user: os.makedirs(folder_path, exist_ok=True) self.timestamp() + # Nach zugehörigem JSON-File suchen und bei Bedarf anlegen + try: + json_filename = f"{self.get_stamp_file()}.json" + with open(json_filename, 'r') as json_file: + pass + except: + dict = { } + dict["archived"] = 0 + dict["total_hours"] = 0 + + json_dict = json.dumps(dict, indent=4) + with open(json_filename, 'w') as json_file: + json_file.write(json_dict) + def stamp_status(self): try: # Öffne die Datei im Lese-Modus ('r') - with open(self.get_stamp_file(), 'r') as file: + with open(f"{self.get_stamp_file()}.txt", 'r') as file: # Zähle die Zeilen lines = file.readlines() file.close() @@ -75,7 +88,7 @@ class user: def last_2_timestmaps(self): - with open(self.get_stamp_file(), 'r') as file: + with open(f"{self.get_stamp_file()}.txt", 'r') as file: lines = file.readlines() file.close() @@ -145,6 +158,10 @@ class user: with open(f"{self.userfolder}/{year}-{month}.txt", "w") as file: file.write(''.join(timestamps)) + def archive_hours(self, year, month): + pass + + # Benutzer auflisten def list_users(): users = [d for d in os.listdir(userfolder) if os.path.isdir(os.path.join(userfolder, d))] diff --git a/users/testuser1/2025-3.json b/users/testuser1/2025-3.json new file mode 100644 index 0000000..7ac4a6f --- /dev/null +++ b/users/testuser1/2025-3.json @@ -0,0 +1,4 @@ +{ + "archived": 1, + "total_hours": 28 +} \ No newline at end of file diff --git a/users/testuser1/2025-4.txt b/users/testuser1/2025-4.txt index aef4b0f..ab032c6 100644 --- a/users/testuser1/2025-4.txt +++ b/users/testuser1/2025-4.txt @@ -1,10 +1,11 @@ +1743562800 +1743566400 +1743584340 +1743606000 1743652800 +1743660240 1743667140 -1743923400 -1743965819 -1743965909 -1743966045 -1743967800 +1743685200 1744889948 1744889966 1744989797 @@ -33,5 +34,3 @@ 1745391056 1745391058 1745391059 -1743660240 -1743685200 diff --git a/users/testuser1/settings.json b/users/testuser1/settings.json index 4f9e3b6..ddeac0f 100644 --- a/users/testuser1/settings.json +++ b/users/testuser1/settings.json @@ -4,7 +4,7 @@ "password": "123456789", "workhours": { "2024-04-01": { - "1": "8", + "1": "4", "2": "8", "3": "8", "4": "8", diff --git a/users/testuser10/2025-4.json b/users/testuser10/2025-4.json new file mode 100644 index 0000000..b7881be --- /dev/null +++ b/users/testuser10/2025-4.json @@ -0,0 +1,4 @@ +{ + "archived": 0, + "total_hours": 0 +} \ No newline at end of file diff --git a/users/testuser10/2025-4.txt b/users/testuser10/2025-4.txt new file mode 100644 index 0000000..83ef3f8 --- /dev/null +++ b/users/testuser10/2025-4.txt @@ -0,0 +1,14 @@ +1744989835 +1744989837 +1744989913 +1744989917 +1744991287 +1744991291 +1744991475 +1744991478 +1744991773 +1744991776 +1744991910 +1744991912 +1745411021 +1745411025 diff --git a/users/testuser5/photo.jpg b/users/testuser10/photo.jpg similarity index 100% rename from users/testuser5/photo.jpg rename to users/testuser10/photo.jpg diff --git a/users/testuser10/settings.json b/users/testuser10/settings.json new file mode 100644 index 0000000..c5776db --- /dev/null +++ b/users/testuser10/settings.json @@ -0,0 +1,17 @@ +{ + "username": "testuser10", + "fullname": "Diego Dieci", + "password": "123456789", + "workhours": { + "2024-04-01": { + "1": "1", + "2": "2", + "3": "3", + "4": "4", + "5": "5", + "6": "6", + "7": "7", + "vacation": "30" + } + } +} \ No newline at end of file diff --git a/users/testuser3/settings.json b/users/testuser3/settings.json index 827a4fb..0f422f5 100644 --- a/users/testuser3/settings.json +++ b/users/testuser3/settings.json @@ -4,24 +4,14 @@ "password": "123456789", "workhours": { "2024-04-01": { - "1": "0", - "2": "8", - "3": "8", + "1": "4", + "2": "4", + "3": "4", "4": "8", "5": "8", - "6": "8", + "6": "0", "7": "0", "vacation": "30" - }, - "2024-04-07": { - "1": "0", - "2": "6", - "3": "6", - "4": "6", - "5": "8", - "6": "6", - "7": "0", - "vacation": "28" } } } \ No newline at end of file diff --git a/users/testuser5/2025-4.txt b/users/testuser5/2025-4.txt deleted file mode 100644 index 71c97e7..0000000 --- a/users/testuser5/2025-4.txt +++ /dev/null @@ -1,12 +0,0 @@ -1743966330 -1743966416 -1744989832 -1744989834 -1744989905 -1744989907 -1744989915 -1744989916 -1744991290 -1744991291 -1745004502 -1745004504 diff --git a/users/testuser5/settings.json b/users/testuser5/settings.json deleted file mode 100644 index aeec70b..0000000 --- a/users/testuser5/settings.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "username": "testuser5", - "fullname": "Peter Pan", - "password": "123456789", - "workhours": { - "2025-04-01": { - "1": "0", - "2": "8", - "3": "8", - "4": "8", - "5": "8", - "6": "8", - "7": "0", - "vacation": "30" - }, - "2025-04-07": { - "1": "5", - "2": "6", - "3": "6", - "4": "6", - "5": "8", - "6": "6", - "7": "0", - "vacation": "28" - }, - "2025-03-16": { - "1": 0, - "2": 0, - "3": 0, - "4": 0, - "5": 0, - "6": 0, - "7": 0, - "vacation": 0 - } - } -} \ No newline at end of file diff --git a/web_ui.py b/web_ui.py index f5ef720..774f892 100644 --- a/web_ui.py +++ b/web_ui.py @@ -20,6 +20,10 @@ class pageheader: ui.markdown(f"##{app_title} {app_version}") ui.markdown(f"###{self.heading}") +class ValueBinder: + def __init__(self): + self.value_to_bind = "" + def cookie_hash(user, password): return hashlib.sha256(b"{user}{app.storage.user['id']}{password}").hexdigest() @@ -125,21 +129,25 @@ def page_admin(): with ui.card(): with ui.row() as timetable_header: + year_binder = ValueBinder() + month_binder = ValueBinder() + def update_months(): - - current_user = user(time_user.value) - available_months = current_user.get_months(select_year.value) - - available_months_dict = {} - for element in available_months: - available_months_dict[element] = calendar.month_name[int(element)] - select_month.clear() - select_month.set_options(available_months_dict) - select_month.value = list(available_months)[0] + try: + current_user = user(time_user.value) + available_months = current_user.get_months(year_binder.value_to_bind) + available_months_dict = {} + for element in available_months: + available_months_dict[element] = calendar.month_name[int(element)] + select_month.clear() + select_month.set_options(available_months_dict) + select_month.value = list(available_months)[0] + except: + pass userlist = list_users() ui.markdown("Benutzer:") - time_user = ui.select(options=userlist) + time_user = ui.select(options=userlist, on_change=update_months) time_user.value = userlist[0] current_year = datetime.datetime.now().year @@ -153,9 +161,9 @@ def page_admin(): for element in available_months: available_months_dict[element] = calendar.month_name[int(element)] - select_month = ui.select(options=available_months_dict) + select_month = ui.select(options=available_months_dict).bind_value(month_binder, 'value_to_bind') - select_year = ui.select(options=available_years, on_change=update_months) + select_year = ui.select(options=available_years, on_change=update_months).bind_value(year_binder, 'value_to_bind') try: select_year.value = str(current_year) except: @@ -171,7 +179,7 @@ def page_admin(): with ui.card() as calendar_card: def update_month_and_year(): - with ui.grid(columns=6) as table_grid: + with ui.grid(columns='auto auto 1fr 1fr 1fr 1fr') as table_grid: ui.markdown("**Datum**") ui.markdown("**Buchungen**") ui.markdown("**Soll**") @@ -189,7 +197,7 @@ def page_admin(): ui.markdown(f"{day_in_list.strftime('%a')}., {day}. {calendar.month_name[int(select_month.value)]}") - # ---> Hier die Schleife für die Buchungen + # Buchungen with ui.row(): counter = 0 @@ -242,10 +250,10 @@ def page_admin(): counter += 1 ui.button(actual_timestamp.strftime('%H:%M'), on_click=lambda t_stamp=i, day=day: edit_entry(t_stamp, day)) - #if counter % 2 == 0: - # current_button.props('color=red') - #else: - # current_button.props('color=green') + if counter % 2 != 0: + ui.markdown("-") + else: + ui.markdown("|") # Arbeitszeitsoll bestimmen workhour_entries = list(current_user.workhours) @@ -323,9 +331,10 @@ def page_admin(): update_month_and_year() add_dialog.close() ui.notify("Eintrag hinzugefügt") - - ui.button("Speichern", on_click=add_entry_save) - ui.button("Abbrechen", on_click=add_dialog.close) + with ui.grid(columns=3): + ui.button("Speichern", on_click=add_entry_save) + ui.space() + ui.button("Abbrechen", on_click=add_dialog.close) add_dialog.open() ui.button("Eintrag hinzufügen", on_click=lambda day=day: add_entry(day)) #4x leer und dann Gesamtsald