示例#1
0
 def encode_json(cls, registry: Registry, data: str, args):
     regular, waltz, body = extract_front_matter(data)
     settings = waltz.get('settings', {})
     submission = settings.get('submission', {})
     timing = settings.get('timing', {})
     secrecy = settings.get('secrecy', {})
     body = hide_data_in_html(regular, m2h(body))
     return json.dumps({
         'name': waltz['title'],
         'description': body,
         'html_url': waltz['url'],
         'published': waltz['published'],
         # General settings
         'points_possible': settings['points_possible'],
         'grading_type': settings['grading_type'],
         # Submissions
         'allowed_extensions': submission.get('allowed_extensions'),
         'submission_types': submission['submission_types'],
         # Timing
         'due_at': from_friendly_date(timing['due_at']),
         'unlock_at': from_friendly_date(timing['unlock_at']),
         'lock_at': from_friendly_date(timing['lock_at']),
         # Secrecy
         'anonymize_students': secrecy['anonymize_students'],
         'anonymous_grading': secrecy['anonymous_grading']
     })
示例#2
0
 def encode_json(cls, registry: Registry, data: str, args):
     regular, waltz, body = extract_front_matter(data)
     body = hide_data_in_html(regular, m2h(body))
     return json.dumps({
         'title': waltz['title'],
         'published': waltz['published'],
         'body': body
         # TODO: Other fields
     })
示例#3
0
 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)
示例#4
0
文件: quiz.py 项目: bedmison/waltz
 def encode_json(cls, registry: Registry, data, args):
     regular, waltz, body = extract_front_matter(data)
     settings = waltz.get('settings', {})
     timing = settings.get('timing', {})
     secrecy = settings.get('secrecy', {})
     body = hide_data_in_html(regular, m2h(body))
     questions = []
     groups = {}
     for question in waltz.get('questions', []):
         if isinstance(question, str):
             # Look up quiz question name
             questions.append(
                 QuizQuestion.encode_question_by_title(
                     registry, question, args))
         elif 'group' in question:
             # This is a question group
             group = QuizGroup.encode_group(registry, question, args)
             groups[group['name']] = group
             questions.extend(
                 QuizGroup.encode_questions(registry, question, args))
         else:
             # This is an embedded question
             questions.append(
                 QuizQuestion.encode_question(registry, question, args))
     # TODO: total_estimated_points from the questions
     return json.dumps({
         'title':
         waltz['title'],
         'published':
         waltz.get('published', False),
         'description':
         body,
         # Settings
         'quiz_type':
         settings.get('quiz_type', 'assignment'),
         'points_possible':
         settings.get('points_possible'),
         'allowed_attempts':
         settings.get('allowed_attempts'),
         'scoring_policy':
         settings.get('scoring_policy'),
         # Timing
         'due_at':
         from_friendly_date(timing.get('due_at')),
         'unlock_at':
         from_friendly_date(timing.get('unlock_at')),
         'lock_at':
         from_friendly_date(timing.get('lock_at')),
         # Secrecy
         'one_question_at_a_time':
         int(secrecy.get('one_question_at_a_time', 0)),
         'shuffle_answers':
         int(secrecy.get('shuffle_answers', 0)),
         'time_limit':
         secrecy.get('time_limit'),
         'cant_go_back':
         int(secrecy.get('cant_go_back', 0)),
         'show_correct_answers':
         int(secrecy.get('show_correct_answers', 1)),
         'show_correct_answers_last_attempt':
         secrecy.get('show_correct_answers_last_attempt'),
         'show_correct_answers_at':
         secrecy.get('show_correct_answers_at'),
         'hide_correct_answers_at':
         secrecy.get('hide_correct_answers_at'),
         'hide_results':
         secrecy.get('hide_results'),
         'one_time_results':
         int(secrecy.get('one_time_results', 0)),
         'access_code':
         secrecy.get('access_code'),
         'ip_filter':
         secrecy.get('ip_filter'),
         # Questions and Groups
         'questions':
         questions,
         'groups':
         groups
     })