本文整理匯總了Python中zope.container.interfaces.IReadContainer類的典型用法代碼示例。如果您正苦於以下問題:Python IReadContainer類的具體用法?Python IReadContainer怎麽用?Python IReadContainer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了IReadContainer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
示例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)
示例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)
示例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
示例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))
示例6: getLengthOf
def getLengthOf(self, item):
res = -1
if IReadContainer.providedBy(item):
try:
res = len(item)
except (Unauthorized, Forbidden):
pass
return res
示例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)
示例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)
示例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
示例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))
示例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
示例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
示例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)
示例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)
示例15: matches
def matches(self, object):
if IReadContainer.providedBy(object):
return len(object) == self._count
else:
return False