start user score pages
This commit is contained in:
+3
-3
@@ -91,6 +91,9 @@ class AnatomyQuestion(models.Model):
|
|||||||
null=True,
|
null=True,
|
||||||
blank=True)
|
blank=True)
|
||||||
created_date = models.DateTimeField(default=timezone.now)
|
created_date = models.DateTimeField(default=timezone.now)
|
||||||
|
|
||||||
|
open_access = models.BooleanField(help_text="If an question should be freely available to browse",
|
||||||
|
default=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
# Get first answer
|
# Get first answer
|
||||||
@@ -195,9 +198,6 @@ class Exam(models.Model):
|
|||||||
active = models.BooleanField(help_text="If an exam should be available",
|
active = models.BooleanField(help_text="If an exam should be available",
|
||||||
default=True)
|
default=True)
|
||||||
|
|
||||||
recreate_json = models.BooleanField(help_text="If the json cache needs updating",
|
|
||||||
default=False)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{% extends 'anatomy/exams.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="anatomy">
|
||||||
|
<h2>{{ exam.name }}</h2>
|
||||||
|
<h3>Candidate: {{ user_names|get_item:user }}</h3>
|
||||||
|
<!-- Answers: {{ user_answers_and_marks|get_item:user }}-->
|
||||||
|
Answers: {% for ans, score in answers_and_marks %}
|
||||||
|
{{ans}} ({{score}}),
|
||||||
|
{% endfor %}
|
||||||
|
<br /> Total mark: {{ score }}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -16,6 +16,8 @@ urlpatterns = [
|
|||||||
path("exam/<int:pk>/", views.exam_overview, name="exam_overview"),
|
path("exam/<int:pk>/", views.exam_overview, name="exam_overview"),
|
||||||
path("exam/<int:pk>/scores", views.exam_scores_cid,
|
path("exam/<int:pk>/scores", views.exam_scores_cid,
|
||||||
name="exam_scores_cid"),
|
name="exam_scores_cid"),
|
||||||
|
path("exam/<int:pk>/scores/<int:sk>/", views.exam_scores_cid_user,
|
||||||
|
name="exam_scores_cid_user"),
|
||||||
path("exam/submit", views.postExamAnswers, name="exam_answers_submit"),
|
path("exam/submit", views.postExamAnswers, name="exam_answers_submit"),
|
||||||
path("exam/", views.exam_list, name="exam_list"),
|
path("exam/", views.exam_list, name="exam_list"),
|
||||||
path("exam/json/", views.active_exams, name="active_exams"),
|
path("exam/json/", views.active_exams, name="active_exams"),
|
||||||
|
|||||||
@@ -580,6 +580,56 @@ def exam_scores_cid(request, pk):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def exam_scores_cid_user(request, pk, sk):
|
||||||
|
exam = get_object_or_404(Exam, pk=pk)
|
||||||
|
|
||||||
|
# TODO:Need some kind of test for cid
|
||||||
|
cid = sk
|
||||||
|
|
||||||
|
questions = exam.exam_questions.all()
|
||||||
|
|
||||||
|
answers_and_marks = []
|
||||||
|
answers_marks = []
|
||||||
|
answers = []
|
||||||
|
|
||||||
|
for q in questions:
|
||||||
|
# Get user answer
|
||||||
|
s = q.cid_user_answers.filter(cid=cid)
|
||||||
|
if not s:
|
||||||
|
# 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
|
||||||
|
answers.append(ans)
|
||||||
|
answers_marks.append(a)
|
||||||
|
answers_and_marks.append((ans, a))
|
||||||
|
|
||||||
|
score = sum(answers_marks)
|
||||||
|
|
||||||
|
total = len(questions)
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"anatomy/exam_scores_user.html",
|
||||||
|
{
|
||||||
|
"exam": exam,
|
||||||
|
"cid": cid,
|
||||||
|
"questions": questions,
|
||||||
|
"answers": answers,
|
||||||
|
"answers_marks": answers_marks,
|
||||||
|
"score": score,
|
||||||
|
"answers_and_marks": answers_and_marks,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def exam_scores(request, pk):
|
def exam_scores(request, pk):
|
||||||
|
|||||||
Reference in New Issue
Block a user