Exemplo n.º 1
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 self.request.has_permission('view', node):
             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 == safe_decode(key)
         icon = node_icon(node)
         css = ''
         if IWorkflowState.providedBy(node):
             css = 'state-%s' % node.state
         child = self.navtreeitem(title, url, target, node_path(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 = node_path(self.model)
             if default_child:
                 selected_path.append(default_child.name)
             selected = False
             # XXX: probably superfluous. keep as of cone.app 1.1
             # if selected_path == node_path(node):
             #     selected = True
             child['selected'] = selected
         tree['children'].append(child)
Exemplo n.º 2
0
    def items_for(self, model, breakpoint=None):
        items = list()
        for node in LocationIterator(model):
            title = node.metadata.title
            title = safe_decode(title) if title else title
            items.append({
                'title': title,
                'url': self.item_url(node),
                'target': self.item_target(node),
                'selected': False,
                'id': node.name,
                'default_child': node.properties.default_child,
            })
            if node is breakpoint:
                break
        items.reverse()
        ret = list()
        count = len(items)
        for i in range(count):
            default_child = items[i]['default_child']
            if default_child \
                    and i < count - 1 \
                    and default_child == items[i + 1]['id']:
                continue
            ret.append(items[i])

        # XXX: this is crap!
        if not breakpoint:
            ret[0]['title'] = 'Home'

        ret[-1]['selected'] = True
        return ret
Exemplo n.º 3
0
 def __getattr__(self, name):
     if name == '__provides__':
         return self.__getattribute__(name)
     try:
         value = self.config().get(self.properties_section, name)
         return safe_decode(value, encoding=self.encoding)
     except configparser.NoOptionError:
         return None
Exemplo n.º 4
0
 def treerepr(self, indent=0, prefix=' '):
     res = '{}{}\n'.format(indent * prefix, self.noderepr)
     items = self.items() \
         if IOrdered.providedBy(self) \
         else sorted(self.items(), key=lambda x: safe_decode(x[0]))
     for key, value in items:
         if INode.providedBy(value):
             res += value.treerepr(indent=indent + 2, prefix=prefix)
         else:
             res += '{}{}: {}\n'.format((indent + 2) * prefix, key,
                                        repr(value))
     return res
Exemplo n.º 5
0
    def make_url(self, params, path=None, include_view=False):
        """Create URL considering ``query_whitelist``.

        :param params: Dictionary with query parameters.
        :param path: Optional model path, if ``None``, path gets taken from
            ``self.model``
        :param include_view: Boolean whether to include
            ``self.related_view`` to URL.
        :return: URL as string.
        """
        return safe_decode(
            make_url(self.request,
                     path=path,
                     node=None if path else self.model,
                     resource=self.related_view if include_view else None,
                     query=self.make_query(params)))
Exemplo n.º 6
0
def node_path(node):
    # XXX: implement in ``BaseNode``.
    return [safe_decode(p) for p in node.path if p is not None]
Exemplo n.º 7
0
 def get(self, key, default=None):
     try:
         value = self.config().get(self.properties_section, key)
         return safe_decode(value, encoding=self.encoding)
     except configparser.NoOptionError:
         return default
Exemplo n.º 8
0
 def __getitem__(self, key):
     try:
         value = self.config().get(self.properties_section, key)
         return safe_decode(value, encoding=self.encoding)
     except configparser.NoOptionError:
         raise KeyError(key)