• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python interfaces.IReadContainer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中zope.container.interfaces.IReadContainer的典型用法代码示例。如果您正苦于以下问题:Python IReadContainer类的具体用法?Python IReadContainer怎么用?Python IReadContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了IReadContainer类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __new__

 def __new__(cls, context, request, view, manager):
     chain = _get_context_chain(context)
     chain.pop() # bungeni_app
     top_section = chain.pop()
     
     if not chain:
         return
     
     # we require the tree to begin with a container object
     if not IReadContainer.providedBy(chain[-1]):
         return
     
     # remove any views from navigation tree
     if not(IAlchemistContent.providedBy(chain[0]) or 
             IAlchemistContainer.providedBy(chain[0]) or
             ISection.providedBy(chain[0])
         ):
         chain.pop(0)
     
     subcontext = chain[-1]
     if (len(chain) > 1 or
             IReadContainer.providedBy(subcontext) and 
             not IAlchemistContainer.providedBy(subcontext) and 
             len(subcontext)
         ):
         inst = object.__new__(cls, context, request, view, manager)
         inst.chain = chain
         inst.top_section_url = url.absoluteURL(top_section, request)
         inst.id_prefix = "nav"
         return inst
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:30,代码来源:navigation.py


示例2: publishTraverse

    def publishTraverse(self, request, name):
        subob = self.traverse(name)
        if subob is not None:
            return safely_locate_maybe(subob, self.context, name)

        traversable_dict = traversable.bind().get(self.context)
        if traversable_dict:
            if name in traversable_dict:
                subob = getattr(self.context, traversable_dict[name])
                if callable(subob):
                    subob = subob()
                return safely_locate_maybe(subob, self.context, name)

        # XXX Special logic here to deal with containers.  It would be
        # good if we wouldn't have to do this here. One solution is to
        # rip this out and make you subclass ContainerTraverser if you
        # wanted to override the traversal behaviour of containers.
        if IReadContainer.providedBy(self.context):
            item = self.context.get(name)
            if item is not None:
                return item

        view = component.queryMultiAdapter((self.context, request), name=name)
        if view is not None:
            return view

        raise NotFound(self.context, name, request)
开发者ID:jean,项目名称:grokcore.traverser,代码行数:27,代码来源:components.py


示例3: update

 def update(self):
     request = self.request
     context = self.context
     chain = _get_context_chain(context)
     length = len(chain)
     self.items = []
     if length < 2:
         # there must be at least: [top-level section, application]
         return # container is None
     else:
         # the penultimate context is the top-level container
         container = chain[-2]
         assert container.__name__ is not None
         if not IReadContainer.providedBy(container):
             return # container has no readable content
     assert container is not None
     
     # add container items
     if length > 2:
         context = chain[-3]
     else:
         context = None
     self.add_container_menu_items(context, container)
     # add any menu items from zcml
     self.add_zcml_menu_items(container)
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:25,代码来源:navigation.py


示例4: subItems

 def subItems(self):
     """Collect all tree items for the given context."""
     items = []
     keys = []
     append = items.append
     if IReadContainer.providedBy(self.context):
         try:
             keys = list(self.context.keys())
         except(Unauthorized, Forbidden):
             return items
     else:
         return items
     counter = 1
     for name in keys:
         # Only include items we can traverse to
         subItem = api.traverse(self.context, name, None)
         if subItem is not None:
             append((api.getName(subItem), subItem,
                 self._hasSubItems(subItem)))
         counter += 1
         if counter == self.maxItems:
             # add context which should support a item listing view with 
             # batch
             lenght = len(keys) - self.maxItems
             default = '[%s more items...]' % lenght
             name = zope.i18n.translate(
                 _('[${lenght} more items...]', mapping={'lenght':lenght}),
                 context=self.request, default=default)
             append((name, self.context, False))
             break
     return items
开发者ID:zopefoundation,项目名称:z3c.jsontree,代码行数:31,代码来源:subitem.py


