numerous improvements
This commit is contained in:
+54
-34
@@ -436,6 +436,18 @@ def mark(request, pk, sk):
|
||||
},
|
||||
)
|
||||
|
||||
def exam_toggle_active(request, pk):
|
||||
if request.is_ajax() and request.method=='POST':
|
||||
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
exam.active = True if request.POST.get('active') == 'true' else False
|
||||
exam.save()
|
||||
data = {'status':'success', 'active':exam.active}
|
||||
return JsonResponse(data, status=200)
|
||||
else:
|
||||
data = {'status':'error'}
|
||||
return JsonResponse(data, status=400)
|
||||
|
||||
def active_exams(request):
|
||||
exams = Exam.objects.all()
|
||||
@@ -602,24 +614,21 @@ def exam_scores_cid_user(request, pk, sk):
|
||||
|
||||
for q in questions:
|
||||
# Get user answer
|
||||
s = q.cid_user_answers.filter(cid=cid)
|
||||
if not s:
|
||||
user_answer = q.cid_user_answers.filter(cid=cid).first()
|
||||
if not user_answer:
|
||||
# skip if no answer
|
||||
answers_marks.append(0)
|
||||
answers.append("")
|
||||
continue
|
||||
|
||||
ans = s[0].answer
|
||||
if q.answers.filter(answer__iexact=ans, status=Answer.MarkOptions.CORRECT).first() is not None:
|
||||
a = 2
|
||||
elif q.answers.filter(answer__iexact=ans, status=Answer.MarkOptions.HALF_MARK).first() is not None:
|
||||
a = 1
|
||||
else:
|
||||
a = 0
|
||||
ans = user_answer.answer
|
||||
|
||||
answer_score = user_answer.get_answer_score()
|
||||
|
||||
correct_answer = q.GetPrimaryAnswer()
|
||||
answers.append(ans)
|
||||
answers_marks.append(a)
|
||||
answers_and_marks.append((ans, a, correct_answer))
|
||||
answers_marks.append(answer_score)
|
||||
answers_and_marks.append((ans, answer_score, correct_answer))
|
||||
|
||||
total_score = sum(answers_marks)
|
||||
|
||||
@@ -658,39 +667,22 @@ def exam_scores(request, pk):
|
||||
# Convoluted (probably...)
|
||||
user_names[u] = User.objects.filter(pk=u[0]).first().get_username()
|
||||
for q in questions:
|
||||
s = q.user_answers.filter(user__in=u)
|
||||
if not s:
|
||||
user_answer = q.user_answers.filter(user__in=u).first()
|
||||
if not user_answer:
|
||||
user_answers_marks[u].append(0)
|
||||
user_answers[u].append("")
|
||||
continue
|
||||
|
||||
ans = s[0].answer
|
||||
if ans in q.answers.all().values_list("answer", flat=True):
|
||||
a = 2
|
||||
elif ans in q.half_mark_answers.all().values_list("answer",
|
||||
flat=True):
|
||||
a = 1
|
||||
else:
|
||||
a = 0
|
||||
ans = user_answer.answer
|
||||
answer_score = user_answer.get_answer_score()
|
||||
user_answers[u].append(ans)
|
||||
user_answers_marks[u].append(a)
|
||||
user_answers_and_marks[u].append((ans, a))
|
||||
user_answers_marks[u].append(answer_score)
|
||||
user_answers_and_marks[u].append((ans, answer_score))
|
||||
|
||||
user_scores = {}
|
||||
for user in user_answers_marks:
|
||||
user_scores[user] = sum(user_answers_marks[user])
|
||||
|
||||
# Users with answers
|
||||
#
|
||||
# for q in questions:
|
||||
# answers = q.user_answers.all()
|
||||
#
|
||||
# for ans in answers:
|
||||
# user = ans.user
|
||||
# if ans.answer in q.answers.all().values_list("answer", flat=True):
|
||||
# user_answers[user].append(2)
|
||||
#
|
||||
|
||||
total = len(questions)
|
||||
|
||||
return render(
|
||||
@@ -706,3 +698,31 @@ def exam_scores(request, pk):
|
||||
"user_answers_and_marks": user_answers_and_marks,
|
||||
},
|
||||
)
|
||||
|
||||
def cid_scores(request, pk):
|
||||
#exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
# TODO:Need some kind of test for cid
|
||||
cid = pk
|
||||
|
||||
#questions = exam.exam_questions.all()
|
||||
answers = CidUserAnswer.objects.filter(
|
||||
cid=cid)
|
||||
|
||||
|
||||
if not answers:
|
||||
return Http404("cid not found")
|
||||
|
||||
exam_ids = answers.values_list("exam").distinct()
|
||||
|
||||
exams = Exam.objects.filter(id__in=exam_ids)
|
||||
|
||||
|
||||
return render(
|
||||
request,
|
||||
"anatomy/cid_scores.html",
|
||||
{
|
||||
"exams": exams,
|
||||
"cid": cid,
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user