append_forms question instance answer request request view self Questi

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
append_forms(question, instance=answer, request=request, view=self)
QuestionExtender(question, data, files, instance, request, view=self).extend_question()
class QuestionExtender(object):
def __init__(self, question, data=None, files=None, instance=None, request=None, view=None):
self.question = question
self.data = data
self.files = files
self.instance = instance
self.request = request
self.view = view
def extend_math_question(self):
question = self.question
question.form = QuestionAnswerMathForm(
question,
exam_event=self.view.object
data=self.data,
files=self.files,
instance=self.instance
)
class QuestionAnswerMathForm(forms.ModelForm, PlaceholderMixin):
class Meta:
model = QuestionAnswer
fields = ['id', 'text_answer']
def __init__(self, question, exam_event, *args, **kwargs):
super(QuestionAnswerMathForm, self).__init__(
prefix=question.id, *args, **kwargs)
# some code ...
configure_froala_plugins_for_safe_exams(exam_event, text_answer_options)
self.fields['text_answer'].widget.options = text_answer_options