diff --git a/anatomy/views.py b/anatomy/views.py
index 8778bbc9..31353f9d 100644
--- a/anatomy/views.py
+++ b/anatomy/views.py
@@ -238,19 +238,19 @@ def loadJsonAnswer(answer):
if (not isinstance(answer["cid"], int)) or (
not isinstance(eid, int) or (not isinstance(answer["ans"], str))
):
- return JsonResponse({"success": False, "error": "cid or eid or answers not defined"})
+ return False, JsonResponse({"success": False, "error": "cid or eid or answers not defined"})
# The model should catch invalid data but this should be less intensive
max_int = 999999999999999999999
if answer["cid"] > max_int or eid > max_int:
- return JsonResponse({"success": False, "error": "invalid cid"})
+ return False, JsonResponse({"success": False, "error": "invalid cid"})
exam = get_object_or_404(Exam, pk=eid)
- if not exam.active:
- return JsonResponse(
- {"success": False, "error": "No active exam: {}".format(eid)}
- )
+ #if not exam.active:
+ # return False, JsonResponse(
+ # {"success": False, "error": "No active exam: {}".format(eid)}
+ # )
exiting_answers = CidUserAnswer.objects.filter(
question__id=answer["qid"], exam__id=eid, cid=answer["cid"]
@@ -272,7 +272,7 @@ def loadJsonAnswer(answer):
ans.full_clean()
ans.save()
- return True
+ return True, None
#@csrf_exempt
@@ -453,7 +453,7 @@ def exam_scores_cid(request, pk):
questions = exam.exam_questions.all()
cids = (
- CidUserAnswer.objects.filter(question__in=questions)
+ CidUserAnswer.objects.filter(question__in=questions, exam__id=pk)
.order_by("cid")
.values_list("cid", flat=True)
.distinct()
@@ -473,7 +473,7 @@ def exam_scores_cid(request, pk):
user_names[cid] = cid
for q in questions:
# Get user answer
- s = q.cid_user_answers.filter(cid=cid).first()
+ s = q.cid_user_answers.filter(cid=cid, exam__id=pk).first()
if not s:
# skip if no answer
user_answers_marks[cid].append(0)
@@ -564,7 +564,7 @@ def exam_scores_cid_user(request, pk, sk):
for q in questions:
# Get user answer
- user_answer = q.cid_user_answers.filter(cid=cid).first()
+ user_answer = q.cid_user_answers.filter(cid=cid, exam__id=pk).first()
if not user_answer:
# skip if no answer
answers_marks.append(0)
diff --git a/generic/views.py b/generic/views.py
index 3cade000..5df08f93 100644
--- a/generic/views.py
+++ b/generic/views.py
@@ -157,6 +157,10 @@ class ExamViews(View, LoginRequiredMixin):
self.question_type = question_type
self.loadJsonAnswer = loadJsonAnswer
+ # THis may be better than check_user_access below
+ #group_map = {"rapids" : "rapid_checker", "anatomy" : "anatomy_checker", "longs":"long_checker"}
+ #exam_group = group_map[self.app_name]
+
def check_user_access(self, user):
"""Check if a user should be able to access a view
@@ -174,6 +178,8 @@ class ExamViews(View, LoginRequiredMixin):
return False
if self.app_name == "physics" and not user.groups.filter(name='physic_checker').exists():
return False
+ if self.app_name == "sbas" and not user.groups.filter(name='sba_checker').exists():
+ return False
return True
@@ -326,6 +332,7 @@ class ExamViews(View, LoginRequiredMixin):
questions = exam.exam_questions.all()
+ # TODO: fix showing unmarked answer count from other exams...
return render(
request, "{}/mark_overview.html".format(self.app_name), {"exam": exam, "questions": questions}
)
@@ -384,7 +391,7 @@ class ExamViews(View, LoginRequiredMixin):
active_exams = {"exams": []}
for exam in exams:
- if exam.active:
+ if exam.active or self.check_user_access(request.user):
if exam.json_creation_time:
creation_time = exam.json_creation_time.isoformat()
else:
@@ -401,7 +408,8 @@ class ExamViews(View, LoginRequiredMixin):
"type": self.question_type,
"eid": "{}/{}".format(self.question_type, exam.pk),
"json_creation_time": creation_time,
- "exam_json_id": exam.exam_json_id
+ "exam_json_id": exam.exam_json_id,
+ "exam_active": exam.active
}
if self.question_type == "long":
@@ -426,13 +434,15 @@ class ExamViews(View, LoginRequiredMixin):
n = 0
for answer in json.loads(request.POST.get("answers")):
- ret = self.loadJsonAnswer(answer)
+ ret_status, ret = self.loadJsonAnswer(answer)
#if ret is not True:
# return ret
- if ret:
+ if ret_status:
n = n + 1
+ else:
+ return ret
# print(UserAnswer.objects.filter(exam__id=q["eid"]))
# print(request.urlencode())
@@ -446,17 +456,18 @@ class ExamViews(View, LoginRequiredMixin):
"""
exam = get_object_or_404(self.Exam, pk=pk)
- if not exam.active:
+ if not exam.active and not self.check_user_access(request.user):
raise Http404("No available exam")
exam_json = exam.get_exam_json(based=False)
+ #exam_json["exam_active"] = False
return JsonResponse(exam_json)
def exam_json(self, request, pk):
exam = get_object_or_404(self.Exam, pk=pk)
- if not exam.active:
+ if not exam.active and not self.check_user_access(request.user):
raise Http404("No available exam")
@@ -504,7 +515,7 @@ class ExamViews(View, LoginRequiredMixin):
question = get_object_or_404(self.Question, pk=sk)
exam = get_object_or_404(self.Exam, pk=pk)
- if not exam.active:
+ if not exam.active and not self.check_user_access(request.user):
raise Http404("No available exam")
@@ -520,7 +531,7 @@ class ExamViews(View, LoginRequiredMixin):
question = get_object_or_404(self.Question, pk=sk)
exam = get_object_or_404(self.Exam, pk=pk)
- if not exam.active:
+ if not exam.active and not self.check_user_access(request.user):
raise Http404("No available exam")
return redirect("{}:question_json_unbased".format(self.app_name), pk=sk)
diff --git a/longs/templates/longs/exam_overview.html b/longs/templates/longs/exam_overview.html
index 1541ad9b..97239ec9 100644
--- a/longs/templates/longs/exam_overview.html
+++ b/longs/templates/longs/exam_overview.html
@@ -32,9 +32,11 @@
{% for series in question.series.all %}
A radiology resource
+ {% endblock %} \ No newline at end of file