From 97dd38393cb4e750f070cd5f9c435201b6a4639c Mon Sep 17 00:00:00 2001 From: Alexander Malzkuhn Date: Wed, 14 May 2025 13:45:56 +0200 Subject: [PATCH 1/2] Zeitenberechnung in JSON-API Fehlerkorrekturen im Admin-Panel --- admin.py | 16 ++++---- api.py | 79 ++++++++++++++++++++++++++++++++++--- users.py | 21 +++++++++- users/testuser1/2025-4.json | 2 +- users/testuser1/2025-5.json | 11 +++++- users/testuser1/2025-5.txt | 5 ++- 6 files changed, 116 insertions(+), 18 deletions(-) diff --git a/admin.py b/admin.py index dd07a58..f755ef6 100644 --- a/admin.py +++ b/admin.py @@ -532,16 +532,18 @@ Dies kann nicht rückgängig gemacht werden!''') username_labels["admin"] = ui.markdown("Administrator:") # Textarea für Admin note_labels["admin"] = ui.textarea() + del_buttons["admin"] = ui.button(icon='remove', on_click=lambda user="admin": del_note_entry(user)) for name, text in notes.items(): if name != "admin": - noteuser = "user" - username_labels[noteuser] = ui.markdown(current_user.fullname) - note_labels[noteuser] = ui.markdown(text) - else: - noteuser = "admin" - note_labels[noteuser].set_value(text) - del_buttons[noteuser] = ui.button(icon='remove', on_click=lambda user=noteuser: del_note_entry(user)) + username_labels["user"] = ui.markdown(current_user.fullname) + note_labels["user"] = ui.markdown(text) + del_buttons["user"] = ui.button(icon='remove', + on_click=lambda + user="user": del_note_entry( + user)) + + with ui.row(): ui.button("OK", on_click=save_notes) diff --git a/api.py b/api.py index 508c091..5811694 100644 --- a/api.py +++ b/api.py @@ -81,9 +81,8 @@ def page_overview_month(username: str, year: int, month: int): color_day = color_weekend current_day_date = f"{datetime(year, month, day).strftime('%a')}, {day}.{month}.{year}" - with ui.link_target(day): - ui.markdown(current_day_date).classes(f'border px-{pad_x} py-{pad_y} bg-{color_day}') - + with ui.link_target(day).classes(f'border px-{pad_x} py-{pad_y} bg-{color_day}'): + ui.markdown(current_day_date) # Abwesenheitseinträge booking_color = "inherit" @@ -108,6 +107,20 @@ def page_overview_month(username: str, year: int, month: int): if len(timestamps_dict[day]) % 2 != 0: booking_text += datetime.fromtimestamp(int(timestamps_dict[day][i])).strftime('%H:%M') + " - ***Buchung fehlt!***" + day_notes = current_user.get_day_notes(year, month, day) + just_once = True + if len(day_notes) > 0: + if len(timestamps_dict[day]) > 0 or day in list(map(int, list(user_absent))): + booking_text += "
" + for user_key, notes in day_notes.items(): + if user_key == "admin": + booking_text += f"Administrator:
{notes}" + else: + booking_text += f"{current_user.fullname}:
{notes}" + if len(day_notes) > 1 and just_once: + booking_text += "
" + just_once = False + booking_text_element = ui.markdown(booking_text).classes(f'border px-{pad_x} py-{pad_y} bg-{booking_color} text-{booking_text_color}') # Ist-Zeiten berechnen @@ -222,9 +235,9 @@ def page_overview_month(username: str, year: int, month: int): if total_absence_days > 0: ui.markdown("###Abwesenheitstage diesen Monat:") - with ui.grid(columns='auto 20%').classes(f'gap-0 border px-0 py-0'): + with ui.grid(columns='auto 25%').classes(f'gap-0 border px-0 py-0'): - for key,value in absence_dict.items(): + for key, value in absence_dict.items(): if value > 0: ui.markdown(absence_entries[key]['name']).classes(f"border px-{pad_x} py-{pad_y}") ui.markdown(str(value)).classes(f'border px-{pad_x} py-{pad_y} text-center') @@ -434,3 +447,59 @@ def page_api_stamp(api_key: str): if found_key == False: ui.label("Keinen passenden Benutzer gefunden") + +@app.get("/api/json/{api_key}") +def json_info(api_key: str): + userlist = list_users() + user_dict = {} + # Dictionary mit Usernamen befüllen + for i in userlist: + user_dict[i] = "" + for entry in list(user_dict): + try: + temp_user = user(entry) + user_dict[entry] = temp_user.api_key + except: + pass + + found_key = False + + for user_key, api_value in user_dict.items(): + if api_key == api_value: + current_user = user(user_key) + now_dt = datetime.now() + year = now_dt.year + month = now_dt.month + day = now_dt.day + + found_key = True + data = { } + data["user"] = current_user.username + if current_user.stamp_status() == status_in: + data["status"] = 1 + else: + data["status"] = 0 + absences = current_user.get_absence(now_dt.year, now_dt.month) + data["absence"] = 0 + if str(now_dt.day) in list(absences): + data["absence"] = absences[str(now_dt.day)] + data["time"] = { } + data["time"]["today"] = current_user.get_worked_time(now_dt.year, now_dt.month, now_dt.day)[0] + + # Arbeitszeit berechnen + months_time_sum = 0 + for checkday in range(1, day + 1): + months_time_sum += (int(current_user.get_worked_time(year, month, checkday)[0]) - int(current_user.get_day_workhours(year, month, checkday))*3600) + + time_saldo = months_time_sum + current_user.get_last_months_overtime(year, month) + + data["time"]["overall"] = time_saldo + data["vacation"] = { } + data["vacation"]["claim"] = current_user.get_vacation_claim(now_dt.year, now_dt.month, now_dt.day) + data["vacation"]["used"] = current_user.count_vacation_days(now_dt.year) + data["vacation"]["remaining"] = data["vacation"]["claim"] - data["vacation"]["used"] + return data + break + + if not found_key: + return { "data": "none"} \ No newline at end of file diff --git a/users.py b/users.py index 9d9f2ff..6dd0fec 100644 --- a/users.py +++ b/users.py @@ -243,6 +243,7 @@ class user: return days_with_errors except: return [ ] + def archive_hours(self, year, month, overtime: int): filename = f"{self.userfolder}/{year}-{month}.json" @@ -259,6 +260,7 @@ class user: os.chmod(filename, S_IREAD) filename_txt = f"{self.userfolder}/{year}-{month}.txt" os.chmod(filename_txt, S_IREAD) + def get_last_months_overtime(self, year, month): try: if int(month) == 1: @@ -301,6 +303,8 @@ class user: if len(note_dict) == 1: json_data["notes"][str(day)] = { } json_data["notes"][str(day)]["user"] = note_dict["user"] + if json_data["notes"][str(day)]["user"] == "": + del json_data["notes"][str(day)]["user"] else: json_data["notes"][str(day)] = note_dict @@ -340,7 +344,7 @@ class user: json_file.write(json_dict) def get_day_workhours(self, year, month, day): - global hours_to_work + #global hours_to_work workhour_entries = list(self.workhours) workhour_entries.sort() day_to_check = datetime.datetime(int(year), int(month), int(day)) @@ -394,7 +398,20 @@ class user: claim = self.workhours[entry]["vacation"] break - return claim + return int(claim) + + def count_vacation_days(self, year): + vacation_used = 0 + for month in range(0, 13): + try: + absence_dict = self.get_absence(year, month) + for entry, absence_type in absence_dict.items(): + if absence_type == "U": + vacation_used += 1 + + except: + pass + return vacation_used def delete_photo(self): os.remove(self.photofile) diff --git a/users/testuser1/2025-4.json b/users/testuser1/2025-4.json index 48da952..f5daf68 100644 --- a/users/testuser1/2025-4.json +++ b/users/testuser1/2025-4.json @@ -1,6 +1,6 @@ { "archived": 1, - "overtime": -877154, + "overtime": -348226, "absence": { "7": "U", "8": "K", diff --git a/users/testuser1/2025-5.json b/users/testuser1/2025-5.json index 7ec0e06..b48584c 100644 --- a/users/testuser1/2025-5.json +++ b/users/testuser1/2025-5.json @@ -2,7 +2,13 @@ "archived": 0, "overtime": 0, "absence": { - "2": "SO" + "2": "SO", + "8": "U", + "9": "U", + "10": "U", + "11": "U", + "12": "U", + "13": "U" }, "notes": { "5": { @@ -20,6 +26,7 @@ }, "12": { "user": "Testtext" - } + }, + "14": {} } } \ No newline at end of file diff --git a/users/testuser1/2025-5.txt b/users/testuser1/2025-5.txt index 58cd3a9..a5ae764 100644 --- a/users/testuser1/2025-5.txt +++ b/users/testuser1/2025-5.txt @@ -8,4 +8,7 @@ 1746609037 1747206908 1747207022 -1747813500 +1747213977 +1747214813 +1747216800 +1747220619 From 21c8b4fb984ff1cf215eee95d43af3ee6a46b824 Mon Sep 17 00:00:00 2001 From: Alexander Malzkuhn Date: Thu, 15 May 2025 10:37:59 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Zeiteintr=C3=A4ge=20f=C3=BCr=20Zukunft=20un?= =?UTF-8?q?terbunden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/admin.py b/admin.py index f755ef6..f20a4d0 100644 --- a/admin.py +++ b/admin.py @@ -538,12 +538,7 @@ Dies kann nicht rückgängig gemacht werden!''') if name != "admin": username_labels["user"] = ui.markdown(current_user.fullname) note_labels["user"] = ui.markdown(text) - del_buttons["user"] = ui.button(icon='remove', - on_click=lambda - user="user": del_note_entry( - user)) - - + del_buttons["user"] = ui.button(icon='remove', on_click=lambda user="user": del_note_entry(user)) with ui.row(): ui.button("OK", on_click=save_notes) @@ -556,6 +551,9 @@ Dies kann nicht rückgängig gemacht werden!''') menu_item = ui.menu_item("Zeiteintrag hinzufügen", lambda day=day: add_entry(day)) if archive_status: menu_item.disable() + if datetime.datetime.now().day < day: + menu_item.disable() + menu_item.tooltip("Kann keine Zeiteinträge für die Zukunft vornehmen.") ui.separator() menu_item = ui.menu_item("Notizen bearbeiten", lambda day=day: edit_notes(day)) if archive_status: