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: parent = getParent(self) if not parent or parent.portal_type == 'Plone Site': return [fti.getId() for fti in self.getDefaultAddableTypes(context)] elif not parentPortalTypeEqual(self): # if parent.portal_type != self.portal_type: default_addable_types = [fti.getId() for fti in self.getDefaultAddableTypes(context)] if ISelectableConstrainTypes.providedBy(parent): return [t for t in parent.getLocallyAllowedTypes(context) if t in default_addable_types] else: return [t for t in parent.getLocallyAllowedTypes() if t in default_addable_types] else: if ISelectableConstrainTypes.providedBy(parent): return parent.getLocallyAllowedTypes(context) else: return parent.getLocallyAllowedTypes() else: raise ValueError, "Invalid value for enableAddRestriction"
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: parent = getParent(self) if not parent or parent.portal_type == 'Plone Site': return [ fti.getId() for fti in self.getDefaultAddableTypes(context) ] elif not parentPortalTypeEqual(self): # if parent.portal_type != self.portal_type: default_addable_types = [ fti.getId() for fti in self.getDefaultAddableTypes(context) ] if ISelectableConstrainTypes.providedBy(parent): return [ t for t in parent.getLocallyAllowedTypes(context) if t in default_addable_types ] else: return [ t for t in parent.getLocallyAllowedTypes() if t in default_addable_types ] else: 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
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
def test_implementsConstrainTypes(self): self.assertTrue(ISelectableConstrainTypes.providedBy(self._ATCT)) self.assertTrue(verifyObject(ISelectableConstrainTypes, self._ATCT))
def test_implementsConstrainTypes(self): self.failUnless(ISelectableConstrainTypes.providedBy(self._ATCT)) self.failUnless(verifyObject(ISelectableConstrainTypes, self._ATCT))