From 24558f92cec1203af4083064efb41b247788c7b1 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 17 Nov 2025 11:15:08 +0000 Subject: [PATCH] Refactor case prior handling: update function to support case_number instead of case_id for improved clarity and maintainability --- .../casedetails_management_links.html | 2 +- atlas/views.py | 19 +++++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/atlas/templates/atlas/partials/casedetails_management_links.html b/atlas/templates/atlas/partials/casedetails_management_links.html index 48776660..2c710e2a 100644 --- a/atlas/templates/atlas/partials/casedetails_management_links.html +++ b/atlas/templates/atlas/partials/casedetails_management_links.html @@ -18,7 +18,7 @@ {% endif %} {% if casedetail.case.previous_case %} - + {% endif %} diff --git a/atlas/views.py b/atlas/views.py index 6d2b0b11..21316d19 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -2834,22 +2834,13 @@ def redirect_collection_case_view_take_user_answers_by_id(request, pk, case_id): @user_is_collection_author_or_atlas_editor -def collection_case_priors(request, exam_id, case_id): - # Support either case_number (index) or case_id (case PK) in the URL/kwargs. - # Backwards compatibility: callers may pass case_id; prefer case_number when present. - casedetail = None - collection = None - # Try treating the parameter as a case PK first, falling back to case index. +def collection_case_priors(request, exam_id, case_number): + collection = get_object_or_404(CaseCollection, pk=exam_id) try: - casedetail = CaseDetail.objects.get(case=case_id, collection=exam_id) - collection = casedetail.collection + case_obj = collection.get_case_by_index(case_number) + casedetail = CaseDetail.objects.get(case=case_obj, collection=collection) except Exception: - collection = get_object_or_404(CaseCollection, pk=exam_id) - try: - case_obj = collection.get_case_by_index(int(case_id)) - casedetail = CaseDetail.objects.get(case=case_obj, collection=collection) - except Exception: - raise Http404("Case not found in collection") + raise Http404("Case not found in collection") if request.htmx: # Ensure we can render the updated single-card partial and return it so HTMX