From 35b163a8877ca9a57b16396fd41ac32b91b0671b Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 5 Jan 2022 19:16:03 +0000 Subject: [PATCH] . --- rapids/forms.py | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/rapids/forms.py b/rapids/forms.py index 31f125b4..6cfb0f34 100755 --- a/rapids/forms.py +++ b/rapids/forms.py @@ -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"] \ No newline at end of file + fields = ["name", "time_limit", "open_access", "exam_mode", "active", "archive"]