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
|
@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).
|
# Accept either case_number (index into collection) or case_id (case PK).
|
||||||
casedetail = None
|
collection = get_object_or_404(CaseCollection, pk=exam_id)
|
||||||
collection = None
|
|
||||||
try:
|
try:
|
||||||
casedetail = CaseDetail.objects.get(case=case_id, collection=exam_id)
|
case_obj = collection.get_case_by_index(int(case_number))
|
||||||
collection = casedetail.collection
|
casedetail = CaseDetail.objects.get(case=case_obj, collection=collection)
|
||||||
except Exception:
|
except Exception:
|
||||||
collection = get_object_or_404(CaseCollection, pk=exam_id)
|
raise Http404("Case not found in collection")
|
||||||
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")
|
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = CaseDetailForm(request.POST, instance=casedetail)
|
form = CaseDetailForm(request.POST, instance=casedetail)
|
||||||
|
|||||||
Reference in New Issue
Block a user