.
This commit is contained in:
@@ -18,4 +18,5 @@ urlpatterns = [
|
|||||||
path("run/<int:run_id>/", views.rota_run_detail, name="rota_run_detail"),
|
path("run/<int:run_id>/", views.rota_run_detail, name="rota_run_detail"),
|
||||||
path("run/<int:run_id>/export/html/", views.rota_run_export_html, name="rota_run_export_html"),
|
path("run/<int:run_id>/export/html/", views.rota_run_export_html, name="rota_run_export_html"),
|
||||||
path("run/<int:run_id>/export/download/", views.rota_run_export_download, name="rota_run_export_download"),
|
path("run/<int:run_id>/export/download/", views.rota_run_export_download, name="rota_run_export_download"),
|
||||||
|
path("rota/<int:rota_id>/export/builder/", views.rota_export_builder, name="rota_export_builder"),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -162,6 +162,35 @@ def rota_run_export_download(request, run_id):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def rota_export_builder(request, rota_id):
|
||||||
|
"""Build a `RotaBuilder` for the given `RotaSchedule` and return its HTML export.
|
||||||
|
|
||||||
|
Query parameters:
|
||||||
|
- solve=1 : attempt to solve the model (may require solver binaries and can be slow)
|
||||||
|
- solver=<name> : solver name passed to `build_and_solve`
|
||||||
|
"""
|
||||||
|
rota = get_object_or_404(RotaSchedule, pk=rota_id)
|
||||||
|
|
||||||
|
try:
|
||||||
|
rb = rota.to_rota_builder()
|
||||||
|
except Exception as exc:
|
||||||
|
return HttpResponseBadRequest(f"Unable to construct RotaBuilder: {exc}")
|
||||||
|
|
||||||
|
solve = request.GET.get("solve") == "1"
|
||||||
|
solver = request.GET.get("solver", "appsi_highs")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Build model (and optionally solve) - keep defaults safe
|
||||||
|
rb.build_and_solve(solve=solve, solver=solver)
|
||||||
|
except Exception as exc:
|
||||||
|
# Return error message in the page so it's visible in browser
|
||||||
|
content = f"<html><body><h1>Error running builder</h1><pre>{exc}</pre></body></html>"
|
||||||
|
return HttpResponse(content, status=500, content_type="text/html")
|
||||||
|
|
||||||
|
html = rb.get_worker_timetable_html(include_html_tag=True)
|
||||||
|
return HttpResponse(html, content_type="text/html; charset=utf-8")
|
||||||
|
|
||||||
|
|
||||||
@require_http_methods(["GET", "POST"])
|
@require_http_methods(["GET", "POST"])
|
||||||
def shift_add(request, rota_id):
|
def shift_add(request, rota_id):
|
||||||
"""HTMX endpoint to render a shift form or accept submission to append a shift to the rota."""
|
"""HTMX endpoint to render a shift form or accept submission to append a shift to the rota."""
|
||||||
|
|||||||
Reference in New Issue
Block a user