예제 #1
0
파일: layout.py 프로젝트: lenadax/cone.app
 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)
예제 #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 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)
예제 #3
0
파일: layout.py 프로젝트: SaiyaGin/cone.app
    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
예제 #4
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
예제 #5
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
예제 #6
0
def node_path(node):
    return [safe_decode(p) for p in node.path if p is not None]
예제 #7
0
def node_path(node):
    # XXX: implement in ``BaseNode``.
    return [safe_decode(p) for p in node.path if p is not None]
예제 #8
0
def node_path(node):
    # XXX: implement in ``BaseNode``.
    return [safe_decode(p) for p in node.path if p is not None]
예제 #9
0
 def test_safe_decode(self):
     self.assertEqual(safe_decode(b'\xc3\xa4\xc3\xb6\xc3\xbc'), u'äöü')
     self.assertEqual(safe_decode(u'already_unicode'), u'already_unicode')
예제 #10
0
 def test_safe_decode(self):
     self.assertEqual(safe_decode(b'\xc3\xa4\xc3\xb6\xc3\xbc'), u'äöü')
     self.assertEqual(safe_decode(u'already_unicode'), u'already_unicode')
예제 #11
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
예제 #12
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)
예제 #13
0
 def __getattr__(self, name):
     try:
         value = self.config().get(self.properties_section, name)
         return safe_decode(value, encoding=self.encoding)
     except configparser.NoOptionError:
         return None
예제 #14
0
 def __getattr__(self, name):
     try:
         value = self.config().get(self.properties_section, name)
         return safe_decode(value, encoding=self.encoding)
     except configparser.NoOptionError:
         return None
예제 #15
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
예제 #16
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)