bloombase/plants/views/dashboard.py
Stephan Kerkman 18e128549d feat: dashboard with plant count and pruning summary
Adds the dashboard view, template, URL routing, and tests. Also upgrades
Django from 5.1.15 to 5.2.1 to fix a Python 3.14 incompatibility in
template context copy that prevented view tests from running.
2026-05-28 09:56:24 +02:00

25 lines
760 B
Python

from datetime import date
from django.shortcuts import render
from plants.models import Plant
from plants.utils.pruning import pruning_status
def dashboard(request):
today = date.today()
all_plants = list(
Plant.objects.select_related('species').prefetch_related('pruning_logs')
)
overdue, due_this_month = [], []
for plant in all_plants:
status = pruning_status(plant, today)
if status == 'overdue':
overdue.append(plant)
elif status == 'due_this_month':
due_this_month.append(plant)
return render(request, 'plants/dashboard.html', {
'total_plants': len(all_plants),
'overdue': overdue,
'due_this_month': due_this_month,
'today': today,
})