Example #1
0
def set_evaluation_method_interfaces(context):
    ct = getToolByName(context, "portal_catalog")
    risks = ct(portal_type="euphorie.risk")
    count = 0
    for brain in risks:
        log.debug("Updating interfaces for %s", brain.getPath())
        risk = brain.getObject()
        EnsureInterface(risk)
        count += 1
    log.info("Updated interfaces for %d risks", count)
Example #2
0
 def createRisk(self, algorithm="kinney"):
     country = self.portal.sectors.nl
     sector = self._create(country, "euphorie.sector", "sector")
     surveygroup = self._create(sector,
                                "euphorie.surveygroup",
                                "group",
                                evaluation_algorithm=algorithm)
     survey = self._create(surveygroup, "euphorie.survey", "survey")
     module = self._create(survey, "euphorie.module", "module")
     risk = self._create(module, "euphorie.risk", "risk")
     EnsureInterface(risk)
     return risk
Example #3
0
    def set_evaluation_method_interfaces(self):
        def walk(node):
            for idx, sub_node in node.ZopeFind(node, search_sub=0):
                if IRisk.providedBy(sub_node):
                    yield sub_node
                if IDexterityContainer.providedBy(sub_node):
                    for sub_sub_node in walk(sub_node):
                        yield sub_sub_node

        count = 0
        walker = walk(self.context)
        for risk in walker:
            log.debug("Ensure interface for %s", "/".join(risk.getPhysicalPath()))
            EnsureInterface(risk)
            count += 1
        log.info("Ensured interface for %d risks", count)
        return count
Example #4
0
    def copyTemplate(self, source, target):
        target = self.context[target.id]  # Acquisition-wrap
        try:
            source._notifyOfCopyTo(target, op=0)
        except ConflictError:
            raise

        copy = source._getCopy(target)

        today = datetime.date.today()
        title = self.request.locale.dates.getFormatter("date", length="long").format(
            datetime.date.today()
        )
        copy.id = today.isoformat()
        copy.title = title
        source_algorithm = aq_parent(source).evaluation_algorithm
        target_algorithm = self.request.form.get(
            "form.widgets.evaluation_algorithm", [source_algorithm]
        ).pop()
        target.evaluation_algorithm = target_algorithm
        target._setObject(copy.id, copy)
        if source_algorithm != target_algorithm:
            from euphorie.content.risk import EnsureInterface
            from euphorie.content.risk import IRisk

            risks = [
                item
                for (id, item) in target.ZopeFind(target, search_sub=1)
                if IRisk.providedBy(item)
            ]
            for risk in risks:
                EnsureInterface(risk)

        if hasattr(copy, "published"):
            delattr(copy, "published")
        copy = target[copy.id]  # Acquisition-wrap
        copy.wl_clearLocks()
        copy._postCopy(target, op=0)

        wt = api.portal.get_tool("portal_workflow")
        if wt.getInfoFor(copy, "review_state") == "published":
            wt.doActionFor(copy, "retract")

        notify(ObjectClonedEvent(target[copy.id]))
        return copy