Esempio n. 1
0
 def _custom_from_disk(cls, yaml_data):
     yaml_data['answers'] = [{
         'comments_html':
         m2h(answer.get('comment', "")),
         'weight':
         100 if 'correct' in answer else 0,
         'html':
         m2h(answer['correct'] if 'correct' in answer else answer['wrong'])
     } for answer in yaml_data['answers']]
     return yaml_data
Esempio n. 2
0
 def from_disk(cls, course, yaml_data, resource_id):
     # Fix configuration on simpler attributes
     yaml_data['description'] = m2h(yaml_data['description'])
     yaml_data['settings'].update(yaml_data['settings'].pop('timing'))
     yaml_data['settings'].update(yaml_data['settings'].pop('secrecy'))
     yaml_data.update(yaml_data.pop('settings'))
     yaml_data.setdefault('access_code', '')
     yaml_data.setdefault('ip_filter', '')
     yaml_data['html_url'] = yaml_data.pop('url')
     yaml_data['due_at'] = from_friendly_date(yaml_data['due_at'])
     yaml_data['unlock_at'] = from_friendly_date(yaml_data['unlock_at'])
     yaml_data['lock_at'] = from_friendly_date(yaml_data['lock_at'])
     # Load in the questions
     groups = yaml_data.pop('groups')
     groups = [
         QuizGroup.from_disk(course, group, resource_id) for group in groups
     ]
     questions = yaml_data.pop('questions')
     questions = [
         QuizQuestion.from_disk(course, question, resource_id)
         for question in questions
     ]
     return cls(**yaml_data,
                questions=questions,
                groups=groups,
                course=course)
Esempio n. 3
0
 def _custom_from_disk(cls, yaml_data):
     yaml_data['answers'] = [{
         'comments_html': m2h(answer.get('comment', "")),
         'text': answer['text'],
         'blank_id': blank_id
     } for blank_id, answers in yaml_data['answers'].items()
                             for answer in answers]
     return yaml_data
Esempio n. 4
0
 def _custom_from_disk(cls, yaml_data):
     yaml_data['answers'] = [{
         'comments_html':
         m2h(yaml_data.get('true_comment', "")),
         'weight':
         100 if yaml_data['answer'] else 0,
         'text':
         'True'
     }, {
         'comments_html':
         m2h(yaml_data.get('false_comment', "")),
         'weight':
         100 if not yaml_data['answer'] else 0,
         'text':
         'False'
     }]
     return yaml_data
Esempio n. 5
0
 def from_disk(cls, course, yaml_data, resource_id):
     question_type = yaml_data['question_type']
     actual_class = QUESTION_TYPES[question_type]
     yaml_data['question_text'] = m2h(yaml_data['question_text'])
     # Fix simplifications of comments
     for label in [
             'correct_comments', 'incorrect_comments', 'neutral_comments'
     ]:
         yaml_data[label + "_html"] = m2h(yaml_data.pop(label, ""))
     yaml_data['quiz_group_id'] = yaml_data.pop('group', None)
     # Fix answers
     actual_class._custom_from_disk(yaml_data)
     # Load the appropriate type
     if isinstance(yaml_data, str):
         return QuizQuestion.by_name(yaml_data['question_name'], course)
     else:
         return actual_class(course=course, **yaml_data)
Esempio n. 6
0
 def _custom_from_disk(cls, yaml_data):
     yaml_data['matching_answer_incorrect_matches'] = yaml_data.pop(
         'incorrect_matches', '')
     yaml_data['answers'] = [{
         'comments_html': m2h(answer.get('comment', '')),
         'left': answer['left'],
         'right': answer['right']
     } for answer in yaml_data['answers']]
     return yaml_data
Esempio n. 7
0
 def from_disk(cls, course, yaml_data, resource_id):
     # Fix configuration on simpler attributes
     yaml_data['description'] = m2h(yaml_data['description'])
     yaml_data['settings'].update(yaml_data['settings'].pop('timing'))
     yaml_data['settings'].update(yaml_data['settings'].pop('secrecy'))
     yaml_data['settings'].update(yaml_data['settings'].pop('submission'))
     yaml_data.update(yaml_data.pop('settings'))
     yaml_data['due_at'] = from_friendly_date(yaml_data['due_at'])
     yaml_data['unlock_at'] = from_friendly_date(yaml_data['unlock_at'])
     yaml_data['lock_at'] = from_friendly_date(yaml_data['lock_at'])
     yaml_data['html_url'] = yaml_data.pop('url')
     return cls(**yaml_data, course=course)
Esempio n. 8
0
 def _custom_from_disk(cls, yaml_data):
     yaml_data['answers'] = [{
         'comments_html':
         m2h(answer.get('comment', "")),
         'text':
         answer['correct'] if 'correct' in answer else answer['wrong'],
         'weight':
         100 if 'correct' in answer else 0,
         'blank_id':
         blank_id
     } for blank_id, answers in yaml_data['answers'].items()
                             for answer in answers]
     return yaml_data
Esempio n. 9
0
 def _custom_from_disk(cls, yaml_data):
     answers = []
     for answer in yaml_data['answers']:
         numerical_answer_type = (
             'exact_answer' if 'exact' in answer else
             'range_answer' if 'start' in answer else 'precision_answer')
         a = {
             'comments_html': m2h(answer.get('comment', "")),
             'numerical_answer_type': numerical_answer_type
         }
         if numerical_answer_type == 'exact_answer':
             a['exact'] = answer['exact']
             a['margin'] = answer.get('margin', 0)
         elif numerical_answer_type == 'range_answer':
             a['start'] = answer['start']
             a['end'] = answer['end']
         elif numerical_answer_type == 'precision_answer':
             a['precision'] = answer['precision']
             a['approximate'] = answer['approximate']
         answers.append(a)
     yaml_data['answers'] = answers
     return yaml_data
Esempio n. 10
0
 def _custom_from_disk(cls, yaml_data):
     yaml_data['answers'] = [{
         'comments_html': m2h(answer.get('comment', "")),
         'text': answer['text']
     } for answer in yaml_data['answers']]
     return yaml_data
Esempio n. 11
0
 def from_disk(cls, course, resource_data, resource_id):
     # Fix configuration on simpler attributes
     return cls(body=m2h(resource_data),
                course=course,
                title=resource_id.canvas_title)