From 7f4570417ee5f738f4e5e6754ea3b2b4311ac540 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 17 Nov 2025 10:09:00 +0000 Subject: [PATCH] Refactor case navigation: consolidate previous and next links into a reusable partial for improved maintainability and consistency across templates --- .../atlas/collection_case_details.html | 10 +------ .../atlas/collection_case_priors.html | 25 ++++------------- .../atlas/collection_case_questions.html | 12 +------- .../templates/atlas/partials/_prior_card.html | 3 ++ .../_viewing_case_as_part_of_collection.html | 24 ++++++++++++++++ .../atlas/partials/case_list_item.html | 2 +- .../templates/atlas/question_link_header.html | 22 +++------------ atlas/views.py | 28 +++++++++++++++---- 8 files changed, 62 insertions(+), 64 deletions(-) create mode 100644 atlas/templates/atlas/partials/_viewing_case_as_part_of_collection.html diff --git a/atlas/templates/atlas/collection_case_details.html b/atlas/templates/atlas/collection_case_details.html index 31f76d7c..d284bb08 100644 --- a/atlas/templates/atlas/collection_case_details.html +++ b/atlas/templates/atlas/collection_case_details.html @@ -3,15 +3,7 @@ {% block content %} -
- {% if previous %} - Previous question - {% endif %} - Viewing question as part of collection: {{collection.name}} [{{case_number|add:1}}/{{collection_length}}] - {% if next %} - Next question - {% endif %} -
+ {% include 'atlas/partials/_viewing_case_as_part_of_collection.html' %}

Case: {{case_detail.case.title}}

diff --git a/atlas/templates/atlas/collection_case_priors.html b/atlas/templates/atlas/collection_case_priors.html index e75a2fcd..bf80c144 100644 --- a/atlas/templates/atlas/collection_case_priors.html +++ b/atlas/templates/atlas/collection_case_priors.html @@ -4,26 +4,7 @@ {% block content %} -
-
- {% if previous %} - ← Previous - {% endif %} -
-
-
Viewing question in collection
-
- {{collection.name}} - [{{case_number|add:1}}/{{collection_length}}] -
-
-
- {% if next %} - Next → - {% endif %} -
-
- + {% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with casedetail=case_detail %}

Case: {{case_detail.case.title}}

@@ -39,6 +20,10 @@
{% for case, added, relation, visibility in available_priors %} {% include 'atlas/partials/_prior_card.html' with case=case added=added relation=relation visibility=visibility case_detail=case_detail collection=collection %} + {% empty %} +
+
No available prior cases found for the case.
+
{% endfor %}
diff --git a/atlas/templates/atlas/collection_case_questions.html b/atlas/templates/atlas/collection_case_questions.html index 587348f2..26fdb5ba 100644 --- a/atlas/templates/atlas/collection_case_questions.html +++ b/atlas/templates/atlas/collection_case_questions.html @@ -4,17 +4,7 @@ {% block content %} -
- - {% if previous %} - Previous question - {% endif %} - Viewing question as part of collection: {{collection.name}} [{{case_number|add:1}}/{{collection_length}}] - {% if next %} - Next question - {% endif %} -
- + {% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with casedetail=case_detail %}

Case: {{case_detail.case.title}}

diff --git a/atlas/templates/atlas/partials/_prior_card.html b/atlas/templates/atlas/partials/_prior_card.html index f013a78b..07ad628a 100644 --- a/atlas/templates/atlas/partials/_prior_card.html +++ b/atlas/templates/atlas/partials/_prior_card.html @@ -1,6 +1,9 @@
+ {% if error %} +
{{ error }}
+ {% endif %}
{{case.title}}
diff --git a/atlas/templates/atlas/partials/_viewing_case_as_part_of_collection.html b/atlas/templates/atlas/partials/_viewing_case_as_part_of_collection.html new file mode 100644 index 00000000..eaecffc7 --- /dev/null +++ b/atlas/templates/atlas/partials/_viewing_case_as_part_of_collection.html @@ -0,0 +1,24 @@ + +
+
+ {% if previous %} + ← Previous + {% endif %} +
+
+
Viewing as part of a collection
+
+ {{collection.name}} + [{{case_number|add:1}}/{{collection_length}}] +
+
+
+ {% if next %} + Next → + {% endif %} +
+ +
+ {% include "atlas/collection_detail.html#casedetails-management-links" %} +
+
\ No newline at end of file diff --git a/atlas/templates/atlas/partials/case_list_item.html b/atlas/templates/atlas/partials/case_list_item.html index d75b1aae..98ef38a6 100644 --- a/atlas/templates/atlas/partials/case_list_item.html +++ b/atlas/templates/atlas/partials/case_list_item.html @@ -14,7 +14,7 @@
{% if casedetail.case.series.count == 0 %} - No series attached + This case has no series / stacks attached {% else %} {{ casedetail.case.series.count }} series {% endif %} diff --git a/atlas/templates/atlas/question_link_header.html b/atlas/templates/atlas/question_link_header.html index 246b44c3..38601583 100644 --- a/atlas/templates/atlas/question_link_header.html +++ b/atlas/templates/atlas/question_link_header.html @@ -18,22 +18,8 @@
- {% if collection %} -
-
Collection
-
- {% include "atlas/collection_detail.html#casedetails-management-links" %} -
-
- {% if previous %} - Previous - {% endif %} - Viewing question as part of a collection: {{ collection.name }} - [{{ case_number|add:1 }} / {{ collection_length }}] - {% if next %} - Next - {% endif %} -
-
- {% endif %}
+ + {% if collection %} + {% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with nav_link_view="atlas:collection_case_view" %} + {% endif %} \ No newline at end of file diff --git a/atlas/views.py b/atlas/views.py index 776da8a3..91cf4961 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -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,