.
This commit is contained in:
+26
-2
@@ -24,7 +24,7 @@ from .forms import (
|
||||
ExaminationForm,
|
||||
)
|
||||
|
||||
from .models import Examination
|
||||
from .models import Examination, QuestionNote
|
||||
|
||||
from rapids.models import Rapid as RapidQuestion
|
||||
from rapids.models import Exam as RapidExam
|
||||
@@ -39,6 +39,8 @@ from django.conf import settings
|
||||
from datetime import datetime
|
||||
import os
|
||||
|
||||
from rad.views import get_question_and_content_type
|
||||
|
||||
|
||||
# Create your views here.
|
||||
@login_required
|
||||
@@ -286,6 +288,10 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
|
||||
can_edit = self.check_user_edit_access(request.user) | request.user.is_superuser
|
||||
|
||||
notes = []
|
||||
if can_edit:
|
||||
notes = self.exam_notes(request, pk)
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
question_number = len(questions)
|
||||
@@ -293,9 +299,27 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
return render(
|
||||
request,
|
||||
"{}/exam_overview.html".format(self.app_name),
|
||||
{"exam": exam, "questions": questions, "question_number": question_number, "can_edit": can_edit},
|
||||
{"exam": exam, "questions": questions, "question_number": question_number, "can_edit": can_edit, "notes": notes},
|
||||
)
|
||||
|
||||
#@method_decorator(login_required)
|
||||
def exam_notes(self, request, pk):
|
||||
exam = get_object_or_404(self.Exam, pk=pk)
|
||||
|
||||
if request.user not in exam.author.all():
|
||||
if not self.check_user_access(request.user):
|
||||
raise PermissionDenied
|
||||
|
||||
q, content_type = get_question_and_content_type(self.question_type)
|
||||
|
||||
question_pks = exam.exam_questions.values_list("pk", flat=True)
|
||||
|
||||
# Get active notes for type
|
||||
notes = QuestionNote.objects.filter(content_type=content_type, object_id__in=question_pks, complete=False)
|
||||
|
||||
return notes
|
||||
|
||||
|
||||
@method_decorator(login_required)
|
||||
def exam_json_edit(self, request, pk):
|
||||
if request.is_ajax() and request.method == "POST":
|
||||
|
||||
+2
-2
@@ -185,7 +185,7 @@ def feedback_create(request, question_type, pk):
|
||||
|
||||
return JsonResponse({"success": False, "error": "Invalid exam type"})
|
||||
|
||||
def get_question_and_content_type(pk, question_type):
|
||||
def get_question_and_content_type(question_type):
|
||||
if question_type == "rapid":
|
||||
question = Rapid
|
||||
content_type = ContentType.objects.get(model="rapid")
|
||||
@@ -219,7 +219,7 @@ class AddQuestionNote(CreateView):
|
||||
pk = self.kwargs["pk"]
|
||||
question_type = self.kwargs["question_type"]
|
||||
|
||||
question, content_type = get_question_and_content_type(pk, question_type)
|
||||
question, content_type = get_question_and_content_type(question_type)
|
||||
|
||||
get_object_or_404(question, pk=pk)
|
||||
return { "content_type" : content_type,
|
||||
|
||||
@@ -9,6 +9,17 @@
|
||||
<a href="{% url 'admin:rapids_exam_change' exam.id %}" title="Edit the Exam using the admin interface">Admin
|
||||
Edit</a>
|
||||
<h1>Exam: {{ exam.name }}</h1>
|
||||
|
||||
{% if notes %}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
The following questions have active notes
|
||||
{% for note in notes %}
|
||||
{{note}}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
This exam has {{question_number}} questions. Time limit: {{exam.time_limit}} seconds.<br />
|
||||
<div class="parent-help" title="">
|
||||
Normal count: {{ exam.get_normal_abnormal_breakdown }}<span class="help-text">[Number of normal questions within
|
||||
@@ -191,12 +202,14 @@
|
||||
$("#full-question-list li").each((n, el) => {
|
||||
$(el).append($(
|
||||
"<span class='exam-question-delete flex-col'><button>DELETE</button></span>"
|
||||
).click(() => {
|
||||
).click(() => {
|
||||
el.remove();
|
||||
}));
|
||||
})
|
||||
|
||||
$("#full-question-list").append($("<button title='click and drag questions to change order'>Save exam order</button>").click(() => {
|
||||
$("#full-question-list").append($(
|
||||
"<button title='click and drag questions to change order'>Save exam order</button>"
|
||||
).click(() => {
|
||||
new_order = [];
|
||||
$("#full-question-list li").each((n, el) => {
|
||||
new_order.push(el.dataset.question_pk)
|
||||
|
||||
Reference in New Issue
Block a user