Files
Andros Fenollosa 051a69cf7d Add Month end section with weekly breakdown and self-assessment
- Weekly expenses table (Week #1-5 + Total)
- Budget result: initial budget - expenses = savings
- Category breakdown by week
- Self-assessment: goals, promises, savings (radio Yes/No/Almost)
- Reflection textarea with auto-save
- Assessment auto-saves on change via LiveView
2026-03-18 15:23:03 +01:00

49 lines
1.1 KiB
Python

from liveview import liveview_handler, send
from app.monthly.models import MonthlyNote
@liveview_handler("save_reflection")
def save_reflection(consumer, content):
form = content.get("form", {})
year = int(form.get("year", 0))
month = int(form.get("month", 0))
reflection = form.get("reflection", "")
if not year or not month:
return
note, _ = MonthlyNote.objects.get_or_create(year=year, month=month)
note.reflection = reflection
note.save()
send(
consumer,
{
"target": "#reflection-status",
"html": '<span class="text-success text-sm">Saved</span>',
},
)
@liveview_handler("save_assessment")
def save_assessment(consumer, content):
form = content.get("form", {})
year = int(form.get("year", 0))
month = int(form.get("month", 0))
field = form.get("assessment_field", "")
value = form.get("assessment_value", "")
if not year or not month or not field:
return
if field not in ("goals_achieved", "promises_kept", "savings_kept"):
return
if value not in ("yes", "no", "almost", ""):
return
note, _ = MonthlyNote.objects.get_or_create(year=year, month=month)
setattr(note, field, value)
note.save()