bloombase/plants/views/pruning.py
Stephan Kerkman 370a02e00e feat: pruning calendar grouped by urgency
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-28 10:06:55 +02:00

40 lines
1.3 KiB
Python

from datetime import date
from django.shortcuts import render
from plants.models import Plant
from plants.utils.pruning import pruning_status
def pruning_calendar(request):
today = date.today()
next_month_num = today.month % 12 + 1
next_month_year = today.year + (1 if today.month == 12 else 0)
next_month_date = date(next_month_year, next_month_num, 1)
all_plants = list(
Plant.objects.select_related('species').prefetch_related('pruning_logs')
)
overdue, due_this_month, next_month_plants, later = [], [], [], []
for plant in all_plants:
if not plant.pruning_months:
continue
status = pruning_status(plant, today)
if status == 'overdue':
overdue.append(plant)
elif status == 'due_this_month':
due_this_month.append(plant)
elif next_month_num in plant.pruning_months:
next_month_plants.append(plant)
else:
later.append(plant)
return render(request, 'plants/pruning_calendar.html', {
'overdue': overdue,
'due_this_month': due_this_month,
'next_month_plants': next_month_plants,
'later': later,
'today': today,
'month_name': today.strftime('%B'),
'next_month_name': next_month_date.strftime('%B'),
})