Example #1
0
    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"
Example #2
0
    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")
Example #3
0
    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
Example #4
0
    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))
Example #6
0
 def test_implementsConstrainTypes(self):
     self.assertTrue(ISelectableConstrainTypes.providedBy(self._ATCT))
     self.assertTrue(verifyObject(ISelectableConstrainTypes, self._ATCT))
Example #7
0
 def test_implementsConstrainTypes(self):
     self.failUnless(ISelectableConstrainTypes.providedBy(self._ATCT))
     self.failUnless(verifyObject(ISelectableConstrainTypes, self._ATCT))
Example #8
0
 def test_implementsConstrainTypes(self):
     self.failUnless(ISelectableConstrainTypes.providedBy(self._ATCT))
     self.failUnless(verifyObject(ISelectableConstrainTypes, self._ATCT))