This commit is contained in:
Ross
2021-02-23 21:12:50 +00:00
parent 38a2165893
commit 7f4dbfec51
12 changed files with 153 additions and 24 deletions
+2
View File
@@ -57,6 +57,8 @@ class AnatomyQuestionTable(tables.Table):
)
exams = tables.ManyToManyColumn(verbose_name="Exams")
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
class Meta:
model = AnatomyQuestion
template_name = "django_tables2/bootstrap4.html"
+34 -2
View File
@@ -16,10 +16,10 @@
</div>
<p><a href="{% url 'anatomy:mark_overview' pk=exam.pk %}"><button>Mark exam</button></a></p>
<ol id="full-question-list">
<ol id="full-question-list" class="sortable">
{% for question in questions.all %}
<li>
<li data-question_pk={{question.pk}}>
<img src="{{ question.image|thumbnail_url:'exam-list' }}" alt="thumbail" />
{{ question.description }}
<br />
@@ -33,6 +33,7 @@
<a href="{% url 'anatomy:exam_json_recreate' pk=exam.pk %}">Refresh JSON cache</a>
<button id='button-open-access'>Make questions open access</button>
<button id='button-closed-access'>Make questions closed access</button>
<button id='button-edit-order'>Edit exam order</button>
</div>
<script type="text/javascript">
@@ -130,6 +131,37 @@
console.log('[Done]');
})
})
$("#button-edit-order").click(function () {
$(this).remove();
sortable('.sortable');
$("#full-question-list").append($("<button>Save exam order</button>").click(() => {
new_order = [];
$("#full-question-list li").each((n, el) => {
new_order.push(el.dataset.question_pk)
})
$.ajax({
url: "{% url 'anatomy:exam_json_edit' pk=exam.pk %}",
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>
{% endblock %}
+1 -1
View File
@@ -953,7 +953,7 @@ def question_save_annotation(request, pk):
return JsonResponse(data, status=400)
AnatomyExamViews = ExamViews(Exam, "anatomy", "anatomy", loadJsonAnswer)
AnatomyExamViews = ExamViews(Exam, AnatomyQuestion, "anatomy", "anatomy", loadJsonAnswer)
class UserAnswerDelete(SuperuserRequiredMixin, DeleteView):
model = CidUserAnswer
+36 -12
View File
@@ -24,6 +24,9 @@ from .forms import (
from .models import Examination
from django.db.models import Case, When
# Create your views here.
@login_required
def create_examination(request):
@@ -52,8 +55,9 @@ def get_examination_id(request):
class ExamViews(View, LoginRequiredMixin):
def __init__(self, exam, app, question_type, loadJsonAnswer):
def __init__(self, exam, question, app, question_type, loadJsonAnswer):
self.Exam = exam
self.Question = question
self.app_name = app
self.question_type = question_type
self.loadJsonAnswer = loadJsonAnswer
@@ -127,19 +131,39 @@ class ExamViews(View, LoginRequiredMixin):
exam = get_object_or_404(self.Exam, pk=pk)
if request.POST.get("set_open_access") == "true":
state = True
else:
state = False
if "set_open_access" in request.POST:
if request.POST.get("set_open_access") == "true":
state = True
else:
state = False
questions_changed = []
for q in exam.exam_questions.all():
q.open_access = state
q.save()
questions_changed.append(q.pk)
questions_changed = []
for q in exam.exam_questions.all():
q.open_access = state
q.save()
questions_changed.append(q.pk)
data = {"status": "success", "questions": questions_changed, "state": state}
return JsonResponse(data, status=200)
data = {"status": "success", "questions": questions_changed, "state": state}
return JsonResponse(data, status=200)
if "set_exam_order" in request.POST:
new_order = json.loads(request.POST.get("set_exam_order"))
preserved = Case(*[When(pk=pk, then=pos) for pos, pk in enumerate(new_order)])
objects = self.Question.objects.filter(pk__in=new_order).order_by(preserved)
if len(objects) != exam.exam_questions.count():
data = {"status": "error, count does not match"}
return JsonResponse(data, status=400)
exam.exam_questions.set(objects)
exam.save()
data = {"status": "success"}
return JsonResponse(data, status=200)
data = {"status": "error, unknown request"}
return JsonResponse(data, status=400)
else:
data = {"status": "error"}
return JsonResponse(data, status=400)
+3
View File
@@ -65,6 +65,8 @@ class LongTable(tables.Table):
#series = tables.ManyToManyColumn(verbose_name="Exams")
exams = tables.ManyToManyColumn(verbose_name="Exams")
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
class Meta:
model = Long
template_name = "django_tables2/bootstrap4.html"
@@ -99,6 +101,7 @@ class LongSeriesTable(tables.Table):
delete = tables.LinkColumn(
"longs:long_series_delete", text="Delete", args=[A("pk")], orderable=False
)
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
class Meta:
model = LongSeries
+34 -2
View File
@@ -17,10 +17,10 @@
</div>
<p><a href="{% url 'longs:mark_overview' pk=exam.pk %}"><button>Mark exam</button></a></p>
<ol id="full-question-list">
<ol id="full-question-list" class="sortable">
{% for question in questions.all %}
<li data-question-id={{question.pk}}>
<li data-question_pk={{question.pk}}>
History: {{ question.history}}
<br />
{% for series in question.series.all %}
@@ -44,6 +44,7 @@
<a href="{% url 'longs:exam_json_recreate' pk=exam.pk %}">Refresh JSON cache</a>
<button id='button-open-access'>Make questions open access</button>
<button id='button-closed-access'>Make questions closed access</button>
<button id='button-edit-order'>Edit exam order</button>
</div>
<script type="text/javascript">
@@ -141,6 +142,37 @@
console.log('[Done]');
})
})
$("#button-edit-order").click(function () {
$(this).remove();
sortable('.sortable');
$("#full-question-list").append($("<button>Save exam order</button>").click(() => {
new_order = [];
$("#full-question-list li").each((n, el) => {
new_order.push(el.dataset.question_pk)
})
$.ajax({
url: "{% url 'longs:exam_json_edit' pk=exam.pk %}",
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>
{% endblock %}
+1 -1
View File
@@ -931,4 +931,4 @@ def exam_scores_cid_user(request, pk, sk):
)
LongExamViews = ExamViews(Exam, "longs", "long", loadJsonAnswer)
LongExamViews = ExamViews(Exam, Long, "longs", "long", loadJsonAnswer)
+1 -1
View File
@@ -285,4 +285,4 @@ def loadJsonAnswer(answer):
return True
PhysicsExamViews = ExamViews(Exam, "physics", "physics", loadJsonAnswer)
PhysicsExamViews = ExamViews(Exam, Question, "physics", "physics", loadJsonAnswer)
+2
View File
@@ -44,6 +44,8 @@ class RapidTable(tables.Table):
orderable=False)
images = ImageColumn("images", orderable=False)
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
class Meta:
model = Rapid
template_name = "django_tables2/bootstrap4.html"
+36 -2
View File
@@ -16,10 +16,10 @@
</div>
<p><a href="{% url 'rapids:mark_overview' pk=exam.pk %}"><button>Mark exam</button></a></p>
<ol id="full-question-list">
<ol id="full-question-list" class="sortable">
{% for question in questions.all %}
<li>
<li data-question_pk={{question.pk}}>
{% for image in question.GetImages %}
<img src="{{ image|thumbnail_url:'exam-list' }}" alt="thumbail" />
{% endfor %}
@@ -39,6 +39,7 @@
<a href="{% url 'rapids:exam_json_recreate' pk=exam.pk %}">Refresh JSON cache</a>
<button id='button-open-access'>Make questions open access</button>
<button id='button-closed-access'>Make questions closed access</button>
<button id='button-edit-order'>Edit exam order</button>
</div>
<script type="text/javascript">
@@ -136,6 +137,39 @@
console.log('[Done]');
})
})
$("#button-edit-order").click(function () {
$(this).remove();
sortable('.sortable');
$("#full-question-list").append($("<button>Save exam order</button>").click(() => {
new_order = [];
$("#full-question-list li").each((n, el) => {
new_order.push(el.dataset.question_pk)
})
$.ajax({
url: "{% url 'rapids:exam_json_edit' pk=exam.pk %}",
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>
{% endblock %}
+2 -2
View File
@@ -7,10 +7,10 @@
Edit</a>
{% if question.normal %}
<h3>This question is normal</h3>
Answers will be automatically marked.<br/>
Answers will be automatically marked.
{% else %}
<h3>This question is abnormal</h3>
Answers marked as normal will be automatically marked.
Answers marked as normal will be automatically marked.<br/>
Region: {{ question.get_regions }}, Abnormalities: {{ question.get_abnormalities }}
{% endif %}
<div id="single-dicom-viewer" class="marking-dicom" data-images="{{question.GetImageUrls}}"
+1 -1
View File
@@ -875,4 +875,4 @@ class QuestionDelete(AuthorOrCheckerRequiredMixin, DeleteView):
model = Rapid
success_url = reverse_lazy("rapids:rapid_view")
RapidExamViews = ExamViews(Exam, "rapids", "rapid", loadJsonAnswer)
RapidExamViews = ExamViews(Exam, Rapid, "rapids", "rapid", loadJsonAnswer)