This commit is contained in:
Ross
2022-06-07 22:37:11 +01:00
parent 70b7c4befe
commit 3a542231f0
3 changed files with 225 additions and 176 deletions
+3 -1
View File
@@ -35,7 +35,9 @@
{% endfor %}
</div>
{% if can_edit %}
<p><button id='button-edit-order' title='click and drag questions to change order' data-posturl="{% url 'anatomy:exam_json_edit' pk=exam.pk %}">Edit question order / Delete questions</button></p>
<p>
<button id='button-edit-order' title='click and drag questions to change order' data-posturl="{% url 'anatomy:exam_json_edit' pk=exam.pk %}">Edit question order / Delete questions</button>
</p>
{% endif %}
<div>
JSON creation time: {{exam.json_creation_time}} ({{exam.json_creation_time|date:"c"}}),
+53 -14
View File
@@ -3,6 +3,7 @@ import django_filters
from .models import Rapid, CidUserAnswer, Exam
from django.contrib.auth.models import User
def get_exams(request):
if request is None:
return Exam.objects.none()
@@ -14,6 +15,7 @@ def get_exams(request):
return queryset
def get_authors(request):
if request is None:
return User.objects.none()
@@ -25,22 +27,47 @@ def get_authors(request):
return queryset
class RapidFilter(django_filters.FilterSet):
exams = django_filters.ModelMultipleChoiceFilter(queryset=get_exams, null_label="No exam")
author = django_filters.ModelMultipleChoiceFilter(queryset=get_authors, null_label="No author")
exams = django_filters.ModelMultipleChoiceFilter(
queryset=get_exams, null_label="No exam"
)
author = django_filters.ModelMultipleChoiceFilter(
queryset=get_authors, null_label="No author"
)
class Meta:
model = Rapid
fields = ("normal", "abnormality", "region", "examination",
"laterality",
#"site",
"created_date", "open_access")
fields = {
"normal": ["exact"],
"abnormality": ["exact"],
"region": ["exact"],
"examination": ["exact"],
"laterality": ["exact"],
# "site",
"created_date": ["exact"],
"open_access": ["exact"],
}
def __init__(self, data=None, queryset=None, prefix=None, strict=None, user=None, request=None):
def __init__(
self,
data=None,
queryset=None,
prefix=None,
strict=None,
user=None,
request=None,
):
if not request.user.groups.filter(name="rapid_checker").exists():
queryset = queryset.filter(open_access=True) | queryset.filter(author__id=request.user.id)
super(RapidFilter, self).__init__(data=data, queryset=queryset, prefix=prefix, request=request)
queryset = queryset.filter(open_access=True) | queryset.filter(
author__id=request.user.id
)
super(RapidFilter, self).__init__(
data=data, queryset=queryset, prefix=prefix, request=request
)
pass
class RapidUserAnswerFilter(django_filters.FilterSet):
class Meta:
model = CidUserAnswer
@@ -49,14 +76,26 @@ class RapidUserAnswerFilter(django_filters.FilterSet):
"user",
"normal",
"answer",
#"answer_compare",
# "answer_compare",
"exam",
"created",
"updated",
)
def __init__(self, data=None, queryset=None, prefix=None, strict=None, user=None, request=None):
def __init__(
self,
data=None,
queryset=None,
prefix=None,
strict=None,
user=None,
request=None,
):
if not request.user.groups.filter(name="rapid_checker").exists():
queryset = queryset.filter(open_access=True) | queryset.filter(author__id=request.user.id)
super(RapidUserAnswerFilter, self).__init__(data=data, queryset=queryset, prefix=prefix, request=request)
pass
queryset = queryset.filter(open_access=True) | queryset.filter(
author__id=request.user.id
)
super(RapidUserAnswerFilter, self).__init__(
data=data, queryset=queryset, prefix=prefix, request=request
)
pass
+169 -161
View File
@@ -1,162 +1,170 @@
<script type="text/javascript">
$(document).ready(function () {
// send request to change the is_private state on customSwitches toggle
$("#exam-active-switch, .exam-active-switch").on("change", function (evt) {
$.ajax({
url: evt.currentTarget.dataset.posturl,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
active: 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(`Exam: ${data.name} [${data.id}]
Active state changed to: ${data.active}.`)
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
})
.fail(function (data) {
console.log(data)
toastr.error(`Failed to change state<br/>${data.responseJSON.status}`);
})
.always(function () {
console.log('[Done]');
})
})
$("#exam-publish-results-switch, .exam-publish-results-switch").on("change", function (evt) {
$.ajax({
url: evt.currentTarget.dataset.posturl,
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(`Exam: ${data.name} [${data.id}]
Published state changed to: ${data.publish_results}.`)
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
})
.fail(function (data) {
toastr.error(`Failed to change state`);
})
.always(function () {
console.log('[Done]');
})
})
$("#button-open-access").click(function (evt) {
$.ajax({
url: evt.currentTarget.dataset.posturl,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
set_open_access: true,
},
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('Question access state changed.');
} else {
toastr.warning("Error");
toastr.info(data.status);
}
})
.fail((e) => {
toastr.warning(`Error, ${e}`);
})
.always(function () {
console.log('[Done]');
})
})
$("#button-closed-access").click(function (evt) {
$.ajax({
url: evt.currentTarget.dataset.posturl,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
set_open_access: 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('Question access state changed.');
} else {
toastr.warning("Error");
toastr.info(data.status);
}
})
.fail((e) => {
toastr.warning(`Error, ${e}`);
})
.always(function () {
console.log('[Done]');
})
})
$("#button-edit-order").click(function (evt) {
$(this).remove();
sortable('.sortable');
$("#full-question-list li").each((n, el) => {
$(el).append($(
"<span class='exam-question-delete flex-col'><button>DELETE</button></span>"
).click(() => {
el.remove();
}));
})
$("#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)
})
$.ajax({
url: evt.currentTarget.dataset.posturl,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
set_exam_order: JSON.stringify(new_order),
},
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('Exam order changed.')
}
})
.always(function () {
console.log('[Done]');
})
}));
});
});
<script type="text/javascript">
$(document).ready(function () {
// send request to change the is_private state on customSwitches toggle
$("#exam-active-switch, .exam-active-switch").on("change", function (evt) {
$.ajax({
url: evt.currentTarget.dataset.posturl,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
active: 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(`Exam: ${data.name} [${data.id}]
Active state changed to: ${data.active}.`)
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
})
.fail(function (data) {
console.log(data)
toastr.error(`Failed to change state<br/>${data.responseJSON.status}`);
})
.always(function () {
console.log('[Done]');
})
})
$("#exam-publish-results-switch, .exam-publish-results-switch").on("change", function (evt) {
$.ajax({
url: evt.currentTarget.dataset.posturl,
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(`Exam: ${data.name} [${data.id}]
Published state changed to: ${data.publish_results}.`)
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
})
.fail(function (data) {
toastr.error(`Failed to change state`);
})
.always(function () {
console.log('[Done]');
})
})
$("#button-open-access").click(function (evt) {
$.ajax({
url: evt.currentTarget.dataset.posturl,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
set_open_access: true,
},
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('Question access state changed.');
} else {
toastr.warning("Error");
toastr.info(data.status);
}
})
.fail((e) => {
toastr.warning(`Error, ${e}`);
})
.always(function () {
console.log('[Done]');
})
})
$("#button-closed-access").click(function (evt) {
$.ajax({
url: evt.currentTarget.dataset.posturl,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
set_open_access: 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('Question access state changed.');
} else {
toastr.warning("Error");
toastr.info(data.status);
}
})
.fail((e) => {
toastr.warning(`Error, ${e}`);
})
.always(function () {
console.log('[Done]');
})
})
$("#button-edit-order").click(function (evt) {
$(this).remove();
sortable('.sortable');
$("#full-question-list").after($("<button id='random-order-button'>Randomise order</button>").click(() =>{
var ul = document.getElementById("full-question-list");
for (var i = ul.children.length; i >= 0; i--) {
ul.appendChild(ul.children[Math.random() * i | 0]);
}
}))
$("#full-question-list li").each((n, el) => {
$(el).append($(
"<span class='exam-question-delete flex-col'><button>DELETE</button></span>"
).click(() => {
el.remove();
}));
})
$("#full-question-list").after($(
"<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)
})
$.ajax({
url: evt.currentTarget.dataset.posturl,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
set_exam_order: JSON.stringify(new_order),
},
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('Exam order changed.')
}
})
.always(function () {
console.log('[Done]');
})
}));
});
});
</script>