This commit is contained in:
Ross
2021-12-12 12:40:15 +00:00
parent 90a2ef78d9
commit 1ecd71d799
14 changed files with 320 additions and 289 deletions
+50 -50
View File
@@ -1,62 +1,62 @@
{% extends 'anatomy/base.html' %} {% extends 'anatomy/base.html' %}
{% block content %} {% block content %}
<div class="question-display-block"> <div class="question-display-block">
<div class="hide-show">HIDE/SHOW</div> <div class="hide-show">HIDE/SHOW</div>
<div class="inner-display-block"> <div class="inner-display-block">
Question <span class="question-number">No question loaded</span><br/> Question <span class="question-number">No question loaded</span><br />
<span id="question-title"></span><br/> <span id="question-title"></span><br />
<span id="question-question"></span> <span id="question-question"></span>
<div id="single-dicom-viewer" class="dicom-viewer" data-images="" data-annotations=''> <div id="single-dicom-viewer" class="dicom-viewer" data-images="" data-annotations=''>
</div>
<div class="answers">Answers: </div>
</div> </div>
<div class="answers">Answers: </div>
</div> </div>
<div class="anatomy"> </div>
<h2>Exam: {{ exam.name }}</h2> <div class="anatomy">
<h3>Candidate: {{ cid }}</h3> <h2>Exam: {{ exam.name }}</h2>
Answers: <h3>Candidate: {{ cid }}</h3>
<ul class="score-answer-list">{% for ans, score, correct_answer in answers_and_marks %} Answers:
<li class="user-answer-li">Question {{forloop.counter}} - Correct answer: <span <ul class="score-answer-list">{% for ans, score, correct_answer in answers_and_marks %}
class="correct-answer">{{ correct_answer }}</span></li> <li class="user-answer-li">Question {{forloop.counter}} - Correct answer: <span class="correct-answer">{{
<span class="user-answer-score user-answer-score-{{score}} physics-ans"> correct_answer }}</span></li>
<pre>{{ans}}</pre> ({{score}}) <span class="user-answer-score user-answer-score-{{score}} physics-ans">
</span> <pre>{{ans}}</pre> ({{score}})
<span class="view-question-link" data-qn={{forloop.counter0}}>View</span> </span>
<span class="view-question-link" data-qn={{forloop.counter0}}>View</span>
{% endfor %} {% endfor %}
</ul> </ul>
<br /> Total mark: {{ total_score }} / {{max_score}} <br /> Total mark: {{ total_score }} / {{max_score}}
<div> <div>
<a href="{% url 'cid_scores' cid %}">Other exams</a> <a href="{% url 'cid_scores' cid passcode %}">Other exams</a>
</div>
</div> </div>
</div>
{% endblock %} {% endblock %}
{% block js %} {% block js %}
<script> <script>
$(document).ready(function () { $(document).ready(function () {
$(".hide-show").click((evt, el) => { $(".hide-show").click((evt, el) => {
$(".inner-display-block").toggle(); $(".inner-display-block").toggle();
}) })
$(".view-question-link").on("click", function (e) { $(".view-question-link").on("click", function (e) {
console.log("click", e) console.log("click", e)
question_number = e.currentTarget.dataset.qn; question_number = e.currentTarget.dataset.qn;
$("#single-dicom-viewer").empty(); $("#single-dicom-viewer").empty();
$.ajax({ $.ajax({
url: `{% url 'anatomy:question_review' pk=exam.pk %}`, url: `{% url 'anatomy:question_review' pk=exam.pk %}`,
data: { data: {
csrfmiddlewaretoken: "{{ csrf_token }}", csrfmiddlewaretoken: "{{ csrf_token }}",
question_number: question_number question_number: question_number
}, },
type: "POST", type: "POST",
dataType: "json", dataType: "json",
}) })
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) { .done(function (data) {
console.log(data); console.log(data);
let event = new CustomEvent('loadDicomViewerUrls', { let event = new CustomEvent('loadDicomViewerUrls', {
"detail": {"images" : data.images, "annotations" : data.annotations} "detail": { "images": data.images, "annotations": data.annotations }
}); });
window.dispatchEvent(event); window.dispatchEvent(event);
@@ -67,13 +67,13 @@
$(".question-display-block .question-number").empty().append(n); $(".question-display-block .question-number").empty().append(n);
$(".inner-display-block").show(); $(".inner-display-block").show();
}) })
.always(function () { .always(function () {
console.log('[Done]'); console.log('[Done]');
}) })
}) })
$(".view-question-link").first().click(); $(".view-question-link").first().click();
}); });
</script> </script>
{% endblock %} {% endblock %}
+1 -1
View File
@@ -76,7 +76,7 @@ urlpatterns = [
name="exam_scores_cid", name="exam_scores_cid",
), ),
path( path(
"exam/<int:pk>/scores/<int:sk>/", "exam/<int:pk>/scores/<int:sk>/<str:passcode>/",
views.exam_scores_cid_user, views.exam_scores_cid_user,
name="exam_scores_cid_user", name="exam_scores_cid_user",
), ),
+93 -91
View File
@@ -134,89 +134,89 @@ def answer_question(request, pk):
) )
@login_required #@login_required
def exam_take(request, pk, sk): #def exam_take(request, pk, sk):
""" # """
Allows taking of the exam on the django server (when logged in) # Allows taking of the exam on the django server (when logged in)
#
No longer used (deprecated in favour of using RTS) # No longer used (deprecated in favour of using RTS)
""" # """
exam = get_object_or_404(Exam, pk=pk) # exam = get_object_or_404(Exam, pk=pk)
#
questions = exam.exam_questions.all() # questions = exam.exam_questions.all()
#
try: # try:
question = questions[sk] # question = questions[sk]
except IndexError: # except IndexError:
raise Http404("Exam question does not exist") # raise Http404("Exam question does not exist")
#
n = sk # n = sk
#
question_details = { # question_details = {
"total": len(questions), # "total": len(questions),
"current": n + 1, # "current": n + 1,
} # }
#
# Get data for flagged # # Get data for flagged
# answered_questions = UserAnswer.objects.filter(user=request.user).values_list("question__pk", flat=True) # # answered_questions = UserAnswer.objects.filter(user=request.user).values_list("question__pk", flat=True)
user_answer_data = UserAnswer.objects.filter(user=request.user).values_list( # user_answer_data = UserAnswer.objects.filter(user=request.user).values_list(
"question__pk", "answer", "flagged" # "question__pk", "answer", "flagged"
) # )
# flagged_questions = UserAnswer.objects.filter(user=request.user, flagged=True).values_list("question__pk", flat=True) # # flagged_questions = UserAnswer.objects.filter(user=request.user, flagged=True).values_list("question__pk", flat=True)
# flagged_questions I= UserAnswer.filter(user=request.user, ).values_list("question__pk", flat=True) # # flagged_questions I= UserAnswer.filter(user=request.user, ).values_list("question__pk", flat=True)
#
answered_questions = set() # answered_questions = set()
flagged_questions = set() # flagged_questions = set()
for ans_pk, answer, flagged in user_answer_data: # for ans_pk, answer, flagged in user_answer_data:
if len(answer.strip()) > 0: # if len(answer.strip()) > 0:
answered_questions.add(ans_pk) # answered_questions.add(ans_pk)
if flagged: # if flagged:
flagged_questions.add(ans_pk) # flagged_questions.add(ans_pk)
#
# u = question.user_answers # # u = question.user_answers
answer = question.user_answers.filter( # answer = question.user_answers.filter(
user=request.user # user=request.user
).first() # .filter(user=User) # ).first() # .filter(user=User)
if request.method == "POST": # if request.method == "POST":
if answer: # if answer:
form = AnatomyAnswerForm(request.POST, instance=answer) # form = AnatomyAnswerForm(request.POST, instance=answer)
else: # else:
form = AnatomyAnswerForm(request.POST) # form = AnatomyAnswerForm(request.POST)
if form.is_valid(): # if form.is_valid():
answer = form.save(commit=False) # answer = form.save(commit=False)
answer.user = request.user # answer.user = request.user
answer.question = question # answer.question = question
# answer.published_date = timezone.now() # # answer.published_date = timezone.now()
answer.save() # answer.save()
if "next" in request.POST: # if "next" in request.POST:
return redirect("anatomy:exam_take", pk=pk, sk=n + 1) # return redirect("anatomy:exam_take", pk=pk, sk=n + 1)
elif "previous" in request.POST: # elif "previous" in request.POST:
return redirect("anatomy:exam_take", pk=pk, sk=n - 1) # return redirect("anatomy:exam_take", pk=pk, sk=n - 1)
else: # else:
form = AnatomyAnswerForm(instance=answer) # form = AnatomyAnswerForm(instance=answer)
return render( # return render(
request, # request,
"anatomy/exam.html", # "anatomy/exam.html",
{ # {
"exam": exam, # "exam": exam,
"form": form, # "form": form,
"question": question, # "question": question,
"question_details": question_details, # "question_details": question_details,
"questions": questions, # "questions": questions,
"flagged_questions": flagged_questions, # "flagged_questions": flagged_questions,
"answered_questions": answered_questions, # "answered_questions": answered_questions,
"answer": answer, # "answer": answer,
}, # },
) # )
def flag_question(request): #def flag_question(request):
pk = request.GET.get("pk", None) # pk = request.GET.get("pk", None)
ans = UserAnswer.objects.filter(user=request.user, question__pk=pk).first() # ans = UserAnswer.objects.filter(user=request.user, question__pk=pk).first()
ans.flagged = not ans.flagged # ans.flagged = not ans.flagged
ans.save() # ans.save()
data = {"flagged": ans.flagged} # data = {"flagged": ans.flagged}
return JsonResponse(data) # return JsonResponse(data)
def loadJsonAnswer(answer): def loadJsonAnswer(answer):
@@ -329,8 +329,7 @@ def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False):
except IndexError: except IndexError:
raise Http404("Exam question does not exist") raise Http404("Exam question does not exist")
# unmarked_user_answers = question.get_unmarked_user_answers()
#unmarked_user_answers = question.get_unmarked_user_answers()
if request.method == "POST": if request.method == "POST":
@@ -383,9 +382,9 @@ def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False):
else: else:
form = MarkAnatomyQuestionForm() form = MarkAnatomyQuestionForm()
#correct_answers = question.answers.filter(status=Answer.MarkOptions.CORRECT) # correct_answers = question.answers.filter(status=Answer.MarkOptions.CORRECT)
#half_mark_answers = question.answers.filter(status=Answer.MarkOptions.HALF_MARK) # half_mark_answers = question.answers.filter(status=Answer.MarkOptions.HALF_MARK)
#incorrect_answers = question.answers.filter(status=Answer.MarkOptions.INCORRECT) # incorrect_answers = question.answers.filter(status=Answer.MarkOptions.INCORRECT)
correct_answers = [] correct_answers = []
half_mark_answers = [] half_mark_answers = []
@@ -395,13 +394,14 @@ def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False):
unmarked_user_answers = [] unmarked_user_answers = []
if review: if review:
unmarked_user_answers = question.get_user_answers(exam_pk=exam_pk, include_normal=False) unmarked_user_answers = question.get_user_answers(
exam_pk=exam_pk, include_normal=False
)
elif unmarked_exam_answers_only: elif unmarked_exam_answers_only:
unmarked_user_answers = question.get_unmarked_user_answers(exam_pk=exam_pk) unmarked_user_answers = question.get_unmarked_user_answers(exam_pk=exam_pk)
else: else:
unmarked_user_answers = question.get_unmarked_user_answers() unmarked_user_answers = question.get_unmarked_user_answers()
if not unmarked_exam_answers_only: if not unmarked_exam_answers_only:
correct_answers = question.answers.filter(status=Answer.MarkOptions.CORRECT) correct_answers = question.answers.filter(status=Answer.MarkOptions.CORRECT)
half_mark_answers = question.answers.filter(status=Answer.MarkOptions.HALF_MARK) half_mark_answers = question.answers.filter(status=Answer.MarkOptions.HALF_MARK)
@@ -532,6 +532,7 @@ def exam_scores_cid(request, pk):
"anatomy/exam_scores.html", "anatomy/exam_scores.html",
{ {
"cids": cids, "cids": cids,
"passcode": passcode,
"exam": exam, "exam": exam,
"unmarked": unmarked, "unmarked": unmarked,
"questions": questions, "questions": questions,
@@ -551,14 +552,15 @@ def exam_scores_cid(request, pk):
) )
def exam_scores_cid_user(request, pk, sk): def exam_scores_cid_user(request, pk, sk, passcode):
exam = get_object_or_404(Exam, pk=pk) exam = get_object_or_404(Exam, pk=pk)
if not exam.exam_mode: if not exam.exam_mode:
raise Http404("Packet not in exam mode") raise Http404("Packet not in exam mode")
# TODO:Need some kind of test for cid
cid = sk cid = sk
if not exam.check_cid_user(cid, passcode):
raise Http404("Error accessing exam")
questions = exam.exam_questions.all() questions = exam.exam_questions.all()
@@ -609,6 +611,7 @@ def exam_scores_cid_user(request, pk, sk):
{ {
"exam": exam, "exam": exam,
"cid": cid, "cid": cid,
"passcode": passcode,
"questions": questions, "questions": questions,
"answers": answers, "answers": answers,
"answers_marks": answers_marks, "answers_marks": answers_marks,
@@ -1051,5 +1054,4 @@ class StructureAutocomplete(autocomplete.Select2QuerySetView):
except FieldError: except FieldError:
return Structure.objects.none() return Structure.objects.none()
return qs return qs
+71 -70
View File
@@ -1,82 +1,83 @@
{% extends 'longs/base.html' %} {% extends 'longs/base.html' %}
{% block content %} {% block content %}
<div class="question-display-block"> <div class="question-display-block">
<div class="hide-show">HIDE/SHOW</div> <div class="hide-show">HIDE/SHOW</div>
<div class="inner-display-block"> <div class="inner-display-block">
Question <span class="question-number">1</span><br /> Question <span class="question-number">1</span><br />
History: <span id="history"></span><br /> History: <span id="history"></span><br />
Images: <span id="series"></span> Images: <span id="series"></span>
<div id="single-dicom-viewer" class="dicom-viewer" data-images="" data-annotations=''> <div id="single-dicom-viewer" class="dicom-viewer" data-images="" data-annotations=''>
</div>
</div> </div>
</div> </div>
<div class="longs"> </div>
<h2>Exam: {{ exam.name }}</h2> <div class="longs">
<h3>Candidate: {{ cid }}</h3> <h2>Exam: {{ exam.name }}</h2>
Scores: <h3>Candidate: {{ cid }}</h3>
<ul>{% for score in answers_marks %} Scores:
<li class="user-answer-li">Question {{forloop.counter}}</li> <ul>{% for score in answers_marks %}
<span class="user-answer-score user-answer-score-{{score}}"> <li class="user-answer-li">Question {{forloop.counter}}</li>
<pre>{{ans}}</pre> ({{score}})</span> <span class="user-answer-score user-answer-score-{{score}}">
<pre>{{ans}}</pre> ({{score}})
</span>
{% endfor %} {% endfor %}
</ul> </ul>
<br /> Total mark: {{ total_score }} / {{max_score}} <br /> Total mark: {{ total_score }} / {{max_score}}
<br /> Normalised score: {{normalised_score}} <br /> Normalised score: {{normalised_score}}
<div> <div>
<h4>Answers</h4> <h4>Answers</h4>
<ul class="long-answer">{% for a,b,c,d,e in answer_text %} <ul class="long-answer">{% for a,b,c,d,e in answer_text %}
<li class="user-answer-li"><b>Question {{forloop.counter}}</b> <span class="view-question-link-longs" <li class="user-answer-li"><b>Question {{forloop.counter}}</b> <span class="view-question-link-longs"
data-qn={{forloop.counter0}}>View</span></li> data-qn={{forloop.counter0}}>View</span></li>
<ul> <ul>
<li class="user-answer-li">Observation</br> <li class="user-answer-li">Observation</br>
<pre>{{a}}</pre> <pre>{{a}}</pre>
</li> </li>
<li class="user-answer-li">Interpretation</br> <li class="user-answer-li">Interpretation</br>
<pre>{{b}}</pre> <pre>{{b}}</pre>
</li> </li>
<li class="user-answer-li">Principle Diagnosis</br> <li class="user-answer-li">Principle Diagnosis</br>
<pre>{{c}}</pre> <pre>{{c}}</pre>
</li> </li>
<li class="user-answer-li">Differential Diagnosis</br> <li class="user-answer-li">Differential Diagnosis</br>
<pre>{{d}}</pre> <pre>{{d}}</pre>
</li> </li>
<li class="user-answer-li">Management</br> <li class="user-answer-li">Management</br>
<pre>{{e}}</pre> <pre>{{e}}</pre>
</li> </li>
</ul>
{% endfor %}
</ul> </ul>
{% endfor %}
</ul>
</div>
<div>
<a href="{% url 'cid_scores' cid %}">Other exams</a>
</div>
</div> </div>
<div>
<a href="{% url 'cid_scores' cid passcode %}">Other exams</a>
</div>
</div>
{% endblock %} {% endblock %}
{% block js %} {% block js %}
<script> <script>
$(document).ready(function () { $(document).ready(function () {
$(".hide-show").click((evt, el) => { $(".hide-show").click((evt, el) => {
$(".inner-display-block").toggle(); $(".inner-display-block").toggle();
}) })
$(".view-question-link-longs").on("click", function (e) { $(".view-question-link-longs").on("click", function (e) {
console.log("click", e) console.log("click", e)
question_number = e.currentTarget.dataset.qn; question_number = e.currentTarget.dataset.qn;
$("#single-dicom-viewer").empty(); $("#single-dicom-viewer").empty();
$.ajax({ $.ajax({
url: `{% url 'longs:question_review' pk=exam.pk %}`, url: `{% url 'longs:question_review' pk=exam.pk %}`,
data: { data: {
csrfmiddlewaretoken: "{{ csrf_token }}", csrfmiddlewaretoken: "{{ csrf_token }}",
question_number: question_number question_number: question_number
}, },
type: "POST", type: "POST",
dataType: "json", dataType: "json",
}) })
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) { .done(function (data) {
console.log(data); console.log(data);
let event = new CustomEvent('loadDicomViewerUrls', { let event = new CustomEvent('loadDicomViewerUrls', {
@@ -93,7 +94,7 @@
$("#series").empty(); $("#series").empty();
data.image_titles.forEach((element, index) => { data.image_titles.forEach((element, index) => {
$("#series").append($( $("#series").append($(
`<span class="image-link" title="click to view">${index+1}: ${element}</span> ` `<span class="image-link" title="click to view">${index + 1}: ${element}</span> `
).click(() => { ).click(() => {
$("#single-dicom-viewer").empty(); $("#single-dicom-viewer").empty();
let event = new CustomEvent('loadDicomViewerUrls', { let event = new CustomEvent('loadDicomViewerUrls', {
@@ -110,13 +111,13 @@
}) })
$(".inner-display-block").show(); $(".inner-display-block").show();
}) })
.always(function () { .always(function () {
console.log('[Done]'); console.log('[Done]');
}) })
}) })
$(".view-question-link").first().click(); $(".view-question-link").first().click();
}); });
</script> </script>
{% endblock %} {% endblock %}
+16 -4
View File
@@ -66,9 +66,21 @@ urlpatterns = [
views.question_review, views.question_review,
name="question_review", name="question_review",
), ),
path("exam/<int:exam_id>/<int:question_number>/<int:cid>/mark", views.mark_answer, name="mark_answer"), path(
path("exam/<int:exam_id>/<int:question_number>/<int:cid>/mark_override", views.mark_answer_override, name="mark_answer_override"), "exam/<int:exam_id>/<int:question_number>/<int:cid>/mark",
path("exam/<int:exam_id>/<int:sk>/mark", views.mark_question_overview, name="mark_question_overview"), views.mark_answer,
name="mark_answer",
),
path(
"exam/<int:exam_id>/<int:question_number>/<int:cid>/mark_override",
views.mark_answer_override,
name="mark_answer_override",
),
path(
"exam/<int:exam_id>/<int:sk>/mark",
views.mark_question_overview,
name="mark_question_overview",
),
path("exam/<int:pk>/mark", views.LongExamViews.mark_overview, name="mark_overview"), path("exam/<int:pk>/mark", views.LongExamViews.mark_overview, name="mark_overview"),
# path("exam/<int:pk>/<int:sk>/", views.exam_take, name="exam_take"), # path("exam/<int:pk>/<int:sk>/", views.exam_take, name="exam_take"),
path( path(
@@ -89,7 +101,7 @@ urlpatterns = [
), ),
path("exam/<int:pk>/scores", views.exam_scores_cid, name="exam_scores_cid"), path("exam/<int:pk>/scores", views.exam_scores_cid, name="exam_scores_cid"),
path( path(
"exam/<int:pk>/scores/<int:sk>/", "exam/<int:pk>/scores/<int:sk>/<str:passcode>/",
views.exam_scores_cid_user, views.exam_scores_cid_user,
name="exam_scores_cid_user", name="exam_scores_cid_user",
), ),
+2 -1
View File
@@ -1032,7 +1032,7 @@ def exam_scores_cid(request, pk):
) )
def exam_scores_cid_user(request, pk, sk): def exam_scores_cid_user(request, pk, sk, passcode):
exam = get_object_or_404(Exam, pk=pk) exam = get_object_or_404(Exam, pk=pk)
# TODO:Need some kind of test for cid # TODO:Need some kind of test for cid
@@ -1104,6 +1104,7 @@ def exam_scores_cid_user(request, pk, sk):
{ {
"exam": exam, "exam": exam,
"cid": cid, "cid": cid,
"passcode" : passcode,
"questions": questions, "questions": questions,
# "answers": answers, # "answers": answers,
"answers_marks": answers_marks, "answers_marks": answers_marks,
@@ -10,7 +10,8 @@
<li class="user-answer-li">Question {{forloop.counter}} - {{ question.stem }}</li> <li class="user-answer-li">Question {{forloop.counter}} - {{ question.stem }}</li>
<ol type="a"> <ol type="a">
{% for q, a, score, correct_answer in ans %} {% for q, a, score, correct_answer in ans %}
<li>{{q}}: Correct answer: {{correct_answer}} <br />{{a}} <span class="answer-{{score}}">(Score: {{score}})</span></li> <li>{{q}}: Correct answer: {{correct_answer}} <br />{{a}} <span class="answer-{{score}}">(Score:
{{score}})</span></li>
{% endfor %} {% endfor %}
</ol> </ol>
{% endfor %} {% endfor %}
+3 -4
View File
@@ -88,7 +88,7 @@ def active_exams(request):
@login_required @login_required
def exam_scores_cid(request, pk, passcode): def exam_scores_cid(request, pk):
exam = get_object_or_404(Exam, pk=pk) exam = get_object_or_404(Exam, pk=pk)
questions = exam.exam_questions.all() questions = exam.exam_questions.all()
@@ -170,7 +170,6 @@ def exam_scores_cid(request, pk, passcode):
"physics/exam_scores.html", "physics/exam_scores.html",
{ {
"cids": cids, "cids": cids,
"passcode": passcode,
"exam": exam, "exam": exam,
"unmarked": unmarked, "unmarked": unmarked,
"questions": questions, "questions": questions,
@@ -281,7 +280,7 @@ def exam_start(request, pk):
) )
def exam_finish(request, pk, cid, passcode=None): def exam_finish(request, pk, cid, passcode):
exam = get_object_or_404(Exam, pk=pk) exam = get_object_or_404(Exam, pk=pk)
if not exam.check_cid_user(cid, passcode): if not exam.check_cid_user(cid, passcode):
@@ -322,7 +321,7 @@ def exam_finish(request, pk, cid, passcode=None):
) )
def exam_take(request, pk, sk, cid, passcode=None): def exam_take(request, pk, sk, cid, passcode):
exam = get_object_or_404(Exam, pk=pk) exam = get_object_or_404(Exam, pk=pk)
+49 -49
View File
@@ -1,62 +1,62 @@
{% extends 'rapids/base.html' %} {% extends 'rapids/base.html' %}
{% block content %} {% block content %}
<div class="question-display-block"> <div class="question-display-block">
<div class="hide-show">HIDE/SHOW</div> <div class="hide-show">HIDE/SHOW</div>
<div class="inner-display-block"> <div class="inner-display-block">
Question <span class="question-number">1</span> Question <span class="question-number">1</span>
<div id="single-dicom-viewer" class="dicom-viewer" data-images="" data-annotations=''> <div id="single-dicom-viewer" class="dicom-viewer" data-images="" data-annotations=''>
</div>
<div class="answers">Answers: </div>
</div> </div>
<div class="answers">Answers: </div>
</div> </div>
<div class="rapids"> </div>
<h2>Exam: {{ exam.name }}</h2> <div class="rapids">
<h3>Candidate: {{ cid }}</h3> <h2>Exam: {{ exam.name }}</h2>
Answers: <h3>Candidate: {{ cid }}</h3>
<ul class="score-answer-list">{% for ans, score, correct_answer in answers_and_marks %} Answers:
<li class="user-answer-li">Question {{forloop.counter}} - Correct answer: <span <ul class="score-answer-list">{% for ans, score, correct_answer in answers_and_marks %}
class="correct-answer">{{ correct_answer }}</span></li> <li class="user-answer-li">Question {{forloop.counter}} - Correct answer: <span class="correct-answer">{{
<span class="user-answer-score user-answer-score-{{score}} rapid-ans"> correct_answer }}</span></li>
<pre>{{ans}}</pre> ({{score}}) <span class="user-answer-score user-answer-score-{{score}} rapid-ans">
</span> <pre>{{ans}}</pre> ({{score}})
<span class="view-question-link" data-qn={{forloop.counter0}}>View</span> </span>
<span class="view-question-link" data-qn={{forloop.counter0}}>View</span>
{% endfor %} {% endfor %}
</ul> </ul>
<br /> Total mark: {{ total_score }} / {{max_score}} <br /> Total mark: {{ total_score }} / {{max_score}}
<br /> Normalised score: {{ normalised_score }} <br /> Normalised score: {{ normalised_score }}
<div> <div>
<a href="{% url 'cid_scores' cid %}">Other exams</a> <a href="{% url 'cid_scores' cid passcode %}">Other exams</a>
</div>
</div> </div>
</div>
{% endblock %} {% endblock %}
{% block js %} {% block js %}
<script> <script>
$(document).ready(function () { $(document).ready(function () {
$(".hide-show").click((evt, el) => { $(".hide-show").click((evt, el) => {
$(".inner-display-block").toggle(); $(".inner-display-block").toggle();
})
$(".view-question-link").on("click", function (e) {
console.log("click", e)
question_number = e.currentTarget.dataset.qn;
$("#single-dicom-viewer").empty();
$.ajax({
url: `{% url 'rapids:question_review' pk=exam.pk %}`,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
question_number: question_number
},
type: "POST",
dataType: "json",
}) })
$(".view-question-link").on("click", function (e) {
console.log("click", e)
question_number = e.currentTarget.dataset.qn;
$("#single-dicom-viewer").empty();
$.ajax({
url: `{% url 'rapids:question_review' pk=exam.pk %}`,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
question_number: question_number
},
type: "POST",
dataType: "json",
})
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) { .done(function (data) {
console.log(data); console.log(data);
let event = new CustomEvent('loadDicomViewerUrls', { let event = new CustomEvent('loadDicomViewerUrls', {
"detail": {"images" : data.images, "annotations" : data.annotations} "detail": { "images": data.images, "annotations": data.annotations }
}); });
window.dispatchEvent(event); window.dispatchEvent(event);
@@ -67,13 +67,13 @@
// For eg. A message box showing that the status has been changed // For eg. A message box showing that the status has been changed
$(".inner-display-block").show(); $(".inner-display-block").show();
}) })
.always(function () { .always(function () {
console.log('[Done]'); console.log('[Done]');
}) })
}) })
$(".view-question-link").first().click(); $(".view-question-link").first().click();
}); });
</script> </script>
{% endblock %} {% endblock %}
+1 -1
View File
@@ -76,7 +76,7 @@ urlpatterns = [
name="exam_scores_cid", name="exam_scores_cid",
), ),
path( path(
"exam/<int:pk>/scores/<int:cid>/", "exam/<int:pk>/scores/<int:cid>/<str:passcode>/",
views.exam_scores_cid_user, views.exam_scores_cid_user,
name="exam_scores_cid_user", name="exam_scores_cid_user",
), ),
+2 -1
View File
@@ -846,7 +846,7 @@ def exam_scores_cid(request, pk):
) )
def exam_scores_cid_user(request, pk, cid): def exam_scores_cid_user(request, pk, cid, passcode):
exam = get_object_or_404(Exam, pk=pk) exam = get_object_or_404(Exam, pk=pk)
if not exam.exam_mode: if not exam.exam_mode:
@@ -908,6 +908,7 @@ def exam_scores_cid_user(request, pk, cid):
{ {
"exam": exam, "exam": exam,
"cid": cid, "cid": cid,
"passcode" : passcode,
"questions": questions, "questions": questions,
"answers": answers, "answers": answers,
"answers_marks": answers_marks, "answers_marks": answers_marks,
+5 -3
View File
@@ -7,13 +7,15 @@
Answers: Answers:
<ul> <ul>
{% for question, a, score, correct_answer in answers_and_marks %} {% for question, a, score, correct_answer in answers_and_marks %}
<li class="user-answer-li"><a href="{% url 'sbas:exam_take' exam.pk forloop.counter0 cid %}">Question {{forloop.counter}}</a> - {{ question.stem |safe}}</li> <li class="user-answer-li"><a href="{% url 'sbas:exam_take' exam.pk forloop.counter0 cid %}">Question
<span>Correct answer: {{correct_answer|safe}} <br />{{a}} <span class="answer-{{score}}">(Score: {{score}})</span></span> {{forloop.counter}}</a> - {{ question.stem |safe}}</li>
<span>Correct answer: {{correct_answer|safe}} <br />{{a}} <span class="answer-{{score}}">(Score:
{{score}})</span></span>
{% endfor %} {% endfor %}
</ul> </ul>
<br /> Total mark: {{ total_score }} / {{max_score}} <br /> Total mark: {{ total_score }} / {{max_score}}
<div> <div>
<a href="{% url 'cid_scores' cid %}">Other exams</a> <a href="{% url 'cid_scores' cid passcode %}">Other exams</a>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
+3 -3
View File
@@ -14,9 +14,9 @@ urlpatterns = [
# path("question/<int:pk>/update", views.QuestionUpdate.as_view(), name="anatomy_question_update"), # path("question/<int:pk>/update", views.QuestionUpdate.as_view(), name="anatomy_question_update"),
# path("exam/<int:pk>/<int:sk>/mark", views.mark, name="mark"), # path("exam/<int:pk>/<int:sk>/mark", views.mark, name="mark"),
# path("exam/<int:pk>/mark", views.mark_overview, name="mark_overview"), # path("exam/<int:pk>/mark", views.mark_overview, name="mark_overview"),
path("exam/<int:pk>/<int:sk>/<str:cid>/take", views.exam_take, name="exam_take"), path("exam/<int:pk>/<int:sk>/<str:cid>/<str:passcode>/take", views.exam_take, name="exam_take"),
path("exam/<int:pk>/start", views.exam_start, name="exam_start"), path("exam/<int:pk>/start", views.exam_start, name="exam_start"),
path("exam/<int:pk>/<str:cid>/finish", views.exam_finish, name="exam_finish"), path("exam/<int:pk>/<str:cid>/<str:passcode>/finish", views.exam_finish, name="exam_finish"),
path("exam/<int:pk>/", views.SbasExamViews.exam_overview, name="exam_overview"), path("exam/<int:pk>/", views.SbasExamViews.exam_overview, name="exam_overview"),
path( path(
"exam/<int:pk>/scores", "exam/<int:pk>/scores",
@@ -24,7 +24,7 @@ urlpatterns = [
name="exam_scores_cid", name="exam_scores_cid",
), ),
path( path(
"exam/<int:pk>/scores/<int:sk>/", "exam/<int:pk>/scores/<int:sk>/<str:passcode>/",
views.exam_scores_cid_user, views.exam_scores_cid_user,
name="exam_scores_cid_user", name="exam_scores_cid_user",
), ),
+19 -7
View File
@@ -179,7 +179,7 @@ def exam_scores_cid(request, pk):
) )
def exam_scores_cid_user(request, pk, sk): def exam_scores_cid_user(request, pk, sk, passcode):
exam = get_object_or_404(Exam, pk=pk) exam = get_object_or_404(Exam, pk=pk)
# TODO:Need some kind of test for cid # TODO:Need some kind of test for cid
@@ -229,6 +229,7 @@ def exam_scores_cid_user(request, pk, sk):
{ {
"exam": exam, "exam": exam,
"cid": cid, "cid": cid,
"passcode" : passcode,
"questions": questions, "questions": questions,
"answers": answers, "answers": answers,
"answers_marks": answers_marks, "answers_marks": answers_marks,
@@ -253,9 +254,12 @@ def exam_start(request, pk):
}, },
) )
def exam_finish(request, pk, cid): def exam_finish(request, pk, cid, passcode):
exam = get_object_or_404(Exam, pk=pk) exam = get_object_or_404(Exam, pk=pk)
if not exam.check_cid_user(cid, passcode):
raise Http404("Error accessing exam")
questions = exam.exam_questions.all() questions = exam.exam_questions.all()
answers = CidUserAnswer.objects.filter( answers = CidUserAnswer.objects.filter(
@@ -286,17 +290,21 @@ def exam_finish(request, pk, cid):
"question_answer_tuples": question_answer_tuples, "question_answer_tuples": question_answer_tuples,
"answer_count": answer_count, "answer_count": answer_count,
"exam_length": len(questions), "exam_length": len(questions),
"passcode": passcode,
}, },
) )
def exam_take(request, pk, sk, cid): def exam_take(request, pk, sk, cid, passcode):
exam = get_object_or_404(Exam, pk=pk) exam = get_object_or_404(Exam, pk=pk)
if not exam.active: if not exam.active:
raise Http404("Exam not found") raise Http404("Exam not found")
if not exam.check_cid_user(cid, passcode):
raise Http404("Error accessing exam")
question = exam.exam_questions.all()[sk] question = exam.exam_questions.all()[sk]
exam_length = len(exam.exam_questions.all()) exam_length = len(exam.exam_questions.all())
@@ -318,14 +326,17 @@ def exam_take(request, pk, sk, cid):
answer.exam = exam answer.exam = exam
# answer.published_date = timezone.now() # answer.published_date = timezone.now()
answer.save() answer.save()
kwargs = {"pk": pk, "cid": cid, "passcode": passcode}
if "next" in request.POST: if "next" in request.POST:
return redirect("sbas:exam_take", pk=pk, sk=pos + 1, cid=cid) return redirect("sbas:exam_take", sk=pos + 1, **kwargs)
elif "previous" in request.POST: elif "previous" in request.POST:
return redirect("sbas:exam_take", pk=pk, sk=pos - 1, cid=cid) return redirect("sbas:exam_take", sk=pos - 1, **kwargs)
elif "finish" in request.POST: elif "finish" in request.POST:
return redirect("sbas:exam_finish", pk=pk, cid=cid) return redirect("sbas:exam_finish", **kwargs)
elif "goto" in request.POST: elif "goto" in request.POST:
return redirect("sbas:exam_take", pk=pk, sk=int(request.POST.get("goto")), cid=cid) return redirect("sbas:exam_take", sk=int(request.POST.get("goto")), **kwargs)
else: else:
form = CidUserAnswerForm(instance=answer) form = CidUserAnswerForm(instance=answer)
@@ -354,6 +365,7 @@ def exam_take(request, pk, sk, cid):
"exam_length": exam_length, "exam_length": exam_length,
"pos": pos, "pos": pos,
"saved_answer": saved_answer, "saved_answer": saved_answer,
"passcode": passcode,
}, },
) )