def getChainFor(self, ob, managescreen=False): """Returns the chain that applies to the object. If chain doesn't exist we return None to get a fallback from portal_workflow. @parm managescreen: If True return the special tuple ('default') instead of the actual default chain (hack). """ cbt = self._chains_by_type if type(ob) == type(''): pt = ob elif hasattr(aq_base(ob), '_getPortalTypeName'): pt = ob._getPortalTypeName() else: pt = None if pt is None: return None chain = None if cbt is not None: chain = cbt.get(pt, _MARKER) # Backwards compatibility: before chain was a string, not a list if chain is not _MARKER and type(chain) == type(''): chain = map(lambda x: x.strip(), chain.split(',')) Log(LOG_DEBUG, 'Chain founded in policy', chain) if chain is _MARKER or chain is None: return None elif len(chain) == 1 and chain[0] == DEFAULT_CHAIN: default = self.getDefaultChain(ob) if default: if managescreen: return chain[0] else: return default else: return None return chain
def _initChains(self, node): """ Import policies from XML Types specified are in two cases: - a default_chain attribute is present - zero or more workflows are presents then type take the chain in the same order For any types not specified, we do nothing and they will acquire their chain from another policy or from portal_workfow. """ seen = set() for child in node.childNodes: if child.nodeName != 'bindings': continue for sub in child.childNodes: if sub.nodeName == 'default': self.context.setDefaultChain(self._getChain(sub)) if sub.nodeName == 'type': type_id = str(sub.getAttribute('type_id')) assert type_id not in seen, ( 'Type %s listed more than once' % type_id) seen.add(type_id) default = sub.getAttribute('default_chain') chain = self._getChain(sub) Log(LOG_DEBUG, default, chain) assert not (default and chain), ( 'Type %s is marked to use default but also ' 'included a chain: %s' % (type_id, chain)) if default: # omit from the policy to acquire self.context.setChain(type_id, (DEFAULT_CHAIN, )) else: self.context.setChain(type_id, chain)
def name(self): Log(LOG_DEBUG, self.context.id) return self.context.id