From a34d9954918ddf92080857bd6ceaf004b12d8e1f Mon Sep 17 00:00:00 2001 From: Alexander Malzkuhn Date: Wed, 4 Jun 2025 13:28:45 +0200 Subject: [PATCH] Pfadchecks angepasst Favicon wird bei Start bei Bedarf erzeugt --- Dockerfile | 1 - docker-compose.yml | 5 ++++- favicon.svg => favicon_original.svg | 0 lib/homepage.py | 1 - lib/users.py | 32 ++++++++++++++++++++++++----- main.py | 6 +++++- 6 files changed, 36 insertions(+), 9 deletions(-) rename favicon.svg => favicon_original.svg (100%) diff --git a/Dockerfile b/Dockerfile index f97154d..570b0f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,6 @@ ENV LANGUAGE de_DE:de ENV LC_ALL de_DE.UTF-8 COPY main.py /app/main.py -COPY favicon.svg /app/favicon.svg COPY lib /app/lib/ EXPOSE 8090 ENTRYPOINT ["/.venv/bin/python", "/app/main.py"] diff --git a/docker-compose.yml b/docker-compose.yml index 9695725..2237bb1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,8 +4,11 @@ services: restart: always ports: - 8090:8090 + environment: + - PYTHONUNBUFFERED=1 volumes: - #- /home/alexander/Dokumente/Python/Zeiterfassung:/app + #- /home/alexander/Dokumente/Python/Zeiterfassung/lib:/app/lib + #- /home/alexander/Dokumente/Python/Zeiterfassung/main.py:/app/main.py - /home/alexander/Dokumente/Python/Zeiterfassung/docker-work/users:/users - /home/alexander/Dokumente/Python/Zeiterfassung/docker-work/backup:/backup - /home/alexander/Dokumente/Python/Zeiterfassung/docker-work/settings:/settings \ No newline at end of file diff --git a/favicon.svg b/favicon_original.svg similarity index 100% rename from favicon.svg rename to favicon_original.svg diff --git a/lib/homepage.py b/lib/homepage.py index 78f1caa..41ed5f8 100644 --- a/lib/homepage.py +++ b/lib/homepage.py @@ -170,7 +170,6 @@ def homepage(): note_dict["user"] = daynote.value nonlocal last_selection last_selection = day_selector.value - print(f"Last selection from save: {last_selection}") if day_selector.value == 0: day_to_write = today.day else: diff --git a/lib/users.py b/lib/users.py index 97e4e93..a556904 100644 --- a/lib/users.py +++ b/lib/users.py @@ -136,10 +136,15 @@ class user: outputfile.write(json_dict) pathcheck = self.userfolder - pathcheck = pathcheck.removeprefix(os.path.join(scriptpath, userfolder)) + if not is_docker(): + pathcheck = pathcheck.removeprefix(os.path.join(scriptpath, userfolder)) + if pathcheck != self.username: + os.rename(self.userfolder, os.path.join(scriptpath, userfolder, self.username)) + else: + pathcheck = pathcheck.removeprefix("/users") + if pathcheck != self.username: + os.rename(self.userfolder, os.path.join(userfolder, self.username)) - if pathcheck != self.username: - os.rename(self.userfolder, os.path.join(scriptpath, userfolder, self.username)) def del_user(self): shutil.rmtree(self.userfolder) @@ -304,10 +309,27 @@ class user: return { } def write_notes(self, year, month, day, note_dict): - with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "r") as json_file: - json_data = json.load(json_file) + try: + with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "r") as json_file: + json_data = json.load(json_file) + except FileNotFoundError: + dict = {} + dict["archived"] = 0 + dict["total_hours"] = 0 + dict["notes"] = { } + + json_dict = json.dumps(dict, indent=4) + with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), 'w') as json_file: + json_file.write(json_dict) + + json_data = dict + if len(note_dict) == 1: user_info = list(note_dict)[0] + try: + json_data["notes"] + except KeyError: + json_data["notes"] = { } json_data["notes"][str(day)] = { } json_data["notes"][str(day)][user_info] = note_dict[user_info] if json_data["notes"][str(day)][user_info] == "": diff --git a/main.py b/main.py index 8afed99..144988a 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 # Zeiterfassung +import os.path from lib.web_ui import * from lib.admin import * @@ -172,8 +173,11 @@ def main(): ''' + if not os.path.exists(os.path.join(scriptpath, "favicon.svg")): + with open(os.path.join(scriptpath, "favicon.svg"), 'w') as favicon_file: + favicon_file.write(favicon) - ui.run(favicon=favicon, port=port, storage_secret=secret, language='de-DE', show_welcome_message=False) + ui.run(favicon=os.path.join(scriptpath, "favicon.svg"), port=port, storage_secret=secret, language='de-DE', show_welcome_message=False) if __name__ in ("__main__", "__mp_main__"): parser = argparse.ArgumentParser(description=f'{app_title} {app_version}')