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, 'kind': 'location', 'nodes': nodes, }) elif IReadContainer.providedBy(context): items.extend(self.expand(chain)) return items
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
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, 'kind': 'location', 'nodes': nodes, }) elif IReadContainer.providedBy(context): items.extend(self.expand(chain)) return items
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