예제 #1
0
def _group_tree_branch(root_group, highlight_group_name=None, type="group"):
    """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,
    })
    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,
    ) in root_group.get_children_group_hierarchy(type=type):
        node = GroupTreeNode({
            "id": group_id,
            "name": group_name,
            "title": group_title
        })
        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
예제 #2
0
def _group_tree_branch(root_group, highlight_group_name=None, type='group', group_counts=None):
    '''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})
    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 in \
            root_group.get_children_group_hierarchy(type=type):
        node = GroupTreeNode({'id': group_id,
                              'name': group_name,
                              'title': group_title})
        if not group_counts or group_id in group_counts:
            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
def _nest_group_tree_list(group_tree_list, group_tree_leaf):
    '''Returns a tree branch composed by nesting the groups in the list.

    :param group_tree_list: list of groups to build a tree, first is root
    :returns: the top GroupTreeNode of the tree
    '''
    root_node = None
    last_node = None
    log.debug(group_tree_list)
    for group in group_tree_list:
        log.debug(group)
        node = GroupTreeNode({
            'id': group.id,
            'name': group.name,
            'description': group.description,
            #'image_display_url': group.image_display_url,
            'title': group.title
        })
        if not root_node:
            root_node = last_node = node
        else:
            last_node.add_child_node(node)
            last_node = node
    last_node.add_child_node(group_tree_leaf)
    return root_node
예제 #4
0
def _group_tree_branch(root_group, pkg_count, highlight_group_name=None, type='group'):
    '''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
    '''
    import pprint
    nodes = {}  # group_id: GroupTreeNode()
    
    #Calculate package count for root orgs
    root_count = pkg_count.get(root_group.name, 0)
    for group_id, group_name, group_title, parent_id in root_group.get_children_group_hierarchy(type=type):
        root_count += pkg_count.get(group_name, 0)
             
    root_node = nodes[root_group.id] = GroupTreeNode(
        {'id': root_group.id,
         'pkg_num': str(root_count),
         'name': root_group.name,
         'title': root_group.title,
         'is_top_org' : True})
    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 in \
            root_group.get_children_group_hierarchy(type=type):
        pkg_num = pkg_count.get(group_name, 0)
        node = GroupTreeNode({'id': group_id,
                             'pkg_num': str(pkg_num),
                              'name': group_name,
                              'title': group_title,
                              'is_top_org' : False})
        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
예제 #5
0
def _nest_group_tree_list(group_tree_list, group_tree_leaf):
    """Returns a tree branch composed by nesting the groups in the list.

    :param group_tree_list: list of groups to build a tree, first is root
    :returns: the top GroupTreeNode of the tree
    """
    root_node = None
    last_node = None
    for group in group_tree_list:
        node = GroupTreeNode({
            "id": group.id,
            "name": group.name,
            "title": group.title
        })
        if not root_node:
            root_node = last_node = node
        else:
            last_node.add_child_node(node)
            last_node = node
    last_node.add_child_node(group_tree_leaf)
    return root_node
예제 #6
0
 def gtn_from_group(grp):
     return GroupTreeNode(group_dictize(grp))