Add rota-builder summary to detail view with weeks, shifts, and workers count
This commit is contained in:
@@ -191,6 +191,31 @@ def rota_detail(request, rota_id):
|
||||
except Exception:
|
||||
configured_constraints = {}
|
||||
|
||||
# Compute a small rota-builder summary for display in the template
|
||||
try:
|
||||
# Prefer explicit value stored in rota.options['weeks'] when present.
|
||||
opts = rota.options or {}
|
||||
if "weeks" in opts:
|
||||
try:
|
||||
weeks_to_rota = max(1, int(opts.get("weeks")))
|
||||
except Exception:
|
||||
weeks_to_rota = None
|
||||
else:
|
||||
delta = rota.end_date - rota.start_date
|
||||
weeks_to_rota = max(1, int(delta.days // 7))
|
||||
except Exception:
|
||||
weeks_to_rota = None
|
||||
|
||||
try:
|
||||
shift_count = len(rota.shifts or [])
|
||||
except Exception:
|
||||
shift_count = None
|
||||
|
||||
try:
|
||||
worker_count = rota.workers.count()
|
||||
except Exception:
|
||||
worker_count = None
|
||||
|
||||
# legacy RotaOptionsForm not used here; we provide a typed RotaScheduleForm below
|
||||
|
||||
# Provide a typed RotaScheduleForm instance so the template can render
|
||||
@@ -205,7 +230,15 @@ def rota_detail(request, rota_id):
|
||||
return render(
|
||||
request,
|
||||
"rota/rota_detail.html",
|
||||
{"rota": rota, "options_form": typed_form, "available_constraints": available_constraints_rich, "configured_constraints": configured_constraints},
|
||||
{
|
||||
"rota": rota,
|
||||
"options_form": typed_form,
|
||||
"available_constraints": available_constraints_rich,
|
||||
"configured_constraints": configured_constraints,
|
||||
"weeks_to_rota": weeks_to_rota,
|
||||
"shift_count": shift_count,
|
||||
"worker_count": worker_count,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user