Пример #1
0
    def listContainedTypes(self, checkAvailability=True):
        if IBoundContentType.providedBy(self):
            context = self.context
            if not IContentContainer.providedBy(context):
                return

            precondition = IItemTypePrecondition(self, None)

            if precondition is not None:
                contenttypes = []
                for tp in precondition.types:
                    ct = queryUtility(IContentType, tp)
                    if ct is not None and ct not in contenttypes:
                        contenttypes.append(ct)

                for tp in precondition.ifaces:
                    for name, ct in getUtilitiesFor(tp):
                        if ct not in contenttypes:
                            contenttypes.append(ct)

                for contenttype in contenttypes:
                    contenttype = contenttype.__bind__(context)

                    explicit = True
                    if IExplicitlyAddable.providedBy(contenttype):
                        explicit = False
                        for tp in precondition.ifaces:
                            if tp not in (IActiveType, IExplicitlyAddable)\
                                    and tp.providedBy(contenttype):
                                explicit = True
                                break

                        for tp in precondition.types:
                            if contenttype.name == tp:
                                explicit = True
                                break

                    if explicit:
                        # check the container constraint
                        validate = queryUtility(
                            IContainerTypesConstraint, contenttype.name)
                        if validate is not None:
                            try:
                                validate(self)

                                if not checkAvailability:
                                    yield contenttype

                                elif contenttype.isAvailable():
                                    yield contenttype
                            except InvalidContainerType:
                                pass
                        else:
                            if not checkAvailability:
                                yield contenttype

                            elif contenttype.isAvailable():
                                yield contenttype
Пример #2
0
def checkContentType(container, contenttype):
    if not (IWriteContainer.providedBy(container) or IContentContainer.providedBy(container)):
        raise TypeError("Container is not a valid Zope container.")

    ct = IContentType(container, None)
    if ct is None:
        raise InvalidContainerType(container)

    # check item precondition
    precondition = ctContains(ct)
    if precondition is not None:
        precondition(container, "", contenttype)

    # check the container constraint
    validate = queryUtility(IContainerTypesConstraint, contenttype.name)
    if validate is not None:
        validate(container)
Пример #3
0
def checkObject(container, name, object):
    """Check containement constraints for an object and container"""
    if not (IWriteContainer.providedBy(container) or IContentContainer.providedBy(container)):
        raise TypeError("Container is not a valid Zope container.")

    # check item precondition
    precondition = contains(container)
    if precondition is not None:
        precondition(container, name, object)
    else:
        contenttype = IContentType(object, None)
        if contenttype is None:
            raise InvalidItemType(container, object, ())

    # check the container constraint
    validate = containers(object)
    if validate is not None:
        validate(container)
Пример #4
0
    def add(self, content, name=''):
        if not self.isAddable():
            raise Unauthorized("Can't create '%s' instance"%self.name)

        context = self.container
        content = removeAllProxies(content)

        if IContentContainer.providedBy(context) or \
                IContentNamesContainer.providedBy(content):
            chooser = INameChooser(context)

            if IContainerNamesContainer.providedBy(context):
                name = chooser.chooseName('', content)
            else:
                name = chooser.chooseName(name, content)
                chooser.checkName(name, content)

            self.checkObject(context, name, content)

            removeSecurityProxy(context)[name] = content
            return context[name]
        else:
            raise ValueError(_("Can't add content."))