.
This commit is contained in:
+26
-24
@@ -59,23 +59,24 @@ def rota_detail(request, rota_id):
|
||||
meta = opts_model.__class__.model_fields
|
||||
except Exception:
|
||||
meta = {}
|
||||
for k, v in defaults.items():
|
||||
desc = None
|
||||
if isinstance(meta, dict) and k in meta:
|
||||
info = meta[k]
|
||||
if hasattr(info, "description"):
|
||||
desc = info.description
|
||||
else:
|
||||
try:
|
||||
desc = info.get("description")
|
||||
except Exception:
|
||||
desc = None
|
||||
# include the current value saved on the rota (if any)
|
||||
try:
|
||||
current = (rota.options or {}).get(k, v)
|
||||
except Exception:
|
||||
current = v
|
||||
available_constraints_rich[k] = {"default": v, "description": desc, "current": current}
|
||||
# iterate defaults and build rich info dict
|
||||
for k, v in defaults.items():
|
||||
desc = None
|
||||
if isinstance(meta, dict) and k in meta:
|
||||
info = meta[k]
|
||||
if hasattr(info, "description") and info.description:
|
||||
desc = info.description
|
||||
else:
|
||||
try:
|
||||
desc = info.get("description")
|
||||
except Exception:
|
||||
desc = None
|
||||
# include the current value saved on the rota (if any)
|
||||
try:
|
||||
current = (rota.options or {}).get(k, v)
|
||||
except Exception:
|
||||
current = v
|
||||
available_constraints_rich[k] = {"default": v, "description": desc, "current": current}
|
||||
except Exception:
|
||||
available_constraints_rich = {k: {"default": v} for k, v in available_constraints.items()}
|
||||
|
||||
@@ -349,10 +350,10 @@ def rota_options(request, rota_id):
|
||||
return _oob_update_options_display(request, rota)
|
||||
return redirect(reverse("rota:rota_detail", args=(rota.id,)))
|
||||
|
||||
# Typed form submission
|
||||
from .forms import RotaScheduleForm
|
||||
# Typed form submission for constraint options only
|
||||
from .forms import RotaConstraintOptionsForm
|
||||
|
||||
form = RotaScheduleForm(request.POST, instance=rota)
|
||||
form = RotaConstraintOptionsForm(request.POST, initial_options=rota.options)
|
||||
if not form.is_valid():
|
||||
if is_hx:
|
||||
# Re-render modal with errors
|
||||
@@ -364,14 +365,15 @@ def rota_options(request, rota_id):
|
||||
return HttpResponse(modal_html)
|
||||
return HttpResponseBadRequest("Invalid form submission")
|
||||
|
||||
form.save()
|
||||
# Persist only constraint keys into rota.options
|
||||
form.save_for_rota(rota)
|
||||
if is_hx:
|
||||
return _oob_update_options_display(request, rota)
|
||||
return redirect(reverse("rota:rota_detail", args=(rota.id,)))
|
||||
|
||||
# GET: render modal with typed form populated from the rota instance
|
||||
from .forms import RotaScheduleForm
|
||||
form = RotaScheduleForm(instance=rota)
|
||||
# GET: render modal with typed constraint form populated from the rota instance
|
||||
from .forms import RotaConstraintOptionsForm
|
||||
form = RotaConstraintOptionsForm(initial_options=rota.options)
|
||||
modal_html = render_to_string(
|
||||
"rota/partials/rota_options_modal.html",
|
||||
{"form_action": reverse("rota:rota_options", args=(rota.id,)), "form": form, "rota": rota},
|
||||
|
||||
Reference in New Issue
Block a user