def __init__(self, vctx, location, page_desc): super(ChoiceQuestionBase, self).__init__(vctx, location, page_desc) self.correct_choice_count = 0 self.disregard_choice_count = 0 self.always_correct_choice_count = 0 for choice_idx, choice in enumerate(page_desc.choices): try: choice = str(choice) except: raise ValidationError( string_concat( "%(location)s, ", _("choice %(idx)d: unable to convert to string") ) % {'location': location, 'idx': choice_idx+1}) if choice.startswith(self.CORRECT_TAG): self.correct_choice_count += 1 if choice.startswith(self.DISREGARD_TAG): self.disregard_choice_count += 1 if choice.startswith(self.ALWAYS_CORRECT_TAG): self.always_correct_choice_count += 1 if vctx is not None: validate_markup(vctx, location, remove_prefix(self.DISREGARD_TAG, remove_prefix(self.CORRECT_TAG, remove_prefix(self.ALWAYS_CORRECT_TAG, choice))))
def __init__(self, vctx, location, page_desc): super(ChoiceQuestionBase, self).__init__(vctx, location, page_desc) self.correct_choice_count = 0 self.disregard_choice_count = 0 for choice_idx, choice in enumerate(page_desc.choices): try: choice = str(choice) except: raise ValidationError( string_concat( "%(location)s, ", _("choice %(idx)d: unable to convert to string") ) % {'location': location, 'idx': choice_idx+1}) if choice.startswith(self.CORRECT_TAG): self.correct_choice_count += 1 if choice.startswith(self.DISREGARD_TAG): self.disregard_choice_count += 1 if vctx is not None: validate_markup(vctx, location, remove_prefix(self.DISREGARD_TAG, remove_prefix(self.CORRECT_TAG, choice)))
def process_choice_string(cls, page_context, s): if not isinstance(s, str): s = str(s) s = remove_prefix(cls.CORRECT_TAG, s) s = remove_prefix(cls.DISREGARD_TAG, s) s = markup_to_html_plain(page_context, s) # allow HTML in option s = mark_safe(s) return s
def process_choice_string(cls, page_context, s): if not isinstance(s, str): s = str(s) s = remove_prefix(cls.CORRECT_TAG, s) s = remove_prefix(cls.DISREGARD_TAG, s) s = remove_prefix(cls.ALWAYS_CORRECT_TAG, s) s = markup_to_html_plain(page_context, s) # allow HTML in option s = mark_safe(s) return s
def process_choice_string(cls, page_context, s): s = remove_prefix(cls.CORRECT_TAG, s) s = markup_to_html(page_context, s) # allow HTML in option s = mark_safe(s) return s
def __init__(self, vctx, location, page_desc): super(ChoiceQuestion, self).__init__(vctx, location, page_desc) correct_choice_count = 0 for choice_idx, choice in enumerate(page_desc.choices): try: choice = str(choice) except: raise ValidationError( string_concat( "%(location)s, ", _("choice %(idx)d: unable to convert to string") ) % {'location': location, 'idx': choice_idx+1}) if choice.startswith(self.CORRECT_TAG): correct_choice_count += 1 if vctx is not None: validate_markup(vctx, location, remove_prefix(self.CORRECT_TAG, choice)) if correct_choice_count < 1: raise ValidationError( string_concat( "%(location)s: ", "one or more correct answer(s) " "expected, %(n_correct)d found") % { 'location': location, 'n_correct': correct_choice_count})
def __init__(self, vctx, location, page_desc): super(ChoiceQuestion, self).__init__(vctx, location, page_desc) correct_choice_count = 0 for choice_idx, choice in enumerate(page_desc.choices): try: choice = str(choice) except: raise ValidationError( string_concat( "%(location)s, ", _("choice %(idx)d: unable to convert to string")) % { 'location': location, 'idx': choice_idx + 1 }) if choice.startswith(self.CORRECT_TAG): correct_choice_count += 1 if vctx is not None: validate_markup(vctx, location, remove_prefix(self.CORRECT_TAG, choice)) if correct_choice_count < 1: raise ValidationError( string_concat( "%(location)s: ", _("one or more correct answer(s) " "expected, %(n_correct)d found")) % { 'location': location, 'n_correct': correct_choice_count })
def __init__(self, vctx, location, name, answers_desc): super(ChoicesAnswer, self).__init__( vctx, location, name, answers_desc) validate_struct( vctx, location, answers_desc, required_attrs=( ("type", str), ("choices", list) ), allowed_attrs=( ("weight", (int, float)), ("hint", str), ("hint_title", str), ("required", bool), ), ) self.weight = getattr(answers_desc, "weight", 0) correct_choice_count = 0 for choice_idx, choice in enumerate(answers_desc.choices): try: choice = str(choice) except Exception: raise ValidationError( string_concat( "%(location)s: '%(answer_name)s' ", _("choice %(idx)d: unable to convert to string") ) % {'location': location, 'answer_name': self.name, 'idx': choice_idx+1}) if choice.startswith(self.CORRECT_TAG): correct_choice_count += 1 if vctx is not None: validate_markup(vctx, location, remove_prefix(self.CORRECT_TAG, choice)) if correct_choice_count < 1: raise ValidationError( string_concat( "%(location)s: ", _("one or more correct answer(s) expected " " for question '%(question_name)s', " "%(n_correct)d found")) % { 'location': location, 'question_name': self.name, 'n_correct': correct_choice_count}) self.hint = getattr(self.answers_desc, "hint", "") self.width = 0
def process_choice_string(cls, page_context, s): if not isinstance(s, str): s = str(s) s = remove_prefix(cls.CORRECT_TAG, s) s_contain_p_tag = "<p>" in s s = markup_to_html(page_context, s) # allow HTML in option if not s_contain_p_tag: s = s.replace("<p>", "").replace("</p>", "") s = mark_safe(s) return s
def __init__(self, vctx, location, page_desc): super(ChoiceQuestion, self).__init__(vctx, location, page_desc) correct_choice_count = 0 for choice_idx, choice in enumerate(page_desc.choices): if not isinstance(choice, six.string_types): raise ValidationError("%s, choice %d: not a string" % (location, choice_idx+1)) if choice.startswith(self.CORRECT_TAG): correct_choice_count += 1 if vctx is not None: validate_markup(vctx, location, remove_prefix(self.CORRECT_TAG, choice)) if correct_choice_count < 1: raise ValidationError("%s: one or more correct answer(s) " "expected, %d found" % (location, correct_choice_count))
def process_choice_string(cls, s): if not isinstance(s, str): s = str(s) s = remove_prefix(cls.CORRECT_TAG, s) from course.content import markup_to_html s_contain_p_tag = "<p>" in s s = markup_to_html( course=None, repo=None, commit_sha=None, text=s, ) # allow HTML in option if not s_contain_p_tag: s = s.replace("<p>", "").replace("</p>", "") s = mark_safe(s) return s
def __init__(self, vctx, location, page_desc): super(ChoiceQuestion, self).__init__(vctx, location, page_desc) correct_choice_count = 0 for choice_idx, choice in enumerate(page_desc.choices): if not isinstance(choice, six.string_types): raise ValidationError("%s, choice %d: not a string" % (location, choice_idx + 1)) if choice.startswith(self.CORRECT_TAG): correct_choice_count += 1 if vctx is not None: validate_markup(vctx, location, remove_prefix(self.CORRECT_TAG, choice)) if correct_choice_count < 1: raise ValidationError("%s: one or more correct answer(s) " "expected, %d found" % (location, correct_choice_count))
def __init__(self, vctx, location, page_desc): validate_struct( location, page_desc, required_attrs=[ ("type", str), ("id", str), ("value", (int, float)), ("title", str), ("choices", list), ("prompt", str), ], allowed_attrs=[ ("shuffle", bool), ], ) correct_choice_count = 0 for choice in page_desc.choices: if choice.startswith(self.CORRECT_TAG): correct_choice_count += 1 if vctx is not None: validate_markup(vctx, location, remove_prefix(self.CORRECT_TAG, choice)) if correct_choice_count < 1: raise ValidationError("%s: one or more correct answer(s) " "expected, %d found" % (location, correct_choice_count)) if vctx is not None: validate_markup(vctx, location, page_desc.prompt) PageBase.__init__(self, vctx, location, page_desc.id) self.page_desc = page_desc self.shuffle = getattr(self.page_desc, "shuffle", False)