This commit is contained in:
Ross
2021-09-08 15:11:09 +01:00
parent c93cb8f368
commit 2ec18d6112
3 changed files with 17 additions and 1 deletions
+12
View File
@@ -468,6 +468,10 @@ class LongUpdate(RevisionMixin, LoginRequiredMixin, AuthorOrCheckerRequiredMixin
return context
def form_valid(self, form):
# save exam orders (there must be a better way to do this)
exam_orders = {}
for exam in self.object.exams.all():
exam_orders[exam] = list(exam.exam_questions.all())
self.object = form.save(commit=False)
self.object.save()
@@ -486,6 +490,14 @@ class LongUpdate(RevisionMixin, LoginRequiredMixin, AuthorOrCheckerRequiredMixin
response = super().form_valid(form)
series_formset.instance = self.object
series_formset.save()
# restore exam orders
for exam in self.object.exams.all():
if exam in exam_orders and self.object in exam_orders[exam]:
print(exam_orders[exam])
exam.exam_questions.set(exam_orders[exam])
exam.save()
return response
else:
return super().form_invalid(form)
@@ -188,6 +188,10 @@
$(this).remove();
sortable('.sortable');
$("#full-question-list li").each((n, el) => {
el.append($("<span class='exam-question-delete flex-col'>[DELETE]</span>"));
})
$("#full-question-list").append($("<button>Save exam order</button>").click(() => {
new_order = [];
$("#full-question-list li").each((n, el) => {
@@ -1,5 +1,5 @@
<div class="rapid {% if question.scrapped %}rapid-scrapped{% endif %}">
<button id="edit-button">Edit</button>
<button id="edit-button">Inline Edit</button>
<div class="date">
{{ question.created_date|date:"d/m/Y" }}
</div>