Refactor collection_case_details: simplify case retrieval logic and improve parameter naming for clarity
This commit is contained in:
+5
-11
@@ -3094,20 +3094,14 @@ def collection_case_questions(request, exam_id, case_id):
|
||||
)
|
||||
|
||||
@user_is_collection_author_or_atlas_editor
|
||||
def collection_case_details(request, exam_id, case_id):
|
||||
def collection_case_details(request, exam_id, case_number):
|
||||
# Accept either case_number (index into collection) or case_id (case PK).
|
||||
casedetail = None
|
||||
collection = None
|
||||
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(int(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.method == "POST":
|
||||
form = CaseDetailForm(request.POST, instance=casedetail)
|
||||
|
||||
Reference in New Issue
Block a user