示例#1
0
 def statefulTree(self, root=None, filter=None, tree_state=None):
     """Build a tree with tree state information from a request.
     """
     if root is None:
         root = self.context
     expanded_nodes = []
     if tree_state is not None:
         encoder = zope.component.getUtility(ITreeStateEncoder)
         expanded_nodes = encoder.decodeTreeState(tree_state)
     node = Node(root, expanded_nodes, filter)
     node.expand()
     return node
示例#2
0
 def statefulTree(self, root=None, filter=None, tree_state=None):
     """Build a tree with tree state information from a request.
     """
     if root is None:
         root = self.context
     expanded_nodes = []
     if tree_state is not None:
         encoder = zapi.getUtility(ITreeStateEncoder)
         expanded_nodes = encoder.decodeTreeState(tree_state)
     node = Node(root, expanded_nodes, filter)
     node.expand()
     return node
示例#3
0
    def test_children(self):
        # test hasChildren()
        root_node = self.root_node
        self.assertTrue(root_node.hasChildren())

        # test getChildNodes()
        children = [node.context for node in root_node.getChildNodes()]
        expected = [self.items['b'], self.items['c']]
        self.assertEqual(children, expected)

        # test with filter
        expand_all = self.items.keys()  # expand all nodes
        # emulate node expansion with the FilterByObject filter
        filter = FilterByObject([self.items[id] for id in self.expanded_nodes])
        filtered_root = Node(self.root_obj, expand_all, filter)
        children = [node.context for node in filtered_root.getChildNodes()]
        expected = [self.items['c']]
        self.assertEqual(children, expected)
示例#4
0
 def test_depth(self):
     expanded = ['a', 'c', 'f']
     root_node = Node(self.root_obj, expanded)
     flat, maxdepth = root_node.getFlatDicts()
     self.assertEqual(6, len(flat))
     self.assertEqual(2, maxdepth)
示例#5
0
 def makeItems(self):
     # this mapping will provide shortcuts to each object
     self.items = {}
     self.root_obj = make_item_from_tuple(tree, self.items)
     self.root_node = Node(self.root_obj, self.expanded_nodes)
示例#6
0
 def test_depth(self):
     expanded = ['a', 'c', 'f']
     root_node = Node(self.root_obj, expanded)
     flat, maxdepth = root_node.getFlatDicts()