many improvement
This commit is contained in:
+18
-8
@@ -6,6 +6,8 @@ from django import forms
|
||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from django.db.models.functions import Lower
|
||||
|
||||
from django.http import Http404, JsonResponse
|
||||
|
||||
from .forms import AnatomyAnswerForm, MarkAnatomyQuestionForm
|
||||
@@ -136,6 +138,11 @@ def exam_overview(request, pk):
|
||||
|
||||
@login_required
|
||||
def exam_take(request, pk, sk):
|
||||
"""
|
||||
Allows taking of the exam on the django server (when logged in)
|
||||
|
||||
No longer used (deprecated in favour of using RTS)
|
||||
"""
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
@@ -298,11 +305,11 @@ def mark(request, pk, sk):
|
||||
except IndexError:
|
||||
raise Http404("Exam question does not exist")
|
||||
|
||||
correct_answers = [i.answer for i in question.answers.all()]
|
||||
half_correct_answers = [i.answer for i in question.half_mark_answers.all()]
|
||||
incorrect_answers = [i.answer for i in question.incorrect_answers.all()]
|
||||
correct_answers = [i.answer.lower() for i in question.answers.all()]
|
||||
half_correct_answers = [i.answer.lower() for i in question.half_mark_answers.all()]
|
||||
incorrect_answers = [i.answer.lower() for i in question.incorrect_answers.all()]
|
||||
|
||||
user_answers = (set([i.answer for i in question.user_answers.all()]) -
|
||||
user_answers = (set([i.answer.lower() for i in question.cid_user_answers.all()]) -
|
||||
set(correct_answers) - set(half_correct_answers) -
|
||||
set(incorrect_answers)) # .filter(user=User)
|
||||
user_answers = set([i for i in user_answers if i.strip() != ""])
|
||||
@@ -402,7 +409,7 @@ def exam_json(request, pk):
|
||||
|
||||
for q in questions:
|
||||
exam_questions[q.id] = {
|
||||
"title": "{}".format(q.examination),
|
||||
"title": "{}".format(q.description),
|
||||
"question": str(q.question_type),
|
||||
"images": [image_as_base64(q.image)],
|
||||
"type": "anatomy",
|
||||
@@ -432,20 +439,23 @@ def exam_scores_cid(request, pk):
|
||||
user_answers = defaultdict(list)
|
||||
user_names = {}
|
||||
|
||||
# Loop through all candidates
|
||||
for cid in cids:
|
||||
# Convoluted (probably...)
|
||||
user_names[cid] = cid
|
||||
for q in questions:
|
||||
s = q.user_answers.filter(cid=cid)
|
||||
# Get user answer
|
||||
s = q.cid_user_answers.filter(cid=cid)
|
||||
if not s:
|
||||
# skip if no answer
|
||||
user_answers_marks[cid].append(0)
|
||||
user_answers[cid].append("")
|
||||
continue
|
||||
|
||||
ans = s[0].answer
|
||||
if ans in q.answers.all().values_list("answer", flat=True):
|
||||
if ans.lower() in q.answers.all().values_list(Lower("answer"), flat=True):
|
||||
a = 2
|
||||
elif ans in q.half_mark_answers.all().values_list("answer",
|
||||
elif ans.lower() in q.half_mark_answers.all().values_list(Lower("answer"),
|
||||
flat=True):
|
||||
a = 1
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user