def test_html2latex(self): """ We correctly translate a question to the latex equivalent. """ translation = Question2Tex.html2latex("<filetype> ?") self.assertEqual("<filetype> ?", translation) translation = Question2Tex.html2latex("Is <strong>42</strong> true ?") self.assertEqual("Is \\textbf{42} true ?", translation) translation = Question2Tex.html2latex("<code>is(this).sparta</code>?") self.assertEqual("$is(this).sparta$?", translation)
def get_caption_specifics(self): caption = "%s '%s' (%s) " % ( _("for the question"), Question2Tex.html2latex(self.question.text), _("left"), ) caption += "%s '%s' (%s) " % ( _("in relation with the question"), Question2Tex.html2latex(self.other_question.text), _("right"), ) return caption
def treat_question(self, question): LOGGER.info("Treating, %s %s", question.pk, question.text) options = self.tconf.get(survey_name=self.survey.name, question_text=question.text) multiple_charts = options.get("multiple_charts") if not multiple_charts: multiple_charts = {"": options.get("chart")} question_synthesis = "" i = 0 for chart_title, opts in list(multiple_charts.items()): i += 1 if chart_title: # "" is False, by default we do not add section or anything mct = options["multiple_chart_type"] question_synthesis += "\\%s{%s}" % (mct, chart_title) tex_type = opts.get("type") if tex_type == "raw": question_synthesis += Question2TexRaw(question, **opts).tex() elif tex_type == "sankey": other_question_text = opts["question"] other_question = Question.objects.get(text=other_question_text) q2tex = Question2TexSankey(question, other_question=other_question) question_synthesis += q2tex.tex() elif tex_type in ["pie", "cloud", "square", "polar"]: q2tex = Question2TexChart(question, latex_label=i, **opts) question_synthesis += q2tex.tex() elif locate(tex_type) is None: msg = "{} '{}' {}".format( _("We could not render a chart because the type"), tex_type, _( "is not a standard type nor the path to an " "importable valid Question2Tex child class. " "Choose between 'raw', 'sankey', 'pie', 'cloud', " "'square', 'polar' or 'package.path.MyQuestion2Tex" "CustomClass'" ), ) LOGGER.error(msg) question_synthesis += msg else: q2tex_class = locate(tex_type) # The use will probably know what type he should use in his # custom class opts["type"] = None q2tex = q2tex_class(question, latex_label=i, **opts) question_synthesis += q2tex.tex() section_title = Question2Tex.html2latex(question.text) return """ \\clearpage{} \\section{%s} \\label{sec:%s} %s """ % ( section_title, question.pk, question_synthesis, )
def treat_question(self, question, survey): LOGGER.info("Treating, %s %s", question.pk, question.text) options = self.tconf.get(survey_name=self.survey.name, question_text=question.text) multiple_charts = options.get("multiple_charts") if not multiple_charts: multiple_charts = {"": options.get("chart")} question_synthesis = "" i = 0 for chart_title, opts in multiple_charts.items(): i += 1 if chart_title: # "" is False, by default we do not add section or anything mct = options["multiple_chart_type"] question_synthesis += "\%s{%s}" % (mct, chart_title) tex_type = opts.get("type") if tex_type == "raw": question_synthesis += Question2TexRaw(question, **opts).tex() elif tex_type == "sankey": other_question_text = opts["question"] other_question = Question.objects.get(text=other_question_text) q2tex = Question2TexSankey(question) question_synthesis += q2tex.tex(other_question) elif tex_type in ["pie", "cloud", "square", "polar"]: q2tex = Question2TexChart(question, latex_label=i, **opts) question_synthesis += q2tex.tex() elif locate(tex_type) is None: msg = "{} '{}' {}".format( _("We could not render a chart because the type"), tex_type, _("is not a standard type nor the path to an " "importable valid Question2Tex child class. " "Choose between 'raw', 'sankey', 'pie', 'cloud', " "'square', 'polar' or 'package.path.MyQuestion2Tex" "CustomClass'") ) LOGGER.error(msg) question_synthesis += msg else: q2tex_class = locate(tex_type) # The use will probably know what type he should use in his # custom class opts["type"] = None q2tex = q2tex_class(question, latex_label=i, **opts) question_synthesis += q2tex.tex() section_title = Question2Tex.html2latex(question.text) return u""" \\clearpage{} \\section{%s} \label{sec:%s} %s """ % (section_title, question.pk, question_synthesis)
def get_caption_specifics(self): return "%s '%s' " % (_("for the question"), Question2Tex.html2latex(self.question.text))