This commit is contained in:
Ross
2022-01-05 19:16:03 +00:00
parent 3977e1d792
commit 35b163a887
+24 -22
View File
@@ -77,7 +77,9 @@ class RapidForm(ModelForm):
js = ["jsi18n.js", "tesseract.min.js"]
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user') # To get request.user. Do not use kwargs.pop('user', None) due to potential security hole
self.user = kwargs.pop(
"user"
) # To get request.user. Do not use kwargs.pop('user', None) due to potential security hole
if kwargs.get("instance"):
# We get the 'initial' keyword argument or initialize it
# as a dict if it didn't exist.
@@ -115,8 +117,9 @@ class RapidForm(ModelForm):
if self.user.groups.filter(name="rapid_checker").exists():
exam_queryset = Exam.objects.all()
else:
exam_queryset = Exam.objects.filter(author__id=self.user.id) | Exam.objects.filter(open_access=True)
exam_queryset = Exam.objects.filter(
author__id=self.user.id
) | Exam.objects.filter(open_access=True)
self.fields["exams"] = ModelMultipleChoiceField(
required=False,
@@ -130,26 +133,25 @@ class RapidForm(ModelForm):
instance.save()
for exam in self.cleaned_data["exams"]:
#exam = Exam.objects.get(pk=exam_pk)
# exam = Exam.objects.get(pk=exam_pk)
exam.exam_questions.add(instance)
# # Prepare a 'save_m2m' method for the form,
# old_save_m2m = self.save_m2m
#
# def save_m2m():
# old_save_m2m()
# # This is where we actually link the pizza with toppings
# instance.exams.clear()
# for exam in self.cleaned_data["exams"]:
# instance.exams.add(exam)
#
# self.save_m2m = save_m2m
#
# # Do we need to save all changes now?
# # if commit:
# instance.save()
# self.save_m2m()
# # Prepare a 'save_m2m' method for the form,
# old_save_m2m = self.save_m2m
#
# def save_m2m():
# old_save_m2m()
# # This is where we actually link the pizza with toppings
# instance.exams.clear()
# for exam in self.cleaned_data["exams"]:
# instance.exams.add(exam)
#
# self.save_m2m = save_m2m
#
# # Do we need to save all changes now?
# # if commit:
# instance.save()
self.save_m2m()
return instance
@@ -221,4 +223,4 @@ AnswerUpdateFormSet = inlineformset_factory(
class ExamForm(ModelForm):
class Meta:
model = Exam
fields = ["name", "time_limit", "open_access", "exam_mode", "active", "archive"]
fields = ["name", "time_limit", "open_access", "exam_mode", "active", "archive"]