Beispiel #1
0
    def getImmediatelyAddableTypes(self, context=None):
        """Get the list of type ids which should be immediately addable.
        If enableTypeRestrictions is ENABLE, return the list set; if it is
        ACQUIRE, use the value from the parent; if it is DISABLE, return
        all type ids allowable on 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('immediatelyAddableTypes').get(self)
        elif mode == ACQUIRE:
            parent = getParent(self)
            if not parent or parent.portal_type == 'Plone Site':
                return [fti.getId() for fti in \
                        PortalFolder.allowedContentTypes(self)]
            elif not parentPortalTypeEqual(self):
                default_allowed = [fti.getId() for fti in \
                        PortalFolder.allowedContentTypes(self)]
                return [t for t in parent.getImmediatelyAddableTypes(context) \
                           if t in default_allowed]
            else:
                parent = aq_parent(aq_inner(self))
                return parent.getImmediatelyAddableTypes(context)
        else:
            raise ValueError, "Invalid value for enableAddRestriction"
Beispiel #2
0
    def getImmediatelyAddableTypes(self, context=None):
        """Get the list of type ids which should be immediately addable.
        If enableTypeRestrictions is ENABLE, return the list set; if it is
        ACQUIRE, use the value from the parent; if it is DISABLE, return
        all type ids allowable on 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('immediatelyAddableTypes').get(self)
        elif mode == ACQUIRE:
            parent = getParent(self)
            if not parent or parent.portal_type == 'Plone Site':
                return [fti.getId() for fti in \
                        PortalFolder.allowedContentTypes(self)]
            elif not parentPortalTypeEqual(self):
                default_allowed = [fti.getId() for fti in \
                        PortalFolder.allowedContentTypes(self)]
                return [t for t in parent.getImmediatelyAddableTypes(context) \
                           if t in default_allowed]
            else:
                parent = aq_parent(aq_inner(self))
                return parent.getImmediatelyAddableTypes(context)
        else:
            raise ValueError, "Invalid value for enableAddRestriction"
Beispiel #3
0
    def allowedContentTypes(self, context=None):
        """returns constrained allowed types as list of fti's
        """
        if context is None:
            context = self
        mode = self.getConstrainTypesMode()

        # Short circuit if we are disabled or acquiring from non-compatible
        # parent

        parent = getParent(self)
        if mode == DISABLED or (mode == ACQUIRE and not parent):
            return PortalFolder.allowedContentTypes(self)
        elif mode == ACQUIRE and not parentPortalTypeEqual(self):
            globalTypes = self.getDefaultAddableTypes(context)
            if parent.portal_type == 'Plone Site':
                return globalTypes
            else:
                allowed = list(parent.getLocallyAllowedTypes(context))
                return [fti for fti in globalTypes if fti.getId() in allowed]
        else:
            globalTypes = self.getDefaultAddableTypes(context)
            allowed = list(self.getLocallyAllowedTypes())
            ftis = [fti for fti in globalTypes if fti.getId() in allowed]
            return ftis
    def __call__(self, context):
        # catch some bad contexts (such as KSS validator)
        try:
            context.portal_type
        except AttributeError:
            return []

        # get default allowed types, but not the allowed types directly from
        # the context because they may already be filtered.
        if not isinstance(context, PortalFolderBase):
            return []
        types = PortalFolderBase.allowedContentTypes(context)

        # find the dexterity FTIs using the IRestrictedDossier behavior
        restricted_types = filter(
            lambda fti: getattr(fti, 'behaviors', []) and
                self.marker_behavior in fti.behaviors, types)

        # create the terms
        terms = []
        for fti in restricted_types:
            title = translate(fti.title,
                              domain=fti.i18n_domain,
                              context=context.REQUEST)
            terms.append(SimpleVocabulary.createTerm(
                    fti.id, fti.id, title))

        # create the vocabulary
        return SimpleVocabulary(terms)
