Пример #1
0
def _group_tree_branch(root_group, highlight_group_name=None, children=[]):
    '''Returns a branch of the group tree hierarchy, rooted in the given group.

    :param root_group_id: group object at the top of the part of the tree
    :param highlight_group_name: group name that is to be flagged 'highlighted'
    :returns: the top GroupTreeNode of the tree
    '''
    nodes = {}  # group_id: GroupTreeNode()
    root_node = nodes[root_group.id] = GroupTreeNode(
        {'id': root_group.id,
         'name': root_group.name,
         'title': root_group.title,
         'dataset_count': root_group.subtree_dataset_count})

    root_node.update(root_group.custom_extras)
    if root_group.name == highlight_group_name:
        nodes[root_group.id].highlight()
        highlight_group_name = None

    for group_id, group_name, group_title, parent_id, dataset_count, extras in children:
        node = GroupTreeNode({'id': group_id,
                              'name': group_name,
                              'title': group_title,
                              'dataset_count': dataset_count})
        if extras:
            node.update(extras)

        nodes[parent_id].add_child_node(node)

        if highlight_group_name and group_name == highlight_group_name:
            node.highlight()

        nodes[group_id] = node

    return root_node