Refactor case navigation: consolidate previous and next links into a reusable partial for improved maintainability and consistency across templates
This commit is contained in:
+23
-5
@@ -2763,6 +2763,7 @@ def collection_case_priors(request, exam_id, case_id):
|
||||
if request.htmx:
|
||||
# Ensure we can render the updated single-card partial and return it so HTMX
|
||||
# can swap the card on the client side.
|
||||
|
||||
if "remove" in request.POST:
|
||||
prior_pk = request.POST["remove"]
|
||||
try:
|
||||
@@ -2792,10 +2793,27 @@ def collection_case_priors(request, exam_id, case_id):
|
||||
return HttpResponse(html)
|
||||
elif "prior_case_id" in request.POST:
|
||||
if not request.POST.get("relation"):
|
||||
return HttpResponse(
|
||||
"You need to enter text to describe the relationship between the cases",
|
||||
status=400,
|
||||
# Return the card partial with an inline error so HTMX will replace
|
||||
# the card and display the validation message rather than navigating
|
||||
# to a new page or showing a plain text response.
|
||||
prior_case = Case.objects.get(pk=request.POST.get("prior_case_id"))
|
||||
added = False
|
||||
relation = request.POST.get("relation", "")
|
||||
visibility = request.POST.get("prior_visibility", "AL")
|
||||
html = render_to_string(
|
||||
"atlas/partials/_prior_card.html",
|
||||
{
|
||||
"case": prior_case,
|
||||
"added": added,
|
||||
"relation": relation,
|
||||
"visibility": visibility,
|
||||
"case_detail": case_detail,
|
||||
"collection": collection,
|
||||
"error": "You need to enter text to describe the relationship between the cases",
|
||||
},
|
||||
request=request,
|
||||
)
|
||||
return HttpResponse(html)
|
||||
prior_case = Case.objects.get(pk=request.POST["prior_case_id"])
|
||||
p, created = CasePrior.objects.get_or_create(
|
||||
case_detail=case_detail, prior_case=prior_case
|
||||
@@ -3576,8 +3594,8 @@ def collection_case_view(request, pk, case_number):
|
||||
|
||||
series_list = case.series.all().prefetch_related("images", "examination", "plane")
|
||||
|
||||
previous = case_number > 0
|
||||
next = case_number < (case_count - 1)
|
||||
previous = collection.get_previous_case(casedetail.case)
|
||||
next = collection.get_next_case(casedetail.case)
|
||||
|
||||
return render(
|
||||
request,
|
||||
|
||||
Reference in New Issue
Block a user