Beispiel #5
0
    def allowedContentTypes(self, context=None):
        """returns constrained allowed types as list of fti's
        """
        if context is None:
            context = self
        mode = self.getConstrainTypesMode()

        # Short circuit if we are disabled or acquiring from non-compatible
        # parent

        parent = getParent(self)
        if mode == DISABLED or (mode == ACQUIRE and not parent):
            return PortalFolder.allowedContentTypes(self)
        elif mode == ACQUIRE and not parentPortalTypeEqual(self):
            globalTypes = self.getDefaultAddableTypes(context)
            if parent.portal_type == 'Plone Site':
                return globalTypes
            else:
                allowed = list(parent.getLocallyAllowedTypes())
                return [fti for fti in globalTypes if fti.getId() in allowed]
        else:
            globalTypes = self.getDefaultAddableTypes(context)
            allowed = list(self.getLocallyAllowedTypes())
            ftis = [fti for fti in globalTypes if fti.getId() in allowed]
            return ftis
    def __call__(self, context):
        # catch some bad contexts (such as KSS validator)
        try:
            context.portal_type
        except AttributeError:
            return []

        # get default allowed types, but not the allowed types directly from
        # the context because they may already be filtered.
        if not isinstance(context, PortalFolderBase):
            return []
        types = PortalFolderBase.allowedContentTypes(context)

        # find the dexterity FTIs using the IRestrictedDossier behavior
        restricted_types = filter(
            lambda fti: getattr(fti, 'behaviors') and self.marker_behavior in
            fti.behaviors, types)

        # create the terms
        terms = []
        for fti in restricted_types:
            title = translate(fti.title,
                              domain=fti.i18n_domain,
                              context=context.REQUEST)
            terms.append(SimpleVocabulary.createTerm(fti.id, fti.id, title))

        # create the vocabulary
        return SimpleVocabulary(terms)
def allowedContentTypes(self, context=None):
    """
    returns constrained allowed types as list of fti's.
    There is a try/except for handle AT folders inside DX containers
    """
    if context is None:
        context = self
    mode = self.getConstrainTypesMode()

    # Short circuit if we are disabled or acquiring from non-compatible
    # parent

    parent = getParent(self)
    if mode == DISABLED or (mode == ACQUIRE and not parent):
        return PortalFolder.allowedContentTypes(self)
    elif mode == ACQUIRE and not parentPortalTypeEqual(self):
        globalTypes = self.getDefaultAddableTypes(context)
        if parent.portal_type == 'Plone Site':
            return globalTypes
        else:
            try:
                allowed = list(parent.getLocallyAllowedTypes(context))
            except AttributeError:
                # parent is a DX content?
                behavior = ISelectableConstrainTypes(parent)
                if not behavior:
                    # return context addable types
                    return get_context_ftis(self)
                allowed = behavior.getLocallyAllowedTypes(context)
            return [fti for fti in globalTypes if fti.getId() in allowed]
    else:
        return get_context_ftis(self)
def getImmediatelyAddableTypes(self, context=None):
    """Get the list of type ids which should be immediately addable.
    If enableTypeRestrictions is ENABLE, return the list set; if it is
    ACQUIRE, use the value from the parent; if it is DISABLE, return
    all type ids allowable on the item.
    There is a try/except for handle AT folders inside DX containers
    """
    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('immediatelyAddableTypes').get(self)
    elif mode == ACQUIRE:
        parent = getParent(self)
        if not parent or parent.portal_type == 'Plone Site':
            return [fti.getId() for fti in
                    PortalFolder.allowedContentTypes(self)]
        elif not parentPortalTypeEqual(self):
            default_allowed = [fti.getId() for fti in
                               PortalFolder.allowedContentTypes(self)]
            try:
                immediately_addable = parent.getImmediatelyAddableTypes(context)
            except AttributeError:
                # parent is a DX content?
                behavior = ISelectableConstrainTypes(parent)
                if not behavior:
                    # return context default addable types
                    immediately_addable = self.getField('immediatelyAddableTypes').get(self)
                immediately_addable = behavior.getImmediatelyAddableTypes(context)
            return [t for t in immediately_addable if t in default_allowed]
        else:
            parent = aq_parent(aq_inner(self))
            try:
                return parent.getImmediatelyAddableTypes(context)
            except AttributeError:
                # parent is a DX content?
                behavior = ISelectableConstrainTypes(parent)
                if not behavior:
                    # return context default addable types
                    return self.getField('immediatelyAddableTypes').get(self)
                return behavior.getImmediatelyAddableTypes(context)
    else:
        raise ValueError, "Invalid value for enableAddRestriction"
Beispiel #9
0
 def allowedContentTypes(self):
     # Make sure PlominoDocument is hidden in Plone "Add..." menu
     # as getNotAddableTypes is not used anymore in Plone 4
     filterOut = ['PlominoDocument']
     types = PortalFolder.allowedContentTypes(self)
     return [ctype for ctype in types if ctype.getId() not in filterOut]
Beispiel #10
0
 def allowedContentTypes(self):
     # Make sure PlominoDocument is hidden in Plone "Add..." menu
     filterOut = ['PlominoDocument']
     types = PortalFolder.allowedContentTypes(self)
     return [ctype for ctype in types if ctype.getId() not in filterOut]