Refactor series cases handling: extract cases list to a partial and enhance HTMX integration for dynamic updates

This commit is contained in:
Ross
2025-11-14 21:55:28 +00:00
parent 8096a36a11
commit 835d0382ba
3 changed files with 52 additions and 38 deletions
+12 -2
View File
@@ -4295,6 +4295,11 @@ def add_series_to_case(request, series_pk):
# Associate the series with the case
series.case.add(case)
# If this is an HTMX request, return the updated cases list partial so the
# client can replace the #cases-list innerHTML. Otherwise return a simple message.
if request.headers.get("Hx-Request") or request.META.get("HTTP_HX_REQUEST"):
return render(request, 'atlas/partials/series_cases_list.html', {'series': series, 'can_edit': case.check_user_can_edit(request.user)})
return HttpResponse(f"Series {series_pk} added to case {case.title} ({case_id}).")
return HttpResponse("Invalid request.")
@@ -4307,10 +4312,15 @@ def remove_series_from_case(request, series_pk, case_pk):
series = get_object_or_404(Series, pk=series_pk)
# Associate the series with the case
# Remove the association
series.case.remove(case)
return HttpResponse(f"Removed")
# If this is an HTMX request, return the updated cases list partial so the
# client can replace the #cases-list innerHTML. Otherwise return a simple message.
if request.headers.get("Hx-Request") or request.META.get("HTTP_HX_REQUEST"):
return render(request, 'atlas/partials/series_cases_list.html', {'series': series, 'can_edit': case.check_user_can_edit(request.user)})
return HttpResponse("Removed")
return HttpResponse("Invalid request.")
@login_required