コード例 #1
0
ファイル: export.py プロジェクト: EU-OSHA/Euphorie
    def exportModule(self, parent, module):
        """ :returns: An XML node with the details of an :obj:`euphorie.content.module`.
        """
        node = etree.SubElement(
            parent, "module", optional="true" if module.optional else "false")
        if getattr(module, "external_id", None):
            node.attrib["external-id"] = module.external_id
        etree.SubElement(node, "title").text = module.title
        if HasText(module.description):
            etree.SubElement(node, "description").text = StripUnwanted(
                module.description)
        if module.optional:
            etree.SubElement(node, "question").text = module.question
        if StripMarkup(module.solution_direction):
            etree.SubElement(node, "solution-direction").text = StripUnwanted(
                module.solution_direction)
        if module.image is not None:
            self.exportImage(node, module.image, module.caption)

        for child in module.values():
            if IModule.providedBy(child):
                self.exportModule(node, child)
            elif IRisk.providedBy(child):
                self.exportRisk(node, child)
        return node
コード例 #2
0
ファイル: export.py プロジェクト: EU-OSHA/Euphorie
    def exportRisk(self, parent, risk):
        """ :returns: An XML node with the details of an :obj:`euphorie.content.risk`.
        """
        node = etree.SubElement(parent, "risk", type=risk.type)
        if getattr(risk, "external_id", None):
            node.attrib["external-id"] = risk.external_id
        etree.SubElement(node, "title").text = risk.title
        etree.SubElement(node, "problem-description").text = StripUnwanted(
            risk.problem_description)
        etree.SubElement(node,
                         "description").text = StripUnwanted(risk.description)
        if StripMarkup(risk.legal_reference):
            etree.SubElement(node, "legal-reference").text = StripUnwanted(
                risk.legal_reference)
        etree.SubElement(node, "show-not-applicable").text = \
                "true" if risk.show_notapplicable else "false"
        if self.use_existing_measures:
            etree.SubElement(node, "existing_measures").text = \
                risk.existing_measures
        if risk.type == "risk":
            method = etree.SubElement(node, "evaluation-method")
            method.text = risk.evaluation_method
            if risk.evaluation_method == "calculated":
                if risk.evaluation_algorithm() == "kinney":
                    if risk.default_probability:
                        method.attrib["default-probability"] = getToken(
                            IKinneyEvaluation["default_probability"],
                            risk.default_probability)
                    if risk.default_frequency:
                        method.attrib["default-frequency"] = getToken(
                            IKinneyEvaluation["default_frequency"],
                            risk.default_frequency)
                    if risk.default_effect:
                        method.attrib["default-effect"] = getToken(
                            IKinneyEvaluation["default_effect"],
                            risk.default_effect)
            elif risk.evaluation_method == "direct":
                if risk.default_priority:
                    method.attrib["default-priority"] = getToken(
                        IRisk["default_priority"], risk.default_priority)

        for index in range(4):
            postfix = "" if not index else str(index + 1)
            image = getattr(risk, "image" + postfix, None)
            if image is not None:
                self.exportImage(node, image,
                                 getattr(risk, "caption" + postfix, None))

        solutions = [
            child for child in risk.values() if ISolution.providedBy(child)
        ]
        if solutions:
            sols = etree.SubElement(node, "solutions")
            for solution in solutions:
                self.exportSolution(sols, solution)
        return node
