def get_html(self): """ Main method called externally to get the HTML to be rendered for this capa Problem. """ self.do_targeted_feedback(self.tree) html = contextualize_text(etree.tostring(self._extract_html(self.tree)), self.context) return html
def get_html(self): ''' Main method called externally to get the HTML to be rendered for this capa Problem. ''' html = contextualize_text( etree.tostring(self._extract_html(self.tree)), self.context) return html
def test_contextualize_text(self, context_value): """Verify that variable substitution works as intended with non-ascii characters.""" key = 'answer0' text = '$answer0' context = {key: context_value} contextual_text = contextualize_text(text, context) assert context_value == contextual_text
def test_contextualize_text_with_non_ascii_context(self): """Verify that variable substitution works as intended with non-ascii characters.""" key = 'あなた$a $b' text = '$' + key context = {'a': 'あなたあなたあなた', 'b': 'あなたhi'} expected_text = '$あなたあなたあなたあなた あなたhi' contextual_text = contextualize_text(text, context) assert expected_text == contextual_text
def get_html(self): """ Main method called externally to get the HTML to be rendered for this capa Problem. """ self.do_targeted_feedback(self.tree) html = contextualize_text( etree.tostring(self._extract_html(self.tree)).decode('utf-8'), self.context, six.text_type(self.capa_module.location) ) return html
def get_question_answers(self): """ Returns a dict of answer_ids to answer values. If we cannot generate an answer (this sometimes happens in customresponses), that answer_id is not included. Called by "show answers" button JSON request (see capa_module) """ # dict of (id, correct_answer) answer_map = dict() for response in self.responders.keys(): results = self.responder_answers[response] answer_map.update(results) # include solutions from <solution>...</solution> stanzas for entry in self.tree.xpath("//" + "|//".join(solution_tags)): answer = etree.tostring(entry) if answer: answer_map[entry.get("id")] = contextualize_text(answer, self.context) log.debug("answer_map = %s", answer_map) return answer_map
def get_question_answers(self): """ Returns a dict of answer_ids to answer values. If we cannot generate an answer (this sometimes happens in customresponses), that answer_id is not included. Called by "show answers" button JSON request (see capa_module) """ # dict of (id, correct_answer) answer_map = dict() for response in self.responders.keys(): results = self.responder_answers[response] answer_map.update(results) # include solutions from <solution>...</solution> stanzas for entry in self.tree.xpath("//" + "|//".join(solution_tags)): answer = etree.tostring(entry).decode('utf-8') if answer: answer_map[entry.get('id')] = contextualize_text(answer, self.context) log.debug('answer_map = %s', answer_map) return answer_map
def get_question_answers(self): """ Returns a dict of answer_ids to answer values. If we cannot generate an answer (this sometimes happens in customresponses), that answer_id is not included. Called by "show answers" button JSON request (see capa_module) """ # dict of (id, correct_answer) answer_map = dict() for response in self.responders.keys(): results = self.responder_answers[response] # escape dict value, without <b>*</b> html tag for (k, v) in results.iteritems(): if isinstance(v, basestring): bold_tag_regex = r"(<b>.*?</b>)" if re.search(bold_tag_regex, v): escaped_strings = [] for splited_string in re.split(bold_tag_regex, v): if not re.search(bold_tag_regex, splited_string): splited_string = escape(splited_string) escaped_strings.append(splited_string) results[k] = ''.join(escaped_strings) else: results[k] = escape(v) answer_map.update(results) # include solutions from <solution>...</solution> stanzas for entry in self.tree.xpath("//" + "|//".join(solution_tags)): answer = etree.tostring(entry) if answer: answer_map[entry.get('id')] = contextualize_text( answer, self.context) log.debug('answer_map = %s', answer_map) return answer_map
def get_html(self): ''' Main method called externally to get the HTML to be rendered for this capa Problem. ''' html = contextualize_text(etree.tostring(self._extract_html(self.tree)), self.context) return html