def getLocallyAllowedTypes(self, context=None): """If enableTypeRestrictions is ENABLE, return the list of types set. If it is ACQUIRE, get the types set on the parent so long as the parent is of the same type - if not, use the same behaviuor as DISABLE: return the types allowable in the item. """ if context is None: context = self mode = self.getConstrainTypesMode() if mode == DISABLED: return [fti.getId() for fti in self.getDefaultAddableTypes(context)] elif mode == ENABLED: return self.getField("locallyAllowedTypes").get(self) elif mode == ACQUIRE: # if not parent or parent.portal_type != self.portal_type: if not parentPortalTypeEqual(self): return [fti.getId() for fti in self.getDefaultAddableTypes(context)] else: parent = aq_parent(aq_inner(self)) if ISelectableConstrainTypes.providedBy(parent): return parent.getLocallyAllowedTypes(context) else: return parent.getLocallyAllowedTypes() else: raise ValueError, "Invalid value for enableAddRestriction"
def _ct_defaultConstrainTypesMode(self): """Configure constrainTypeMode depending on the parent ACQUIRE if parent support ISelectableConstrainTypes DISABLE if not """ portal_factory = getToolByName(self, "portal_factory", None) if portal_factory is not None and portal_factory.isTemporary(self): # created by portal_factory parent = aq_parent(aq_parent(aq_parent(aq_inner(self)))) else: parent = aq_parent(aq_inner(self)) if ISelectableConstrainTypes.providedBy(parent) and parentPortalTypeEqual(self): return ACQUIRE else: return DISABLED