Beispiel #1
0
 def items(self):
     res = []
     container = IContentContainer(self.context, None)
     if container is not None:
         for value in container.values():
             if checkPermission('zope.View', value):
                 item = IItem(value, None)
                 if item is not None:
                     items = component.queryMultiAdapter((item, self.request), ISitemap)
                     res.append({'title': item.title,
                            'url': absoluteURL(item, self.request),
                            'items': getattr(items, 'items', [])})
     return res
    def upperContainer(self):
        request = self.request
        vhr = request.getVirtualHostRoot()
        parent = getattr(self.context, '__parent__', None)

        while True:
            if (parent is None or
                sameProxiedObjects(parent, vhr) or
                IContainmentRoot.providedBy(parent)):
                return None

            if IContentContainer.providedBy(parent):
                url = absoluteURL(parent, request)

                if checkPermission('zojax.ModifyContent', parent):
                    return '%s/@@context.html' % url

                viewName = queryMultiAdapter(
                    (parent, request),
                    IContentViewView
                )
                if viewName:
                    return '%s/%s' % (url, viewName.name)

                return '%s/' % url
            else:
                parent = getattr(parent, '__parent__', None)
Beispiel #3
0
 def query(self, default=None):
     dc = None
     if IContentContainer.providedBy(self.content):
         try:
             dc = IDCTimes(self.catalog.searchResults(traversablePath={'any_of':(self.content,)},
                                                      sort_on='modified', sort_order='reverse')[0], None)
         except (TypeError,IndexError), e:
             pass
Beispiel #4
0
def findContainer(context):
    """
    >>> from zope import interface
    >>> from zojax.content.browser.utils import findContainer

    >>> class Content(object):
    ...     __parent__ = None

    >>> class Container(object):
    ...     interface.implements(IContentContainer)
    ...     __parent__ = None

    >>> ob = Content()
    >>> ob.__parent__ = Content()
    >>> ob.__parent__.__parent__ = Content()

    No root container

    >>> findContainer(ob) is None
    True

    Recursive

    >>> ob.__parent__.__parent__.__parent__ = ob.__parent__.__parent__
    >>> findContainer(ob) is None
    True

    With container

    >>> ob.__parent__.__parent__.__parent__ = Container()

    >>> print findContainer(ob)
    <zojax.content.browser.utils.Container object at ...>
    """
    parent = context

    seen = set()

    while True:
        if parent in seen:
            break

        seen.add(parent)

        if IContentContainer.providedBy(parent):
            return parent

        parent = getattr(parent, '__parent__', None)
        if parent is None:
            break

    return None
Beispiel #5
0
    def _process(self, context, level=1, parent=None):
        request = self.request

        data = []
        for name, configlet in context.items():
            if not IConfiglet.providedBy(configlet) or \
                    not configlet.isAvailable():
                continue

            info = {'name': name,
                    'title': configlet.__title__,
                    'icon': queryMultiAdapter(
                         (configlet, request), name='zmi_icon'),
                    'items': (),
                    'selected': False,
                    'hasSelected': False,
                    'isLink': bool(list(configlet.__schema__)) or \
                                IContentContainer.providedBy(configlet) or \
                                not ICategory.providedBy(configlet),
                    'parent': parent,
                    'configlet': configlet,
                    'level': level}

            if configlet.__id__ == self.context.__id__:
                info['selected'] = True
                info['hasSelected'] = True
                p = parent
                while p is not None:
                    p['hasSelected'] = True
                    if p['cssClass'].endswith(' closed'):
                        p['cssClass'] = p['cssClass'][0:-7]
                    p = p['parent']
            info['cssClass'] = info['selected'] and 'selected' \
                                or ''

            info['items'] = self._process(configlet, level+1, info)

            if not info['hasSelected'] and info['items']:
                info['cssClass'] += ' closed'

            data.append((configlet.__title__, info))

        data.sort()
        data = [info for t, info in data]
        return data
def target(self):
    target = self.raw_target
    proxied_target = TargetProxy(target, target.__parent__, target.__name__, self)
    if IContentContainer.providedBy(target):
        return ContainerLocationProxy(proxied_target, self.__parent__, self.__name__)
    return proxied_target