.
This commit is contained in:
+24
-22
@@ -77,7 +77,9 @@ class RapidForm(ModelForm):
|
|||||||
js = ["jsi18n.js", "tesseract.min.js"]
|
js = ["jsi18n.js", "tesseract.min.js"]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
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"):
|
if kwargs.get("instance"):
|
||||||
# We get the 'initial' keyword argument or initialize it
|
# We get the 'initial' keyword argument or initialize it
|
||||||
# as a dict if it didn't exist.
|
# as a dict if it didn't exist.
|
||||||
@@ -115,8 +117,9 @@ class RapidForm(ModelForm):
|
|||||||
if self.user.groups.filter(name="rapid_checker").exists():
|
if self.user.groups.filter(name="rapid_checker").exists():
|
||||||
exam_queryset = Exam.objects.all()
|
exam_queryset = Exam.objects.all()
|
||||||
else:
|
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(
|
self.fields["exams"] = ModelMultipleChoiceField(
|
||||||
required=False,
|
required=False,
|
||||||
@@ -130,26 +133,25 @@ class RapidForm(ModelForm):
|
|||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
for exam in self.cleaned_data["exams"]:
|
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)
|
exam.exam_questions.add(instance)
|
||||||
|
|
||||||
|
# # Prepare a 'save_m2m' method for the form,
|
||||||
# # Prepare a 'save_m2m' method for the form,
|
# old_save_m2m = self.save_m2m
|
||||||
# old_save_m2m = self.save_m2m
|
#
|
||||||
#
|
# def save_m2m():
|
||||||
# def save_m2m():
|
# old_save_m2m()
|
||||||
# old_save_m2m()
|
# # This is where we actually link the pizza with toppings
|
||||||
# # This is where we actually link the pizza with toppings
|
# instance.exams.clear()
|
||||||
# instance.exams.clear()
|
# for exam in self.cleaned_data["exams"]:
|
||||||
# for exam in self.cleaned_data["exams"]:
|
# instance.exams.add(exam)
|
||||||
# instance.exams.add(exam)
|
#
|
||||||
#
|
# self.save_m2m = save_m2m
|
||||||
# self.save_m2m = save_m2m
|
#
|
||||||
#
|
# # Do we need to save all changes now?
|
||||||
# # Do we need to save all changes now?
|
# # if commit:
|
||||||
# # if commit:
|
# instance.save()
|
||||||
# instance.save()
|
self.save_m2m()
|
||||||
# self.save_m2m()
|
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
@@ -221,4 +223,4 @@ AnswerUpdateFormSet = inlineformset_factory(
|
|||||||
class ExamForm(ModelForm):
|
class ExamForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Exam
|
model = Exam
|
||||||
fields = ["name", "time_limit", "open_access", "exam_mode", "active", "archive"]
|
fields = ["name", "time_limit", "open_access", "exam_mode", "active", "archive"]
|
||||||
|
|||||||
Reference in New Issue
Block a user