Add solver settings display and configuration options to rota detail view
This commit is contained in:
@@ -216,6 +216,40 @@ def rota_detail(request, rota_id):
|
||||
except Exception:
|
||||
worker_count = None
|
||||
|
||||
# Extract solver settings saved on the rota (if any) for display.
|
||||
try:
|
||||
opts = rota.options or {}
|
||||
solver = opts.get("solver")
|
||||
so = opts.get("solver_options")
|
||||
# Normalize solver_options to a dict when possible and extract ratio
|
||||
solver_options = None
|
||||
solver_ratio = None
|
||||
if isinstance(so, dict):
|
||||
solver_options = so
|
||||
solver_ratio = so.get("ratio")
|
||||
elif isinstance(so, str):
|
||||
try:
|
||||
solver_options = json.loads(so)
|
||||
except Exception:
|
||||
solver_options = so
|
||||
if isinstance(solver_options, dict):
|
||||
solver_ratio = solver_options.get("ratio")
|
||||
# fallback to legacy top-level 'ratio' key
|
||||
if solver_ratio is None:
|
||||
solver_ratio = opts.get("ratio")
|
||||
# Pretty JSON for display when dict
|
||||
try:
|
||||
if isinstance(solver_options, dict):
|
||||
solver_options_pretty = json.dumps(solver_options, indent=2)
|
||||
else:
|
||||
solver_options_pretty = str(solver_options) if solver_options is not None else None
|
||||
except Exception:
|
||||
solver_options_pretty = None
|
||||
except Exception:
|
||||
solver = None
|
||||
solver_options_pretty = None
|
||||
solver_ratio = None
|
||||
|
||||
# legacy RotaOptionsForm not used here; we provide a typed RotaScheduleForm below
|
||||
|
||||
# Provide a typed RotaScheduleForm instance so the template can render
|
||||
@@ -238,6 +272,9 @@ def rota_detail(request, rota_id):
|
||||
"weeks_to_rota": weeks_to_rota,
|
||||
"shift_count": shift_count,
|
||||
"worker_count": worker_count,
|
||||
"solver": solver,
|
||||
"solver_options": solver_options_pretty,
|
||||
"solver_ratio": solver_ratio,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user