This commit is contained in:
Ross
2025-12-09 12:16:59 +00:00
parent c63d4d1585
commit e6943ccfc7
5 changed files with 76 additions and 4 deletions
+19 -1
View File
@@ -8,6 +8,7 @@ from .forms import ShiftForm
from django.views.decorators.http import require_http_methods
from django.template.loader import render_to_string
from django.http import HttpResponse, HttpResponseBadRequest
from django.views.decorators.http import require_POST
def index(request):
@@ -19,7 +20,9 @@ def rota_detail(request, rota_id):
rota = get_object_or_404(RotaSchedule, pk=rota_id)
if request.method == "POST":
# trigger a background run
run = run_rota_async(rota.id)
generate_builder = request.POST.get("generate_builder") == "1"
builder_solve = request.POST.get("builder_solve") == "1"
run = run_rota_async(rota.id, generate_builder=generate_builder, builder_solve=builder_solve)
return redirect(reverse("rota:rota_run_detail", args=(run.id,)))
return render(request, "rota/rota_detail.html", {"rota": rota})
@@ -253,6 +256,21 @@ def rota_export_builder(request, rota_id):
return HttpResponse(html, content_type="text/html; charset=utf-8")
@require_POST
def rota_runs_clear(request, rota_id):
"""Delete all RotaRun records for the given rota and redirect back.
This is a POST-only endpoint; the template uses an inline form with a
JavaScript confirmation to avoid accidental removal.
"""
rota = get_object_or_404(RotaSchedule, pk=rota_id)
# Delete all runs for this rota
from .models import RotaRun
RotaRun.objects.filter(rota=rota).delete()
return redirect("rota:rota_detail", rota_id=rota.id)
@require_http_methods(["GET", "POST"])
def shift_add(request, rota_id):
"""HTMX endpoint to render a shift form or accept submission to append a shift to the rota."""