示例5: add_container_menu_items

 def add_container_menu_items(self, context, container):
     request = self.request
     
     _url = url.absoluteURL(container, request)
     
     if IReadContainer.providedBy(container):
         #XXX should be the same in all containers ?
         container=proxy.removeSecurityProxy(container)
         for name, item in container.items():
             if context is None:
                 selected = False
             else:
                 selected = url.same_path_names(context.__name__, name)
             item = proxy.removeSecurityProxy(item)
             if IDCDescriptiveProperties.providedBy(item):
                 title = item.title
             else:
                 props = IDCDescriptiveProperties(item)
                 title = props.title
             # only items with valid title
             if title is not None:
                 self.items.append(url.get_menu_item_descriptor(
                         title, selected, _url, name))
     default_view_name = queryDefaultViewName(container, self.request)
     default_view = component.queryMultiAdapter(
         (container, self.request), name=default_view_name)
     if hasattr(default_view, "title") and default_view.title is not None:
         self.items.insert(0, url.get_menu_item_descriptor(
                 default_view.title, 
                 sameProxiedObjects(container, self.context), 
                 _url))
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:31,代码来源:navigation.py


示例6: getLengthOf

 def getLengthOf(self, item):
     res = -1
     if IReadContainer.providedBy(item):
         try:
             res = len(item)
         except (Unauthorized, Forbidden):
             pass
     return res
开发者ID:grodniewicz,项目名称:oship,代码行数:8,代码来源:xmlobject.py


示例7: children_xmldoc

    def children_xmldoc(self):
        # If you need custom filter then reimplement this method.
        # Otherwise this implementation is generic and it is correct
        # for standard cases.
        try:
            rc = IReadContainer(self.context)
        except TypeError:
            return XMLDOC % u''
        except Unauthorized:
            return XMLDOC % u''

        specs = [queryMultiAdapter((value, self.request), IXML)
                for value in rc.values()]
        specs = filter(lambda x:x, specs)
        specs.sort(key = lambda x: x.sort_key())
        nodes = [x.to_xml() for x in specs]
        return XMLDOC % u'\n'.join(nodes)
开发者ID:fudong1127,项目名称:ice.control,代码行数:17,代码来源:xmlbase.py


示例8: singleBranchTree

 def singleBranchTree(self, root=''):
     parent = getParent(self.context)
     while parent is not None:
             if IReadContainer.providedBy(parent):
                 view = queryMultiAdapter(
                     (parent, self.request), name='singleBranchTree.xml')
                 return view()
             else:
                 parent = getParent(parent)
开发者ID:grodniewicz,项目名称:oship,代码行数:9,代码来源:xmlobject.py


示例9: __new__

    def __new__(cls, context, request, view, manager):
        # we have both primary and secondary navigation, so we won't
        # show the navigation tree unless we're at a depth > 2
        chain = _get_context_chain(context)[:-2]
        if not chain:
            return

        # we require the tree to begin with a container object
        if not IReadContainer.providedBy(chain[-1]):
            return

        subcontext = chain[-1]
        if (len(chain) > 1 or
            IReadContainer.providedBy(subcontext) and not
            IAlchemistContainer.providedBy(subcontext) and len(subcontext)):
            inst = object.__new__(cls, context, request, view, manager)
            inst.chain = chain
            return inst
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:18,代码来源:navigation.py


示例10: add_container_menu_items

    def add_container_menu_items(self, context, container):
        request = self.request
        # add a menu item for each user workspace, if we are in an
        # IWorkspaceSectionLayer
        # !+ if user is logged in or if request.layer_data
        if interfaces.IWorkspaceSectionLayer.providedBy(request):
            try:
                workspaces = IAnnotations(request)["layer_data"].get(
                    "workspaces")
            except:
                workspaces = []
            log.info("%s got user workspaces: %s" % (self, workspaces))
            base_url_path = "/workspace"
            for workspace in workspaces:
                log.info("appending menu item for user workspace: %s" %
                         str(workspace))
                self.items.append(
                    url.get_menu_item_descriptor(
                        workspace.full_name,
                        pos_action_in_url(
                            "/workspace/obj-%s" % workspace.group_id,
                            request.getURL()), base_url_path,
                        "obj-%s" % workspace.group_id))

        _url = url.absoluteURL(container, request)

        if IReadContainer.providedBy(container):
            #XXX should be the same in all containers ?
            container = proxy.removeSecurityProxy(container)
            for name, item in container.items():
                if context is None:
                    selected = False
                else:
                    selected = url.same_path_names(context.__name__, name)
                item = proxy.removeSecurityProxy(item)
                if IDCDescriptiveProperties.providedBy(item):
                    title = item.title
                else:
                    props = IDCDescriptiveProperties(item)
                    title = props.title
                # only items with valid title
                if title is not None:
                    self.items.append(
                        url.get_menu_item_descriptor(title, selected, _url,
                                                     name))
        default_view_name = queryDefaultViewName(container, self.request)
        default_view = component.queryMultiAdapter((container, self.request),
                                                   name=default_view_name)
        if hasattr(default_view, "title") and default_view.title is not None:
            self.items.insert(
                0,
                url.get_menu_item_descriptor(
                    default_view.title,
                    sameProxiedObjects(container, self.context), _url))
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:54,代码来源:navigation.py


