add publish results feature
This commit is contained in:
+1
-1
@@ -6,5 +6,5 @@ from .models import AnatomyQuestion
|
|||||||
class AnatomyQuestionFilter(django_filters.FilterSet):
|
class AnatomyQuestionFilter(django_filters.FilterSet):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AnatomyQuestion
|
model = AnatomyQuestion
|
||||||
fields = ("question_type", "examination", "modality", "region",
|
fields = ("question_type", "exams", "examination", "modality", "region",
|
||||||
"body_part", "created_date", "open_access", "author")
|
"body_part", "created_date", "open_access", "author")
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2020-12-10 23:11
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('anatomy', '0011_anatomyquestion_author'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='exam',
|
||||||
|
name='publish_results',
|
||||||
|
field=models.BooleanField(default=True, help_text='If an exams results should be available'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -258,6 +258,10 @@ class Exam(models.Model):
|
|||||||
help_text="If an exam should be available", default=True
|
help_text="If an exam should be available", default=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
publish_results = models.BooleanField(
|
||||||
|
help_text="If an exams results should be available", default=True
|
||||||
|
)
|
||||||
|
|
||||||
recreate_json = models.BooleanField(
|
recreate_json = models.BooleanField(
|
||||||
help_text="If the json cache needs updating", default=False
|
help_text="If the json cache needs updating", default=False
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -301,3 +301,11 @@ img.uploading:hover {
|
|||||||
.user-answer-li {
|
.user-answer-li {
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.parent-help:hover .help-text {
|
||||||
|
opacity: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.parent-help .help-text {
|
||||||
|
opacity: 0%;
|
||||||
|
}
|
||||||
+1
-1
@@ -21,6 +21,6 @@ class AnatomyQuestionTable(tables.Table):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = AnatomyQuestion
|
model = AnatomyQuestion
|
||||||
template_name = "django_tables2/bootstrap4.html"
|
template_name = "django_tables2/bootstrap4.html"
|
||||||
fields = ("question_type", "description", "examination", "modality", "region",
|
fields = ("question_type", "exams", "description", "examination", "modality", "region",
|
||||||
"body_part", "created_date", "open_access", "author")
|
"body_part", "created_date", "open_access", "author")
|
||||||
sequence = ("view", )
|
sequence = ("view", )
|
||||||
@@ -7,8 +7,11 @@
|
|||||||
<h1>Exam: {{ exam.name }}</h1>
|
<h1>Exam: {{ exam.name }}</h1>
|
||||||
This exam has {{question_number}} questions.
|
This exam has {{question_number}} questions.
|
||||||
|
|
||||||
<div title="Click to enable / disable the exam">
|
<div class="parent-help" title="Click to enable / disable the exam">
|
||||||
Exam active: <input type="checkbox" id="exam-active-switch" {% if exam.active %}checked{% endif %}>
|
Exam active: <input type="checkbox" id="exam-active-switch" {% if exam.active %}checked{% endif %}> <span class="help-text">[When checked the exam will be available to take in the test system]</span>
|
||||||
|
</div>
|
||||||
|
<div class="parent-help" title="Click to enable / disable the exam results">
|
||||||
|
Publish results: <input type="checkbox" id="exam-publish-results-switch" {% if exam.publish_results %}checked{% endif %}> <span class="help-text">[When checked the exam results will be available on this site]</span>
|
||||||
</div>
|
</div>
|
||||||
<p><a href="{% url 'anatomy:mark_overview' pk=exam.pk %}"><button>Mark exam</button></a></p>
|
<p><a href="{% url 'anatomy:mark_overview' pk=exam.pk %}"><button>Mark exam</button></a></p>
|
||||||
<!--<p><button><a href="{% url 'anatomy:exam_take' pk=exam.pk sk=0 %}">Click here to start</a></button></p>-->
|
<!--<p><button><a href="{% url 'anatomy:exam_take' pk=exam.pk sk=0 %}">Click here to start</a></button></p>-->
|
||||||
@@ -57,6 +60,30 @@
|
|||||||
console.log('[Done]');
|
console.log('[Done]');
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
$("#exam-publish-results-switch").on("change", function () {
|
||||||
|
$.ajax({
|
||||||
|
url: "{% url 'anatomy:exam_toggle_results_published' pk=exam.pk %}",
|
||||||
|
data: {
|
||||||
|
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||||
|
publish_results: this.checked // true if checked else false
|
||||||
|
},
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
})
|
||||||
|
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||||
|
.done(function (data) {
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
if (data.status == "success") {
|
||||||
|
toastr.info('Publish results state changed.')
|
||||||
|
}
|
||||||
|
// show some message according to the response.
|
||||||
|
// For eg. A message box showing that the status has been changed
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
console.log('[Done]');
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -23,6 +23,7 @@ urlpatterns = [
|
|||||||
path("exam/<int:pk>/scores/<int:sk>/", views.exam_scores_cid_user,
|
path("exam/<int:pk>/scores/<int:sk>/", views.exam_scores_cid_user,
|
||||||
name="exam_scores_cid_user"),
|
name="exam_scores_cid_user"),
|
||||||
path("exam/<int:pk>/toggle_active", views.exam_toggle_active, name="exam_toggle_active"),
|
path("exam/<int:pk>/toggle_active", views.exam_toggle_active, name="exam_toggle_active"),
|
||||||
|
path("exam/<int:pk>/toggle_results_published", views.exam_toggle_results_published, name="exam_toggle_results_published"),
|
||||||
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"),
|
||||||
|
|||||||
@@ -457,6 +457,19 @@ def mark(request, pk, sk):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def exam_toggle_results_published(request, pk):
|
||||||
|
if request.is_ajax() and request.method=='POST':
|
||||||
|
|
||||||
|
exam = get_object_or_404(Exam, pk=pk)
|
||||||
|
|
||||||
|
exam.publish_results = True if request.POST.get('publish_results') == 'true' else False
|
||||||
|
exam.save()
|
||||||
|
data = {'status':'success', 'publish_results':exam.publish_results}
|
||||||
|
return JsonResponse(data, status=200)
|
||||||
|
else:
|
||||||
|
data = {'status':'error'}
|
||||||
|
return JsonResponse(data, status=400)
|
||||||
|
|
||||||
def exam_toggle_active(request, pk):
|
def exam_toggle_active(request, pk):
|
||||||
if request.is_ajax() and request.method=='POST':
|
if request.is_ajax() and request.method=='POST':
|
||||||
|
|
||||||
@@ -664,6 +677,10 @@ def exam_scores_cid_user(request, pk, sk):
|
|||||||
answer_score = user_answer.get_answer_score()
|
answer_score = user_answer.get_answer_score()
|
||||||
|
|
||||||
correct_answer = q.GetPrimaryAnswer()
|
correct_answer = q.GetPrimaryAnswer()
|
||||||
|
|
||||||
|
if not exam.publish_results:
|
||||||
|
correct_answer = "*****"
|
||||||
|
answer_score = 0
|
||||||
answers.append(ans)
|
answers.append(ans)
|
||||||
answers_marks.append(answer_score)
|
answers_marks.append(answer_score)
|
||||||
answers_and_marks.append((ans, answer_score, correct_answer))
|
answers_and_marks.append((ans, answer_score, correct_answer))
|
||||||
|
|||||||
Reference in New Issue
Block a user