feat: add daily + global notes

This commit is contained in:
2026-07-17 14:43:05 +02:00
parent d2270a737b
commit 0cfe4c7108
7 changed files with 349 additions and 3 deletions
+18 -1
View File
@@ -10,7 +10,7 @@ from django.utils import timezone
from django.utils.dateparse import parse_date
from tracker.api import build_day, pulse_trend
from tracker.models import DoseLog, PulseReading, ScheduledDose
from tracker.models import DailyNote, DoseLog, GlobalNote, PulseReading, ScheduledDose
CHART_WIDTH = 320
CHART_HEIGHT = 140
@@ -62,6 +62,16 @@ def today(request):
if request.method == "POST":
day = parse_date(request.POST.get("date", "")) or timezone.localdate()
# The shared note has its own form and save button, so that editing it
# while looking at a past day cannot touch that day's records.
if "global_note" in request.POST:
note = GlobalNote.load()
note.body = request.POST["global_note"].strip()
note.save(update_fields=["body", "updated_at"])
messages.success(request, "Shared note saved.")
return redirect(f"{reverse('tracker:today')}?date={day.isoformat()}")
doses = ScheduledDose.objects.filter(is_active=True, medication__is_active=True)
for dose in doses:
@@ -84,6 +94,12 @@ def today(request):
# Clearing the field removes the reading for that day.
PulseReading.objects.filter(date=day).delete()
note_body = (request.POST.get("note") or "").strip()
if note_body:
DailyNote.objects.update_or_create(date=day, defaults={"body": note_body})
else:
DailyNote.objects.filter(date=day).delete()
messages.success(request, f"Saved for {day:%A %d %B}.")
return redirect(f"{reverse('tracker:today')}?date={day.isoformat()}")
@@ -104,6 +120,7 @@ def today(request):
"next_date": day + timedelta(days=1),
"chart": build_chart(readings),
"reading_count": len(readings),
"global_note": GlobalNote.load(),
# Empty when push is not configured; the card then says so rather than
# vanishing, because a missing card looks like a bug in the page.
"vapid_public_key": settings.VAPID_PUBLIC_KEY,