Пример #1
0
    def addingInfo(self):
        request = self.request
        container = self.context
        url = absoluteURL(container, request)

        contenttype = IContentType(container, None)

        if contenttype is None:
            return []

        result = []
        for ptype in contenttype.listContainedTypes():
            if ptype.addform:
                action = '%s/+/%s'%(url, ptype.addform)
            else:
                action = '%s/+/%s/'%(url, ptype.name)

            result.append({'id': ptype.name,
                           'title': ptype.title,
                           'description': ptype.description,
                           'selected': False,
                           'has_custom_add_view': True,
                           'action': action,
                           'icon': queryMultiAdapter(
                               (ptype, request), name='zmi_icon'),
                           'contenttype': ptype})

        result.sort(lambda a, b: cmp(a['title'], b['title']))
        return result
Пример #2
0
    def __iter__(self):
        if self.contenttype is None:
            raise StopIteration

        context = self.context
        request = self.request

        actions = []
        for ct in self.contenttype.listContainedTypes():
            action = AddContent(context, request, ct, 9999)
            actions.append((action.title, action))

        for context in self.context.values():
            if IWorkspace.providedBy(context):
                contenttype = IContentType(context, None)
                if contenttype is not None:
                    for ct in contenttype.listContainedTypes():
                        action = AddContent(context, request, ct, 9999)
                        actions.append((action.title, action))

        actions.sort()

        weight = 999
        for _t, action in actions:
            weight = weight + 1
            action.weight = weight
            yield action
Пример #3
0
    def __init__(self, context, default=None):
        self.value = default
        if IDraftedContent.providedBy(context):
            return

        _context = removeSecurityProxy(context)

        ct = IContentType(_context, None)
        if ct is None:
            return

        perms = {}
        for ct in ct.listContainedTypes(False):
            dct = queryUtility(IDraftContentType, ct.name)
            if dct is not None:
                # do not check permission
                if IDraftedContentType.providedBy(ct):
                    interface.noLongerProvides(ct, IDraftedContentType)
                ct.permission = None
                if not ct.isAvailable():
                    continue

                if dct.publish:
                    perms[dct.publish] = 1

        principals = {}
        for permission in perms.keys():
            principals.update(
                [(user, 1) for user in getAccessList(_context, permission)])

        if principals:
            self.value = principals.keys()
Пример #4
0
    def __call__(self, context):
        contenttype = IContentType(context, None)
        if contenttype is None:
            return SimpleVocabulary([])

        result = []
        for ptype in contenttype.listContainedTypes():
            result.append((ptype.title, ptype.name))

        result.sort()
        return SimpleVocabulary([
                SimpleTerm(name, name, title) for title, name in result])
Пример #5
0
    def publish(self, comment=u''):
        location = self.getLocation()

        if not self.isPublishable(location):
            raise DraftException("You can't publish content to this location.")

        self.published = True

        contentType = IContentType(self.content).__bind__(location)

        content = self.content
        interface.noLongerProvides(content, IDraftedContent)

        content = contentType.add(content, self.shortname)

        event.notify(ObjectModifiedEvent(content))
        event.notify(events.DraftPublishedEvent(content, self, comment))

        return content
Пример #6
0
    def update(self):
        super(Contents, self).update()

        item = IItem(self.context, None)
        if item is not None:
            self.content_title = item.title or self.context.__name__
            self.content_description = item.description
        else:
            dc = IDCDescriptiveProperties(self.context, None)
            if dc is not None:
                self.content_title = dc.title
                self.content_description = dc.description

        contenttype = IContentType(self.context, None)
        try:
            contenttype.listContainedTypes().next()
            self.hasAdding = True
        except:
            self.hasAdding = False
Пример #7
0
    def nameAllowed(self):
        """Return whether names can be input by the user."""
        context = self.context

        if IContentType.providedBy(context):
            context = context.context

        if IAdding.providedBy(context):
            context = context.context

        if IWriteContainer.providedBy(context):
            return not IContainerNamesContainer.providedBy(context)
        else:
            return False
Пример #8
0
    def add(self, object):
        name = self.getName(object)

        if IContentType.providedBy(self.context):
            ob = self.context.add(object, name)

        elif IAdding.providedBy(self.context):
            self.context.contentName = name
            ob = self.context.add(object)

        else:
            raise ValueError("Can't add content.")

        self._addedObject = ob
        return ob
Пример #9
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))
Пример #10
0
 def __call__(self, context, default=None):
     contenttype = queryUtility(IContentType, name=self.name, default=default)
     if IContentType.providedBy(contenttype):
         return contenttype.__bind__(context)