Refactor case prior handling: update function to support case_number instead of case_id for improved clarity and maintainability

This commit is contained in:
Ross
2025-11-17 11:15:08 +00:00
parent 0f8bae8a14
commit 24558f92ce
2 changed files with 6 additions and 15 deletions
@@ -18,7 +18,7 @@
{% endif %}
{% if casedetail.case.previous_case %}
<a class="btn btn-outline-secondary" href='{% url "atlas:collection_case_priors" casedetail.collection.pk casedetail.case.pk %}' title="Manage priors">
<a class="btn btn-outline-secondary" href='{% url "atlas:collection_case_priors_legacy" casedetail.collection.pk casedetail.case.pk %}' title="Manage priors">
<i class="bi bi-link-45deg"></i>
</a>
{% endif %}
+5 -14
View File
@@ -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