示例#1
0
 def navtree(self):
     root = self.navtreeitem(None, None, None, "", None)
     model = self.navroot
     # XXX: default child
     path = nodepath(self.model)[len(nodepath(model)) :]
     self.fillchildren(model, path, root)
     return root
示例#2
0
 def fillchildren(self, model, path, tree):
     """XXX: consider cone.app.interfaces.INavigationLeaf
     """
     curpath = None
     if path:
         curpath = path[0]
     default_child = None
     if model.properties.default_child:
         if not curpath or curpath == model.properties.default_child:
             default_child = model[model.properties.default_child]
     if default_child and default_child.properties.hide_if_default:
         model = default_child
         default_child = None
         if path:
             path = path[1:]
             if path:
                 curpath = path[0]
     if default_child:
         if not curpath:
             curpath = model.properties.default_child
     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
         if title:
             title = safe_decode(title)
         url = make_url(self.request, node=node)
         query = make_query(contenttile=node.properties.default_content_tile)
         target = make_url(self.request, node=node, query=query)
         curnode = curpath == key and True or False
         icon = node_icon(self.request, node)
         css = ""
         if IWorkflowState.providedBy(node):
             css = "state-%s" % node.state
         child = self.navtreeitem(title, url, target, nodepath(node), icon, css)
         child["showchildren"] = curnode
         if curnode:
             child["selected"] = True
             if default_child:
                 self.fillchildren(default_child, path[1:], child)
             else:
                 self.fillchildren(node, path[1:], child)
         else:
             selected_path = nodepath(self.model)
             if default_child:
                 selected_path.append(default_child.name)
             selected = False
             if selected_path == nodepath(node):
                 selected = True
             child["selected"] = selected
         tree["children"].append(child)
示例#3
0
 def vocab(self):
     ret = list()
     path = nodepath(self.model)
     count = self.references_tile.item_count
     slicesize = self.references_tile.slicesize
     pages = count / slicesize
     if count % slicesize != 0:
         pages += 1
     current = self.request.params.get('b_page', '0')
     params = {
         UX_IDENT: UX_FRONTEND,
         'submitter_came_from': submitter_came_from(self.request),
         'size': slicesize,
     }
     for i in range(pages):
         params['b_page'] = str(i)
         query = make_query(**params)
         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
示例#4
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
示例#5
0
 def navtree(self):
     root = self.navtreeitem(None, None, '', None)
     model = self.model.root
     # XXX: default child
     path = nodepath(self.model)
     self.fillchildren(model, path, root)
     return root
示例#6
0
 def menuitems(self):
     ret = list()
     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
     root_props = root.properties
     # check for default child id if no curpath
     if not curpath and root_props.default_child:
         curpath = root_props.default_child
     # check wether to render mainmenu item title
     empty_title = root_props.mainmenu_empty_title
     # XXX: icons
     for key in root.keys():
         child = root[key]
         props = child.properties
         if self.ignore_node(child, props):
             continue
         selected = curpath == key
         item = self.create_item(child, props, empty_title, selected)
         if props.mainmenu_display_children:
             item["children"] = self.create_children(child, selected)
         else:
             item["children"] = None
         ret.append(item)
     return ret
示例#7
0
 def vocab(self):
     ret = list()
     path = nodepath(self.model)
     count = self.table_tile.item_count
     slicesize = self.table_tile.slicesize
     pages = count / slicesize
     if count % slicesize != 0:
         pages += 1
     current = self.request.params.get('b_page', '0')
     params = {
         'sort': self.table_tile.sort_column,
         'order': self.table_tile.sort_order,
         'size': slicesize,
         'term': self.table_tile.filter_term,
     }
     for term in self.table_tile.query_whitelist:
         params[term] = self.request.params.get(term, '')
     for i in range(pages):
         params['b_page'] = str(i)
         query = make_query(**params)
         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
示例#8
0
 def fillchildren(self, model, path, tree):
     curpath = None
     if path:
         curpath = path[0]
     default_child = None
     if model.properties.default_child:
         if not curpath or curpath == model.properties.default_child:
             default_child = model[model.properties.default_child]
     if default_child and default_child.properties.hide_if_default:
         model = default_child
         default_child = None
     if default_child:
         if not curpath:
             curpath = model.properties.default_child
     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
         icon = node_icon_url(self.request, node)
         child = self.navtreeitem(title, url, nodepath(node), icon)
         child['showchildren'] = curnode
         if curnode:
             child['selected'] = True
             if default_child:
                 self.fillchildren(default_child, path[1:], child)
             else:
                 self.fillchildren(node, path[1:], child)
         else:
             selected_path = nodepath(self.model)
             if default_child:
                 selected_path.append(default_child.name)
             selected = False
             if selected_path == nodepath(node):
                 selected = True
             child['selected'] = selected
         tree['children'].append(child)
示例#9
0
def index_media(media):
    body = ' '.join([
        media.metadata.get('title', ''),
        media.metadata.get('description', ''), 
        media.metadata.get('author', ''),
    ])
    index_doc(solr_config(media),
              media,
              path='/'.join(nodepath(media)),
              repository=media.__parent__.metadata.title,
              type='Media',
              body=body)
示例#10
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
示例#11
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)
示例#12
0
def index_revision(revision):
    path = '/'.join(nodepath(revision))
    physical_path = '/'.join(nodepath(revision.model))
    try:
        size = os.path.getsize('%s.binary' % physical_path)
    except OSError:
        size = 0
    body = ' '.join([
        revision.metadata.get('title', ''),
        revision.metadata.get('description', ''), 
        revision.metadata.get('author', ''),
        revision.metadata.get('alttag', ''),
        ', '.join(revision.metadata.get('keywords', [])),
    ])
    mimetype = revision.metadata.get('mimetype', '')
    index_doc(solr_config(revision),
              revision,
              type='Revision',
              mimetype=mimetype,
              revision=revision.model.__name__,
              path=path,
              physical_path=physical_path,
              size=size,
              body=body)
示例#13
0
 def vocab(self):
     ret = list()
     path = nodepath(self.model)
     count = len(self.items)
     pages = count // self.slicesize
     if count % self.slicesize != 0:
         pages += 1
     current = self.listing.current_page
     for i in range(pages):
         ret.append({
             'page': '%i' % (i + 1),
             'current': current == i,
             'visible': True,
             'target': self.listing.batch_target(path, i)
         })
     return ret
示例#14
0
 def create_children(self, node, selected):
     children = list()
     path = nodepath(self.model)
     if path and len(path) > 1 and path[0] == node.name:
         curpath = path[1]
     else:
         curpath = ""
     for key in node.keys():
         child = node[key]
         props = child.properties
         if self.ignore_node(child, props):
             continue
         selected = curpath == key
         item = self.create_item(child, props, False, selected)
         children.append(item)
     return children
示例#15
0
 def vocab(self):
     ret = list()
     path = nodepath(self.model)
     count = len(self.items)
     pages = count / self.slicesize
     if count % self.slicesize != 0:
         pages += 1
     current = self.request.params.get('b_page', '0')
     for i in range(pages):
         query = make_query(b_page=str(i))
         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
示例#16
0
 def vocab(self):
     ret = list()
     path = nodepath(self.model)
     count = len(self.items)
     pages = count / self.slicesize
     if count % self.slicesize != 0:
         pages += 1
     current = self.request.params.get('b_page', '0')
     for i in range(pages):
         query = make_query(b_page=str(i))
         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