示例11: getObjectURL

def getObjectURL(ob, req):
    """Return the URL for the object `ob`.

    If the object is a container and the url doesn't end in slash '/' then
    append a slash to the url.
    """
    url = zope.component.getMultiAdapter((ob, req), IAbsoluteURL)()
    if IReadContainer.providedBy(ob) and url[-1] != "/":
        url += "/"

    return url
开发者ID:mkerrin,项目名称:z3c.dav,代码行数:11,代码来源:utils.py


示例12: _hasSubItems

 def _hasSubItems(self, item):
     """This method allows us to decide if a sub item has items from the 
     point of view of the context."""
     res = False
     if IReadContainer.providedBy(item):
         try:
             if len(item) > 0:
                 res = True
         except(Unauthorized, Forbidden):
             pass
     return res
开发者ID:zopefoundation,项目名称:z3c.jsontree,代码行数:11,代码来源:subitem.py


示例13: children_xmldoc

    def children_xmldoc(self):
        try:
            rc = IReadContainer(self.context)
        except TypeError:
            return XMLDOC % u''
        except Unauthorized:
            return XMLDOC % u''

        specs = [queryMultiAdapter((value, self.request), IXML)
                for value in rc.values()]
        specs = filter(lambda x:x, specs)
        specs.sort(key = lambda x: x.sort_key())

        nodes = [x.to_xml() for x in specs]

        # add ++etc++site
        sm = self.context.getSiteManager()
        sm_spec = queryMultiAdapter((sm, self.request), IXML)
        nodes.append(sm_spec.to_xml())

        return XMLDOC % u'\n'.join(nodes)
开发者ID:fudong1127,项目名称:ice.control,代码行数:21,代码来源:xmlnice.py


示例14: _search_helper

def _search_helper(id, obj, container, id_filters, object_filters, result):
    # check id filters if we get a match then return immediately
    for id_filter in id_filters:
        if id_filter.matches(id):
            result.append(obj)
            return

    # now check all object filters
    for object_filter in object_filters:
        if object_filter.matches(obj):
            result.append(obj)
            return

    # do we need to check sub containers?
    if not IReadContainer.providedBy(obj):
        return

    for key, value in obj.items():
        _search_helper(key, value, obj, id_filters, object_filters, result)
开发者ID:jean,项目名称:z3c.contents,代码行数:19,代码来源:value.py


示例15: matches

 def matches(self, object):
     if IReadContainer.providedBy(object):
         return len(object) == self._count
     else:
         return False
开发者ID:jean,项目名称:zope.container,代码行数:5,代码来源:test_find.py


示例16: is_container

 def is_container(self):
     # I recommend reimplement this and return IS_CONTAINER
     # or empty string directly
     return IReadContainer.providedBy(self.context) or u''
开发者ID:fudong1127,项目名称:ice.control,代码行数:4,代码来源:xmlbase.py


