From 208d0c0c54cb3147b0864f08ddcefeabd9063d24 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Sun, 2 Aug 2026 21:52:46 +0200 Subject: [PATCH] modified: routes/journal_routes.py modified: templates/edit_future.html modified: templates/future.html modified: templates/report.html --- routes/journal_routes.py | 32 ++++++++++++++++++++++++-------- templates/edit_future.html | 4 ++-- templates/future.html | 4 ++-- templates/report.html | 2 +- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/routes/journal_routes.py b/routes/journal_routes.py index 40c66b7..1470649 100644 --- a/routes/journal_routes.py +++ b/routes/journal_routes.py @@ -54,6 +54,21 @@ def parse_date(s: str) -> date | None: return None +def parse_month(s: str) -> date | None: + """Akzeptiert 'YYYY-MM' oder 'YYYY-MM-DD'; liefert den 1. des Monats.""" + s = (s or "").strip() + if not s: + return None + try: + if len(s) == 7: # YYYY-MM + y, mo = int(s[:4]), int(s[5:7]) + return date(y, mo, 1) + d = parse_date(s) # YYYY-MM-DD + return d.replace(day=1) if d else None + except (ValueError, TypeError): + return None + + def _fetch_notes(user_id: int, note_date: date) -> list[dict]: with get_connection() as conn: with conn.cursor() as cur: @@ -123,11 +138,7 @@ def _report_filters() -> dict: if range_type == "month": month_param = args.get("month", "") - try: - y, mo = (int(x) for x in month_param.split("-")) - start = date(y, mo, 1) - except (ValueError, TypeError): - start = date.today().replace(day=1) + start = parse_month(month_param) or date.today().replace(day=1) end = date(start.year, start.month, calendar.monthrange(start.year, start.month)[1]) label = start.strftime("%B %Y") @@ -276,7 +287,7 @@ def future(): if request.method == "POST": note_text = request.form.get("note_text", "").strip() month_str = request.form.get("month", "") - month = parse_date(month_str) + month = parse_month(month_str) ref_type = request.form.get("ref_type", "").strip() ref_value = request.form.get("ref_value", "").strip() refs = None @@ -604,10 +615,16 @@ def report(): current_week = monday_of_week(today).strftime("%G-W%V") current_month = today.strftime("%Y-%m") + current_month_date = today.strftime("%Y-%m-%d") filters["week_value"] = current_week filters["from_value"] = filters["start"].strftime("%Y-%m-%d") if filters["range_type"] == "custom" else "" filters["to_value"] = filters["end"].strftime("%Y-%m-%d") if filters["range_type"] == "custom" else "" + filters["month_value"] = ( + filters["start"].strftime("%Y-%m-%d") + if filters["range_type"] == "month" + else current_month_date + ) return render_template( "report.html", @@ -623,7 +640,6 @@ def report(): export_pdf_url=export_pdf_url, ) - @journal_bp.route("/report/export") @login_required def report_export(): @@ -765,7 +781,7 @@ def edit_future(entry_id: int): if request.method == "POST": note_text = request.form.get("note_text", "").strip() month_str = request.form.get("month", "") - month = parse_date(month_str) + month = parse_month(month_str) if note_text and month: with get_connection() as conn: with conn.cursor() as cur: diff --git a/templates/edit_future.html b/templates/edit_future.html index b921be5..80c3585 100644 --- a/templates/edit_future.html +++ b/templates/edit_future.html @@ -11,8 +11,8 @@