diff --git a/anatomy/views.py b/anatomy/views.py index 902db09f..7c3be34e 100644 --- a/anatomy/views.py +++ b/anatomy/views.py @@ -95,9 +95,43 @@ class AuthorOrCheckerRequiredMixin(object): @register.filter def get_item(dictionary, key, default=None): + """Safe template filter to fetch an item by key/index from various containers. + + Supports dict-like objects (uses .get), lists/tuples (indexing by integer + keys), and other indexable objects. Returns ``default`` when the lookup + fails or the input is None. + """ if dictionary is None: return default - return dictionary.get(key) + + # If it's dict-like, prefer .get + try: + if hasattr(dictionary, "get") and callable(getattr(dictionary, "get")): + # Allow .get default behaviour + try: + return dictionary.get(key, default) + except Exception: + # Fall through to other strategies + pass + + # If it's a list/tuple and key is integer-like, return by index + if isinstance(dictionary, (list, tuple)): + try: + idx = int(key) + except Exception: + return default + try: + return dictionary[idx] + except Exception: + return default + + # Generic attempt: try __getitem__ with key (handles QueryDict, lists with int keys, etc.) + try: + return dictionary[key] + except Exception: + return default + except Exception: + return default def user_is_admin(user): diff --git a/physics/templates/physics/partials/exam_review_question_fragment.html b/physics/templates/physics/partials/exam_review_question_fragment.html index 6b74b338..3a7f0503 100644 --- a/physics/templates/physics/partials/exam_review_question_fragment.html +++ b/physics/templates/physics/partials/exam_review_question_fragment.html @@ -1,3 +1,101 @@ +
{{ question|safe }}
+ ++ View full question details +
+ +