modified: routes/journal_routes.py
modified: templates/edit_future.html modified: templates/future.html modified: templates/report.html
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user