Пример #1
0
    def __init__(self, content, default=None):
        self.draft = False

        if IContent.providedBy(content):
            while content is not None:
                if IDraftContent.providedBy(content):
                    self.draft = True

                content = getattr(content, '__parent__', None)
Пример #2
0
    def isAvailable(self):
        context = self.context

        for key in context:
            item = context[key]

            if IContent.providedBy(item):
                if checkPermission('zope.View', item):
                    return True

        return False
Пример #3
0
    def update(self):
        context = self.context
        while not IContent.providedBy(context):
            context = getattr(context, '__parent__', None)
            if context is None:
                break

        if context is not None:
            ct = IContentType(context, None)
            if ct is not None:
                self.klass = ct.name.replace('.', '-')

        super(ContentViewLayout, self).update()
    def __call__(self, context):
        if IContentItem.providedBy(context):
            context = context.context

        terms = []
        for name, content in context.items():
            if IContent.providedBy(content) and \
                   checkPermission('zope.View', content):
                item = IItem(content, None)
                if item is None:
                    title = content.__name__
                else:
                    title = u'%s (%s)'%(item.title, content.__name__)
                terms.append((title, SimpleTerm(name, name, title)))

        terms.sort()
        return SimpleVocabulary([term for t, term in terms])
Пример #5
0
    def __call__(self, context):
        while not IContent.providedBy(context):
            context = getattr(context, '__parent__', None)
            if context is None:
                return SimpleVocabulary(())

        try:
            request = getInteraction().participations[0]
        except:
            request = TestRequest()

        terms = []
        for name, view in getAdapters((context, request), IViewModel):
            view.update()
            if not view.isAvailable():
                continue

            term = SimpleTerm(name, name, view.__title__)
            term.description = view.__description__

            terms.append((view.__title__, term))

        terms.sort()
        return Vocabulary([defaultModel] + [term for t, term in terms])
Пример #6
0
def contentHandler(_context, schema, name, title, class_=None,
                   description='', permission='zope.View',
                   contenttype=None, ctclass=None,
                   type=[], contains=(), containers=(), addform=None):

    if class_ is None:
        type = type + [IInactiveType,]

    if IInactiveType in type and IActiveType in type:
        type.remove(IActiveType)

    # make content type Active if no type is set
    if not type:
        type.append(IActiveType)

    for tp in type:
        if tp.isOrExtends(IContentType):
            raise ValueError(
                'Content type type can not extend IContentType interface.', tp)

    # check schema
    if class_ is not None and not schema.implementedBy(class_):
        raise ValueError(
            'Content class should implement content schema.', class_, schema)

    # create content type
    if ctclass is not None:
        if not IContentType.implementedBy(ctclass):
            raise ValueError('Custom content type implementation '\
                                 'should implement IContentType interface.')
        ct_factory = ctclass
    else:
        ct_factory = ContentType

    ct = ct_factory(
        name, schema, class_, title, description, permission, addform)

    # set types
    interface.alsoProvides(ct, type)

    for tp in type:
        utility(_context, tp, ct, name=name)

    # create unique interface for content type
    if contenttype is None:
        iname = name
        for ch in ('.', '-'):
            iname = iname.replace(ch, '_')

        contenttype = InterfaceClass(iname, (IContentType,),
                                     __doc__='Content Type: %s' %name,
                                     __module__='zojax.content')

        # Add the content type to the `zojax.content` module.
        setattr(zojax.content, iname, contenttype)

    # register content type as utility
    utility(_context, contenttype, ct)

    # create named utility for content type
    utility(_context, IContentType, ct, name=name)

    # adapter that return IContentType object from class instances
    adapter(_context, (ClassToTypeAdapter(name),), IContentType, (schema,))

    if class_ is not None:
        clsifaces = list(interface.implementedBy(class_))
        if not IContent.implementedBy(class_):
            clsifaces.append(IContent)
        clsifaces.extend(type)
        interface.classImplements(class_, clsifaces)
        
    # process constraints
    _context.action(
        discriminator = ('zojax.content:contentTypeConstraints', name),
        callable = contentTypeConstraints,
        args = (name, contains, containers, _context),
        order = 999998)

    # added custom interface to contenttype object
    _context.action(
        discriminator = ('zojax.content:contenttypeInterface', contenttype),
        callable = contenttypeInterface,
        args = (ct, contenttype))