コード例 #3
0
ファイル: export.py プロジェクト: EU-OSHA/Euphorie
    def exportSurvey(self, parent, survey):
        """ :returns: An XML node with the details of an :obj:`euphorie.content.survey`.
        """
        node = etree.SubElement(parent, "survey")
        if getattr(survey, "external_id", None):
            node.attrib["external-id"] = survey.external_id
        etree.SubElement(node, "title").text = aq_parent(survey).title
        if StripMarkup(survey.introduction):
            etree.SubElement(node, "introduction").text = StripUnwanted(
                survey.introduction)
        if survey.classification_code:
            etree.SubElement(node, "classification-code").text = \
                    survey.classification_code
        etree.SubElement(node, "language").text = survey.language
        etree.SubElement(node, "evaluation-algorithm").text = \
                aq_parent(survey).evaluation_algorithm
        etree.SubElement(node, "evaluation-optional").text = \
                "true" if survey.evaluation_optional else "false"

        for child in survey.values():
            if IProfileQuestion.providedBy(child):
                self.exportProfileQuestion(node, child)
            if IModule.providedBy(child):
                self.exportModule(node, child)
        return node
コード例 #4
0
ファイル: export.py プロジェクト: EU-OSHA/Euphorie
    def exportProfileQuestion(self, parent, profile):
        """ :returns: An XML node with the details of an :obj:`euphorie.content.profilequestion`.
        """
        node = etree.SubElement(parent, "profile-question")
        if getattr(profile, "external_id", None):
            node.attrib["external-id"] = profile.external_id
        etree.SubElement(node, "title").text = profile.title
        # Use title if question is not available (Euphorie < 2.0rc2 data)
        etree.SubElement(node, "question").text = \
                profile.question or profile.title
        if HasText(profile.description):
            etree.SubElement(node, "description").text = StripUnwanted(
                profile.description)

        for fname in ProfileQuestionLocationFields:
            value = getattr(profile, fname, None)
            if value:
                etree.SubElement(node, fname.replace('_', '-')).text = value

        etree.SubElement(node, "use-location-question").text = \
                "true" if getattr(profile, "use_location_question", True) else "false"

        for child in profile.values():
            if IModule.providedBy(child):
                self.exportModule(node, child)
            elif IRisk.providedBy(child):
                self.exportRisk(node, child)
        return node
コード例 #5
0
 def _add_string_or_html(self, node, text, element):
     stripped_text = StripUnwanted(text)
     if self.is_etranslate_compatible:
         html_fragment = html.fragment_fromstring(stripped_text, element)
         node.append(html_fragment)
     else:
         etree.SubElement(node, element).text = stripped_text
     return node
コード例 #6
0
ファイル: export.py プロジェクト: EU-OSHA/Euphorie
 def exportSolution(self, parent, solution):
     """ :returns: An XML node with the details of an :obj:`euphorie.content.solution`.
     """
     node = etree.SubElement(parent, "solution")
     if getattr(solution, "external_id", None):
         node.attrib["external-id"] = solution.external_id
     etree.SubElement(node, "description").text = StripUnwanted(
         solution.description)
     etree.SubElement(node, "action-plan").text = StripUnwanted(
         solution.action_plan)
     if solution.prevention_plan:
         etree.SubElement(node, "prevention-plan").text = StripUnwanted(
             solution.prevention_plan)
     if solution.requirements:
         etree.SubElement(node, "requirements").text = StripUnwanted(
             solution.requirements)
     return node
コード例 #7
0
 def exportSolution(self, parent, solution):
     """:returns: An XML node with the details
     of an :obj:`euphorie.content.solution`."""
     node = etree.SubElement(parent, "solution")
     if getattr(solution, "external_id", None):
         node.attrib["external-id"] = solution.external_id
     etree.SubElement(node, "description").text = StripUnwanted(
         solution.description)
     stripped_action = StripUnwanted(solution.action)
     if ISolution.providedBy(solution) and self.is_etranslate_compatible:
         solution_view = api.content.get_view(context=solution,
                                              name="nuplone-view",
                                              request=self.request)
         action_with_br = stripped_action.replace("\n", "<br/>")
         action_html = solution_view.render_md(action_with_br)
         fragment = html.fragment_fromstring(action_html, "action")
         node.append(fragment)
     else:
         etree.SubElement(node, "action").text = stripped_action
     if solution.requirements:
         etree.SubElement(node, "requirements").text = StripUnwanted(
             solution.requirements)
     return node