Refactor case prior handling: update function to support case_number instead of case_id for improved clarity and maintainability
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if casedetail.case.previous_case %}
|
{% 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>
|
<i class="bi bi-link-45deg"></i>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
+2
-11
@@ -2834,19 +2834,10 @@ def redirect_collection_case_view_take_user_answers_by_id(request, pk, case_id):
|
|||||||
|
|
||||||
|
|
||||||
@user_is_collection_author_or_atlas_editor
|
@user_is_collection_author_or_atlas_editor
|
||||||
def collection_case_priors(request, exam_id, case_id):
|
def collection_case_priors(request, exam_id, case_number):
|
||||||
# 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.
|
|
||||||
try:
|
|
||||||
casedetail = CaseDetail.objects.get(case=case_id, collection=exam_id)
|
|
||||||
collection = casedetail.collection
|
|
||||||
except Exception:
|
|
||||||
collection = get_object_or_404(CaseCollection, pk=exam_id)
|
collection = get_object_or_404(CaseCollection, pk=exam_id)
|
||||||
try:
|
try:
|
||||||
case_obj = collection.get_case_by_index(int(case_id))
|
case_obj = collection.get_case_by_index(case_number)
|
||||||
casedetail = CaseDetail.objects.get(case=case_obj, collection=collection)
|
casedetail = CaseDetail.objects.get(case=case_obj, collection=collection)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise Http404("Case not found in collection")
|
raise Http404("Case not found in collection")
|
||||||
|
|||||||
Reference in New Issue
Block a user