def encode_json_raw(cls, registry: Registry, data, args): result = QuizQuestion.encode_question_common(registry, data, args) result['answers'] = [{ 'comments_html': m2h(answer.get('comment', "")), 'weight': 100 if 'correct' in answer else 0, 'text': answer['correct'] if 'correct' in answer else answer['wrong'], 'html': m2h(answer['correct'] if 'correct' in answer else answer['wrong']) } for answer in data['answers']] return result
def encode_question_common(cls, registry: Registry, data, args): if 'text' in data: text = m2h(data['text']) else: text = data['question_text'] comments = data.get('comments', {}) return { 'question_name': data['title'], 'question_type': data['type'], 'question_text': text, 'points_possible': data['points'], 'correct_comments_html': m2h(comments.get("if_correct", "")), 'incorrect_comments_html': m2h(comments.get("if_incorrect", "")), 'neutral_comments_html': m2h(comments.get("always", "")), }
def encode_json_raw(cls, registry: Registry, data, args): result = QuizQuestion.encode_question_common(registry, data, args) result['answers'] = [{ 'comments_html': m2h(answer.get('comment', "")), 'text': answer['text'] } for answer in data['answers']] return result
def encode_json_raw(cls, registry: Registry, data, args): result = QuizQuestion.encode_question_common(registry, data, args) result['answers'] = [{ 'comments_html': m2h(answer.get('comment', "")), 'text': answer['text'], 'blank_id': blank_id } for blank_id, answers in data['answers'].items() for answer in answers] return result
def encode_json_raw(cls, registry: Registry, data, args): result = QuizQuestion.encode_question_common(registry, data, args) result['matching_answer_incorrect_matches'] = "\n".join( data.get('distractors', [])) result['answers'] = [{ 'comments_html': m2h(answer.get('comment', '')), 'left': answer['left'], 'right': answer['right'] } for answer in data['answers']] return result
def encode_question_by_title(cls, registry: Registry, title: str, args): local = registry.get_service(args.local_service, 'local') # TODO: By default limit search to "<Quiz> Questions/" folder? source_path = local.find_existing(registry, title, check_front_matter=True, top_directories=args.banks) decoded_markdown = local.read(source_path) regular, waltz, body = extract_front_matter(decoded_markdown) body = hide_data_in_html(regular, m2h(body)) waltz['question_text'] = body return cls.encode_question(registry, waltz, args)
def encode_json_raw(cls, registry: Registry, data, args): result = QuizQuestion.encode_question_common(registry, data, args) comments = data.get('comments', {}) result['answers'] = [{ 'comments_html': m2h(comments.get('if_true_chosen', "")), 'weight': 100 if data['answer'] else 0, 'text': 'True' }, { 'comments_html': m2h(comments.get('if_false_chosen', "")), 'weight': 100 if not data['answer'] else 0, 'text': 'False' }] return result
def encode_json_raw(cls, registry: Registry, data, args): result = QuizQuestion.encode_question_common(registry, data, args) text_mode = data['mode'] == 'text' if 'mode' in data else False result['answers'] = [] for answer in data['answers']: result_answer = { 'comments_html': m2h(answer.get('comment', "")), 'weight': 100 if 'correct' in answer else 0, 'text': answer['correct'] if 'correct' in answer else answer['wrong'], 'html': m2h(answer['correct'] if 'correct' in answer else answer['wrong']) } if text_mode: del result_answer['html'] result['answers'].append(result_answer) return result
def encode_json_raw(cls, registry: Registry, data, args): result = QuizQuestion.encode_question_common(registry, data, args) result['answers'] = [] for answer in 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'] result['answers'].append(a) return result