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) if HasText(profile.question): node = self._add_string_or_html(node, profile.question, "question") else: etree.SubElement(node, "question").text = profile.title if HasText(profile.description): node = self._add_string_or_html(node, profile.description, "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
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 self.include_module_description_texts and HasText( module.description): node = self._add_string_or_html(node, module.description, "description") if module.optional: etree.SubElement(node, "question").text = module.question if self.include_module_solution_texts and 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
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
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
def update(self): actions = getFactoriesInContext(self.context) if IModule.providedBy(self.context): for (i, action) in enumerate(actions): # To be able to determine what button label to display, we # explicitly set the action.id to the fake "euphorie.submodule" if action.id == "euphorie.module": actions[i] = FactoryInfo("euphorie.submodule", _(u"Submodule"), *action[2:]) break self.actions = sorted(actions, key=lambda x: x.title) self.can_edit = checkPermission(self.context, "Modify portal content")
def update(self): actions = getFactoriesInContext(self.context) if IModule.providedBy(self.context): for (i, action) in enumerate(actions): # To be able to determine what button label to display, we # explicitly set the action.id to the fake "euphorie.submodule" if action.id == "euphorie.module": actions[i] = FactoryInfo("euphorie.submodule", _("Submodule"), *action[2:]) break self.actions = sorted(actions, key=lambda x: x.title) self.can_edit = checkPermission(self.context, "Modify portal content") self.library_available = IQuestionContainer.providedBy(self.context)
def exportProfileQuestion(self, parent, profile): 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 = profile.description for child in profile.values(): if IModule.providedBy(child): self.exportModule(node, child) elif IRisk.providedBy(child): self.exportRisk(node, child) return node
def exportSurvey(self, parent, survey): """Export a survey given a parent and the survey itself :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 self.include_intro_text and StripMarkup(survey.introduction): node = self._add_string_or_html(node, survey.introduction, "introduction") if survey.classification_code: etree.SubElement( node, "classification-code").text = survey.classification_code etree.SubElement(node, "language").text = survey.language if self.is_etranslate_compatible: etree.SubElement(node, "tool_type", attrib={"value": get_tool_type(survey)}) etree.SubElement( node, "measures_text_handling", attrib={ "value": getattr(survey, "measures_text_handling", "full") }, ) etree.SubElement( node, "integrated_action_plan", attrib={ "value": "true" if getattr(survey, "integrated_action_plan", False) else "false" }, ) etree.SubElement( node, "evaluation-algorithm", attrib={"value": aq_parent(survey).evaluation_algorithm}, ) etree.SubElement( node, "evaluation-optional", attrib={ "value": "true" if survey.evaluation_optional else "false" }, ) else: etree.SubElement(node, "tool_type").text = get_tool_type(survey) etree.SubElement(node, "measures_text_handling").text = getattr( survey, "measures_text_handling", "full") etree.SubElement( node, "integrated_action_plan").text = ("true" if getattr( survey, "integrated_action_plan", False) else "false") etree.SubElement(node, "evaluation-algorithm").text = aq_parent( survey).evaluation_algorithm etree.SubElement(node, "evaluation-optional").text = ( "true" if survey.evaluation_optional else "false") if IToolCategory.providedBy(survey): tool_category = IToolCategory(survey).tool_category or [] etree.SubElement(node, "tool-category").text = ", ".join( [x.replace(",", COMMA_REPLACEMENT) for x in tool_category]) if getattr(survey, "external_site_logo", None): self.exportImage(node, survey.external_site_logo, tagname="external_site_logo") if getattr(survey, "image", None): self.exportImage(node, survey.image) for child in survey.values(): if IProfileQuestion.providedBy(child): self.exportProfileQuestion(node, child) if IModule.providedBy(child): self.exportModule(node, child) return node
def AddToTree(root, node, zodb_path=[], title=None, profile_index=0, skip_children=False): """Add a new node to the session tree. :param root: parent node of the new child :type root: py:class:`euphorie.client.model.SurveySession` or :py:class:`euphorie.client.model.SurveyTreeItem` :param node: ZODB object to add to the node. :type node: one of the :py:mod:`euphorie.content` content types :param zodb_path: list of ids of all parents of the root in the session tree :param title: title for the generated node. Defaults to the title of the ZODB object :type title: unicode or None :param int profile_index: profile answer index number. """ title = title or node.title if title: title = title[:500] if IQuestionContainer.providedBy(node): child = model.Module(title=title, module_id=node.id) child.has_description = HasText(node.description) if IModule.providedBy(node): child.solution_direction = HasText(node.solution_direction) if node.optional: child.skip_children = False child.has_description = True else: child.postponed = False elif IRisk.providedBy(node): priority = getattr(node, "default_priority", None) if priority == "none": priority = None if IFrenchRisk.providedBy(node): effect = node.default_severity else: effect = node.default_effect child = model.Risk(title=title, risk_id=node.id, risk_type=node.type, skip_evaluation=(node.evaluation_method == 'fixed'), probability=node.default_probability, frequency=node.default_frequency, effect=effect, priority=priority) child.skip_children = False child.postponed = False child.has_description = HasText(node.description) if node.type in ['top5', 'policy']: child.priority = 'high' if node.risk_always_present: child.identification = u"no" else: return None # Should never happen zodb_path = zodb_path + [node.id] child.zodb_path = "/".join(zodb_path) child.profile_index = profile_index root.addChild(child) if IQuestionContainer.providedBy(node) and not skip_children: for grandchild in node.values(): AddToTree(child, grandchild, zodb_path, None, profile_index) return child