Пример #1
0
 def menuitems(self):
     ret = list()
     count = 0
     path = nodepath(self.model)
     if path:
         curpath = path[0]
     else:
         curpath = ''
     # work with ``self.model.root.keys()``, ``values()`` propably not works
     # due to the use of factory node.
     root = self.model.root
     # check for default child id if no curpath
     if not curpath and root.properties.default_child:
         curpath = root.properties.default_child
     # check wether to render mainmenu item title
     empty_title = root.properties.mainmenu_empty_title
     for key in root.keys():
         child = root[key]
         if not has_permission('view', child, self.request):
             continue
         item = dict()
         item['id'] = key
         if empty_title:
             item['title'] = ' '
             item['description'] = child.metadata.title
         else:
             item['title'] = child.metadata.title
             item['description'] = child.metadata.description
         item['url'] = make_url(self.request, path=[key])
         item['selected'] = curpath == key
         item['first'] = count == 0
         ret.append(item)
         count += 1
     return ret
Пример #2
0
 def vocab(self):
     ret = list()
     path = nodepath(self.model)
     count = len(self.model.keys())
     pages = count / self.contents.slicesize
     if count % self.contents.slicesize != 0:
         pages += 1
     current = self.request.params.get("b_page", "0")
     sort = self.request.params.get("sort", "")
     for i in range(pages):
         query = make_query(b_page=str(i), sort=sort)
         url = make_url(self.request, path=path, query=query)
         ret.append({"page": "%i" % (i + 1), "current": current == str(i), "visible": True, "url": url})
     return ret
Пример #3
0
 def fillchildren(self, model, path, tree):
     if path:
         curpath = path[0]
     else:
         curpath = None
     for key in model:
         node = model[key]
         if not has_permission('view', node, self.request):
             continue
         if not node.properties.get('in_navtree'):
             continue
         title = node.metadata.title
         url = make_url(self.request, node=node)
         curnode = curpath == key and True or False
         child = self.navtreeitem(title, url, nodepath(node))
         child['showchildren'] = curnode
         if curnode:
             self.fillchildren(node, path[1:], child)
         selected = False
         if nodepath(self.model) == nodepath(node):
             selected = True
         child['selected'] = selected
         child['showchildren'] = curnode
         tree['children'].append(child)
Пример #4
0
 def navtree(self):
     root = self.navtreeitem(None, None, '')
     model = self.model.root
     path = nodepath(self.model)
     self.fillchildren(model, path, root)
     return root