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.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 try: self.context.setChain(type_id, (DEFAULT_CHAIN, )) except: if type_id == 'Collection': # this is really just a plone.app.upgrade? # test fix but it should be fine if we retry # with Topic instead of Collection self.context.setChain('Topic', chain) else: raise else: try: self.context.setChain(type_id, chain) except ValueError: if type_id == 'Collection': self.context.setChain('Topic', chain) else: raise
def getPlacefulChainFor(self, portal_type, start_here=False): """Get the chain for the given portal_type. Returns None if no placeful chain is found. Does _not_ acquire from parent configurations. Usecases: If the policy config is in the object that request the chain we cannot take the 'below' policy. In other case we test the 'below' policy first and, if there's no chain found, the 'in' policy. """ workflow_tool = getToolByName(self, 'portal_placeful_workflow') Log.debug('below policy id %s', self.getPolicyBelowId()) Log.debug('in policy id %s', self.getPolicyInId()) chain = None policy = None if not start_here: policy = workflow_tool.getWorkflowPolicyById( self.getPolicyBelowId()) if policy is not None: chain = policy.getChainFor(portal_type) policy = workflow_tool.getWorkflowPolicyById(self.getPolicyInId()) if policy is not None: Log.debug("policy %s %s", repr(policy), policy is not None) if chain is None and policy is not None: chain = policy.getChainFor(portal_type) Log.debug("portal_type and chain %s %s", portal_type, chain) return chain
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 isinstance(ob, six.string_types): 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 isinstance(chain, six.string_types): chain = map(lambda x: x.strip(), chain.split(',')) Log.debug('Chain founded in policy %s', 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 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.debug('Chain founded in policy %s', 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.debug(self.context.id) return self.context.id
def name(self): Log(LOG_DEBUG, self.context.id) return self.context.id