示例17: expand

    def expand(self, chain, include_siblings=True):
        if len(chain) == 0:
            return ()

        context = chain.pop()
        items = []

        if IApplication.providedBy(context):
            items.extend(self.expand(chain))

        elif IAlchemistContent.providedBy(context):
            _url = url.absoluteURL(context, self.request)
            if IDCDescriptiveProperties.providedBy(context):
                title = context.title
            else:
                props = IDCDescriptiveProperties(context, None)
                if props is not None:
                    title = props.title
                else:
                    title = context.short_name

            selected = len(chain) == 0
            
            if chain:
                nodes = self.expand(chain)
            else:
                kls = context.__class__
                containers = [
                    (key, getattr(context, key))
                    for key, value in kls.__dict__.items()
                    if isinstance(value, ManagedContainerDescriptor)]
                nodes = []
                self.expand_containers(nodes, containers, _url, chain, None)

            items.append(
                {'title': title,
                 'url': _url,
                 'current': True,
                 'selected': selected,
                 'kind': 'content',
                 'nodes': nodes,
                 })

        elif IAlchemistContainer.providedBy(context):
            # loop through all managed containers of the parent
            # object, and include the present container as the
            # 'current' node.
            parent = context.__parent__
            assert parent is not None
            _url = url.absoluteURL(parent, self.request)

            # append managed containers as child nodes
            kls = type(proxy.removeSecurityProxy(parent))

            if include_siblings is True:
                if IApplication.providedBy(parent):
                    containers = [
                        (name, parent[name])
                        for name in 
                            location.model_to_container_name_mapping.values()
                        if name in parent
                    ]
                elif IReadContainer.providedBy(parent):
                    containers = list(parent.items())
                else:
                    containers = [
                        (key, getattr(parent, key))
                        for key, value in kls.__dict__.items()
                        if isinstance(value, ManagedContainerDescriptor)]
            else:
                containers = [(context.__name__, context)]
                
            self.expand_containers(items, containers, _url, chain, context)

        elif ILocation.providedBy(context):
            _url = url.absoluteURL(context, self.request)
            #props = IDCDescriptiveProperties.providedBy(context) and \
            #    context or IDCDescriptiveProperties(context)
            if IDCDescriptiveProperties.providedBy(context):
                props = IDCDescriptiveProperties(context)
            else:
                props = context
            props = proxy.removeSecurityProxy(props)

            selected = len(chain) == 0
            if selected and IReadContainer.providedBy(context):
                nodes = []
                try:
                    self.expand_containers(
                        nodes, context.items(), _url, chain, context)
                except:
                    pass
            else:
                nodes = self.expand(chain)
            i_id = getattr(props, 'id','N/A')
            items.append(
                {'title': getattr(props, 'title', i_id),
                 'url': _url,
                 'current': True,
                 'selected': selected,
#.........这里部分代码省略.........
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:101,代码来源:navigation.py


示例18: expand

 def expand(self, chain, include_siblings=True):
     if len(chain) == 0:
         return ()
     context = chain.pop()
     items = []
     if IApplication.providedBy(context):
         items.extend(self.expand(chain))
     elif IAlchemistContent.providedBy(context):
         _url = url.absoluteURL(context, self.request)
         selected = len(chain) == 0
         
         if chain:
             nodes = self.expand(chain)
         else:
             containers = utils.get_managed_containers(context)
             nodes = []
             self.expand_containers(nodes, containers, _url, chain, None)
         
         items.append({
                 "id": self.get_nav_entry_id(_url),
                 "label": IDCDescriptiveProperties(context).title,
                 "url": _url,
                 "current": True,
                 "selected": selected,
                 "kind": "content",
                 "nodes": nodes,
             })
     elif IAlchemistContainer.providedBy(context):
         # loop through all managed containers of the parent
         # object, and include the present container as the
         # "current" node.
         parent = context.__parent__
         assert parent is not None
         _url = url.absoluteURL(parent, self.request)
         
         # append managed containers as child nodes            
         if include_siblings is True:
             if IApplication.providedBy(parent):
                 containers = [ (name, parent[name])
                     for name in 
                         location.model_to_container_name_mapping.values()
                     if name in parent ]
             elif IReadContainer.providedBy(parent):
                 containers = list(parent.items())
             else:
                 containers = utils.get_managed_containers(parent)
         else:
             containers = [(context.__name__, context)]
         self.expand_containers(items, containers, _url, chain, context)
     elif ILocation.providedBy(context):
         # e.g. bungeni.core.content.Section, DisplayForm
         _url = url.absoluteURL(context, self.request)
         selected = len(chain) == 0
         if selected and IReadContainer.providedBy(context):
             nodes = []
             try:
                 self.expand_containers(
                     nodes, context.items(), _url, chain, context)
             except:
                 pass
         else:
             nodes = self.expand(chain)
         _title = getattr(context, "title", None) or \
             getattr(context, "page_title", "!+BungeniBrowserView.title")
         items.append({
                 "id": self.get_nav_entry_id(_url),
                 # !+BungeniBrowserView.title
                 "label": _title, #IDCDescriptiveProperties(context).title,
                 "url": _url,
                 "current": True,
                 "selected": selected,
                 "kind": "location",
                 "nodes": nodes,
             })
     elif IReadContainer.providedBy(context):
         #!+NavigationTreeViewlet-EXPAND-IReadContainer(mr, oct-2012) does this ever execute?!
         raise Exception("!+NavigationTreeViewlet-EXPAND-IReadContainer [%s]" % context)
         items.extend(self.expand(chain))
     return items
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:79,代码来源:navigation.py



注:本文中的zope.container.interfaces.IReadContainer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python contenttype.guess_content_type函数代码示例发布时间:2022-05-26
下一篇:
Python interfaces.IObjectAddedEvent类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap