Пример #1
0
 def compilation(self):  # prepares the answer by creating a dict
     self.dict = {
         '@fraction': self.structure['relativegrade'],
         '@format': 'html',
         'text': strtools.html(self.structure['text']),
         'feedback': {
             '@format': 'html',
             'text': strtools.html(self.structure['feedback'])
         }
     }
Пример #2
0
 def _set(self, field, value=None):
     """ Assigns a value to a field of a Question. It is stored in both .structure and .dict """
     #value = set_oparg(value, "")
     field_structure = self.structure[field]
     if value is None:  # this happens when creating a question with an empty dict
         value = self.structure[field]['default']
         field_structure['isset'] = False
     else:
         field_structure['isset'] = True
     # now 'value' has the good ... value
     field_structure['value'] = value
     if 'attribute' not in field_structure:  # no attributes, just stupid value to assign
         self.dict[field] = value
     else:  # we have "attributes" which means the field contains a "<text>" element
         if 'html' in field_structure['attribute'].values(
         ):  # the value is a string to be turned...
             value = strtools.html(
                 value
             )  # ... into a html string (tackles latex, <p>'s and stuff)
         # now we just fill the field with a text element, and its attributes
         self.dict[field] = {
             **field_structure['attribute'],
             **{
                 "text": value
             }
         }  # concatenation needs Python >= 3.5
Пример #3
0
 def compilation(
     self
 ):  # extract all the questions the Category contains, and puts it in a dict
     question_init = {
         "@type": "category",
         "category": {
             "text": "$module$/top/" + self.get_path() + self.get_name()
         },
         "info": {
             "@format": "html",
             "text": strtools.html(self.get_description())
         }
     }
     self.dict = {"quiz": {"question": [question_init]}}
     for question in self.structure['question']:
         # compiler la question ici pour créer question.dict a partir de sa structure ?
         question.compilation()
         self.dict['quiz']['question'].append(question.dict)
Пример #4
0
 def compilation(
     self
 ):  # extract all the questions the Category contains, and puts it in a dict
     question_init = {
         "@type": "category",
         "category": {
             "text": "$module$/top/" + self.get_path() + self.get_name()
         },
         "info": {
             "@format": "html",
             "text": strtools.html(self.get_description())
         }
     }
     self.dict = {"quiz": {"question": [question_init]}}
     for idx, question in enumerate(self.structure['question']):
         # here we need smarter rule for suffix because in alphabetic order gives 1, 10, 2, 3, etc
         question.namefrom(
             self,
             idx + 1)  # eventually gives a name + number to the question
         question.compilation()  # redundant with Question.addto
         self.dict['quiz']['question'].append(question.dict)