allow completion of sbas / physics exams

This commit is contained in:
Ross
2024-12-30 11:12:36 +00:00
parent 13713d870f
commit 7493d55bc2
17 changed files with 362 additions and 240 deletions
+5 -2
View File
@@ -9,13 +9,13 @@
{% endif %}
{% if request.user.is_authenticated and valid_user %}
<a href="{% url 'sbas:exam_take_user' pk=exam.pk sk=0 %}">Start Exam</a>
<a href="{% url 'sbas:exam_take_user' pk=exam.pk sk=0 %}" title="Click to start the exam"><button class="btn btn-primary">Start Exam</button></a>
{% else %}
Enter your CID and passcode in the below boxes.<br />
<p><input id="cid-box" type="text" value="Candidate ID"></p>
<p><input id="passcode-box" type="text" value="Passcode"></p>
<button>Start exam</button>
<button type="button" class="btn btn-primary">Start exam</button>
<script type="text/javascript">
$(document).ready(function () {
@@ -52,4 +52,7 @@
});
</script>
{% endif %}
{% include "sbas/exam_take_help.html" %}
{% endblock %}
+9 -17
View File
@@ -15,6 +15,10 @@
<div class="alert alert-primary review-mode-alert" role="alert">
Exam is in review mode. Add question feedback <a href="#" onclick="return window.create_popup_window('{% url 'feedback_create' question_type='sbas' pk=question.pk %}')">here</a>.
</div>
{% elif cid_user_exam.completed %}
<div class="alert alert-primary review-mode-alert" role="alert">
Exam completed.
</div>
{% endif %}
<div>
@@ -62,26 +66,14 @@
<div id="menu-list">
</div>
<details><summary>Help</summary>
<p>Each question contains a list of 5 different statements. One of these is the single BEST answer.</p>
<p>Click on the correct statement to select it. Once selected it will be highlighted. </p>
<p>Your answers are saved when navigating between questions (or if the save button is clicked on the final question). An overview of all the questions can be seen by clicking on the overview button (or by clicking <a target="_blank" href="
{% if cid %}
{% url 'sbas:exam_scores_cid_user' pk=exam.pk cid=cid passcode=passcode %}
{% else %}
{% url 'sbas:exam_scores_user' pk=exam.pk %}
{% endif %}
"
>here</a>).</p>
</details>
{% include "sbas/exam_take_help.html" %}
{% endblock %}
{% block js %}
<script>
$(document).ready(() => {
/* beautify ignore:start */
{% if not exam.publish_results %}
{% if not exam.publish_results and not cid_user_exam.completed %}
let time_limit = '{{exam.time_limit}}'
if (time_limit != "None") {
@@ -97,7 +89,7 @@
$(el).addClass("selected")
})
})
{% else %}
{% elif exam.publish_results %}
$("ul.sba-answer-list li[data-ans='{{question.best_answer}}']").addClass("correct");
{% endif %}
@@ -130,12 +122,12 @@
.selected {
border: 1px solid purple;
}
li:hover::before {
.sba-answer-list li:hover::before {
content: "Click to select";
float: right
}
li:hover.selected::before {
.sba-answer-list li:hover.selected::before {
content: "Chosen answer";
float: right
}
+15
View File
@@ -0,0 +1,15 @@
<details class="help-text pt-3">
<summary><i class="bi bi-info-circle"></i> Help</summary>
<p>Each question contains a list of 5 different statements. One of these is the single BEST answer.</p>
<p>Click on the correct statement to select it. Once selected it will be highlighted. </p>
<p>Your answers are saved when navigating between questions (or if the save button is clicked on the final question). An overview of all the questions can be seen by clicking on the overview button.</p>
<p>Results are also available on the results page
<a target="_blank" href="
{% if cid %}
{% url 'sbas:exam_scores_cid_user' pk=exam.pk cid=cid passcode=passcode %}
{% else %}
{% url 'sbas:exam_scores_user' pk=exam.pk %}
{% endif %}
">here</a>.</p>
</details>
+26 -7
View File
@@ -2,7 +2,7 @@
{% block content %}
<span id="user-id">
{% if request.user.is_authenticated %}
{% if not cid %}
User: {{request.user}}
{% else %}
CID: {{cid}}
@@ -15,16 +15,22 @@
{% if exam.publish_results %}
<div class="alert alert-primary review-mode-alert" role="alert">
Exam is in review mode. Score are available
{% if request.user.is_authenticated %}
{% if not cid %}
<a href="{% url 'sbas:exam_scores_user' pk=exam.id %}">here</a>
{% else %}
<a href="{% url 'sbas:exam_scores_cid_user' pk=exam.id cid=cid passcode=passcode %}">here</a>
{% endif %}
</div>
{% endif %}
{% if not exam.publish_results and answer_count != exam_length %}
{% elif cid_user_exam.completed %}
<div class="alert alert-primary review-mode-alert" role="alert">
Exam completed. Answers are available
{% if not cid %}
<a href="{% url 'sbas:exam_scores_user' pk=exam.id %}">here</a>
{% else %}
<a href="{% url 'sbas:exam_scores_cid_user' pk=exam.id cid=cid passcode=passcode %}">here</a>
{% endif %}
</div>
{% elif answer_count != exam_length %}
<div id="unanswered-questions-alert" class="alert alert-warning" role="alert">
You have unanswered questions.
</div>
@@ -44,9 +50,22 @@
</div>
<div id="time-details">
Start time: {{cid_user_exam.start_time}}<br/>
Last change time: {{cid_user_exam.end_time}}
Last change time: {{cid_user_exam.end_time}}<br/>
Completed: {{cid_user_exam.completed}}
</div>
{% if not cid_user_exam.completed %}
{% if not cid %}
<button hx-get="{% url 'sbas:exam_complete_user' pk=exam.id %}" hx-swap="outerHTML" hx-confirm="Finish exam?">Finish Exam</button>
{% else %}
<button hx-get="{% url 'sbas:exam_complete' pk=exam.id cid=cid passcode=passcode %}" hx-swap="outerHTML" hx-confirm="Finish exam?">Finish Exam</button>
{% endif %}
{% endif %}
{% include "sbas/exam_take_help.html" %}
{% endblock %}
{% block js %}
+10
View File
@@ -45,6 +45,16 @@ urlpatterns = [
views.exam_take_overview,
name="exam_take_overview_user",
),
path(
"exam/<int:pk>/<str:cid>/<str:passcode>/complete",
views.exam_complete,
name="exam_complete",
),
path(
"exam/<int:pk>/complete",
views.exam_complete,
name="exam_complete_user",
),
path("exam/<int:pk>/markers", views.ExamMarkersUpdate.as_view(), name="exam_markers"),
path("exam/<int:pk>/groups", views.ExamGroupsUpdate.as_view(), name="exam_groups_edit"),
+12 -1
View File
@@ -116,6 +116,17 @@ def exam_start(request, pk):
{"exam": exam, "valid_user": exam.check_logged_in_user(request)},
)
def exam_complete(request, pk, cid=None, passcode=None):
exam = get_object_or_404(Exam, pk=pk)
exam.check_user_can_take(cid, passcode, request.user)
cid_user_exam = exam.get_or_create_cid_user_exam(cid=cid, user_user=request.user)
cid_user_exam.complete_exam()
return HttpResponse("<div role='alert' class='alert alert-info'>Exam completed</div>")
def exam_take_overview(request, pk, cid=None, passcode=None):
exam = get_object_or_404(Exam, pk=pk)
@@ -195,7 +206,7 @@ def exam_take(request, pk: int, sk: int, cid: int = None, passcode: str = None):
form = UserAnswerForm(request.POST, instance=answer)
else:
form = UserAnswerForm(request.POST)
if form.is_valid():
if form.is_valid() and not exam.publish_results and not cid_user_exam.completed:
answer = form.save(commit=False)
if cid is not None: