def from_node(cls, node: mcqnodes.mcq_choice_feedback, builder: Builder) -> "McqFeedback": """Extract data from a mcq_choice_feedback node.""" return cls( is_correct=node.get("is_correct"), text=node.astext(), html=builder.render_partial(node.children[0])["fragment"], )
def from_node(cls, node: mcqnodes.mcq, builder: Builder) -> "McqQuestion": """Extract data from an mcq node.""" # The prompt of the question is stored in mcq_body body_index = node.first_child_matching_class(mcqnodes.mcq_body) question_body = node.children[body_index] return McqQuestion( id=node.get("ids", [""])[0], text=question_body.astext(), html=builder.render_partial(question_body)["fragment"], answer=node.get("answer"), show_feedback=node.get("show_feedback"), numbered=node.get("numbered"), )
def from_node(cls, node: mcqnodes.mcq_choice, builder: Builder) -> "McqChoice": """Extract data from a mcq_choice node.""" # Find children of mcq_choice that aren't feedback. # FIXME: this is a bad idea. We should create separate node for value of # choice so we can separate it from feedback not_feedback = [ child for child in node.children if type(child) is not mcqnodes.mcq_choice_feedback ] # Create a node so we can render not_feedback nodes choice_body = nodes.container("", classes=[]) choice_body += not_feedback return cls( text=choice_body.astext(), html=builder.render_partial(choice_body)["fragment"], )