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
|
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]:
|
def _fetch_notes(user_id: int, note_date: date) -> list[dict]:
|
||||||
with get_connection() as conn:
|
with get_connection() as conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
@@ -123,11 +138,7 @@ def _report_filters() -> dict:
|
|||||||
|
|
||||||
if range_type == "month":
|
if range_type == "month":
|
||||||
month_param = args.get("month", "")
|
month_param = args.get("month", "")
|
||||||
try:
|
start = parse_month(month_param) or date.today().replace(day=1)
|
||||||
y, mo = (int(x) for x in month_param.split("-"))
|
|
||||||
start = date(y, mo, 1)
|
|
||||||
except (ValueError, TypeError):
|
|
||||||
start = date.today().replace(day=1)
|
|
||||||
end = date(start.year, start.month,
|
end = date(start.year, start.month,
|
||||||
calendar.monthrange(start.year, start.month)[1])
|
calendar.monthrange(start.year, start.month)[1])
|
||||||
label = start.strftime("%B %Y")
|
label = start.strftime("%B %Y")
|
||||||
@@ -276,7 +287,7 @@ def future():
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
note_text = request.form.get("note_text", "").strip()
|
note_text = request.form.get("note_text", "").strip()
|
||||||
month_str = request.form.get("month", "")
|
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_type = request.form.get("ref_type", "").strip()
|
||||||
ref_value = request.form.get("ref_value", "").strip()
|
ref_value = request.form.get("ref_value", "").strip()
|
||||||
refs = None
|
refs = None
|
||||||
@@ -604,10 +615,16 @@ def report():
|
|||||||
|
|
||||||
current_week = monday_of_week(today).strftime("%G-W%V")
|
current_week = monday_of_week(today).strftime("%G-W%V")
|
||||||
current_month = today.strftime("%Y-%m")
|
current_month = today.strftime("%Y-%m")
|
||||||
|
current_month_date = today.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
filters["week_value"] = current_week
|
filters["week_value"] = current_week
|
||||||
filters["from_value"] = filters["start"].strftime("%Y-%m-%d") if filters["range_type"] == "custom" else ""
|
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["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(
|
return render_template(
|
||||||
"report.html",
|
"report.html",
|
||||||
@@ -623,7 +640,6 @@ def report():
|
|||||||
export_pdf_url=export_pdf_url,
|
export_pdf_url=export_pdf_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@journal_bp.route("/report/export")
|
@journal_bp.route("/report/export")
|
||||||
@login_required
|
@login_required
|
||||||
def report_export():
|
def report_export():
|
||||||
@@ -765,7 +781,7 @@ def edit_future(entry_id: int):
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
note_text = request.form.get("note_text", "").strip()
|
note_text = request.form.get("note_text", "").strip()
|
||||||
month_str = request.form.get("month", "")
|
month_str = request.form.get("month", "")
|
||||||
month = parse_date(month_str)
|
month = parse_month(month_str)
|
||||||
if note_text and month:
|
if note_text and month:
|
||||||
with get_connection() as conn:
|
with get_connection() as conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
<section class="card">
|
<section class="card">
|
||||||
<form method="post" action="{{ url_for('journal.edit_future', entry_id=entry.id) }}" class="stack">
|
<form method="post" action="{{ url_for('journal.edit_future', entry_id=entry.id) }}" class="stack">
|
||||||
<label>
|
<label>
|
||||||
Monat
|
Monat (Kalender)
|
||||||
<input type="month" name="month" value="{{ entry.month_date.strftime('%Y-%m') }}" required>
|
<input type="date" name="month" value="{{ entry.month_date.strftime('%Y-%m-%d') }}" required>
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Notiz
|
Notiz
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
<form method="post" action="{{ url_for('journal.future') }}" class="note-form">
|
<form method="post" action="{{ url_for('journal.future') }}" class="note-form">
|
||||||
<div class="note-form-row">
|
<div class="note-form-row">
|
||||||
<label>
|
<label>
|
||||||
Monat
|
Monat (Kalender)
|
||||||
<input type="month" name="month" required>
|
<input type="date" name="month" required>
|
||||||
</label>
|
</label>
|
||||||
<label class="grow">
|
<label class="grow">
|
||||||
Notiz
|
Notiz
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
<input type="radio" name="range" value="month"
|
<input type="radio" name="range" value="month"
|
||||||
{{ 'checked' if f.range_type == 'month' else '' }}> Monat
|
{{ 'checked' if f.range_type == 'month' else '' }}> Monat
|
||||||
</label>
|
</label>
|
||||||
<label class="grow"><input type="month" name="month" value="{{ current_month }}"></label>
|
<label class="grow"><input type="date" name="month" value="{{ f.month_value }}"></label>
|
||||||
<label>
|
<label>
|
||||||
<input type="radio" name="range" value="custom"
|
<input type="radio" name="range" value="custom"
|
||||||
{{ 'checked' if f.range_type == 'custom' else '' }}> Zeitraum
|
{{ 'checked' if f.range_type == 'custom' else '' }}> Zeitraum
|
||||||
|
|||||||
Reference in New Issue
Block a user