Esempio n. 1
0
def teams_menu(href, selected=None):
    """
    Create menus for teams percent definitions.
    """
    teams = Team.objects.filter(billing_type='TIME').order_by('name')
    items = []
    for team in teams:
        item = MenuItem(
            team.name,
            name=team.name,
            subitems=[],
            fugue_icon='fugue-user-worker',
            href='{}/{}'.format(href, team.name),
            indent=' ',
            collapsed=True,
            collapsible=True,
        )
        if item.name == selected:
            item.kwargs['collapsed'] = False
        for dates in team.dateranges.values('start', 'end', 'id'):
            daterange = '{0} - {1}'.format(dates['start'], dates['end'])
            subitem = MenuItem(
                daterange,
                name=dates['id'],
                subitems=[],
                fugue_icon='fugue-clock',
                href='{}/{}/{}'.format(href, team.name, dates['id']),
                indent=' '
            )
            subitem.parent = item
            item.subitems.append(subitem)
        items.append(item)
    return items
Esempio n. 2
0
def ventures_menu(href='', selected=None):
    top_items = []
    stack = [
        (None, top_items, Venture.objects.root_nodes()),
    ]
    while stack:
        parent, items, ventures = stack.pop()
        for venture in ventures.order_by('name'):
            item = MenuItem(
                venture.name,
                name='{}'.format(venture.id),
                subitems=[],
                fugue_icon='fugue-store-medium',
                indent=' ',
                href='{}/{}/'.format(href, venture.id),
                collapsed=True,
                collapsible=True,
            )
            item.parent = parent
            items.append(item)
            stack.append((item, item.subitems, venture.get_children()))
            if item.name == selected:
                while item:
                    item.kwargs['collapsed'] = False
                    item = item.parent
    return top_items
Esempio n. 3
0
def ventures_menu(href='', selected=None):
    """
    Generate ventures submenu

    :param string href: base url for submenu items
    :param string selected: name of selected row
    :returns list: list of menu items
    :rtype list:
    """
    top_items = []
    stack = [
        (None, top_items, Venture.objects.root_nodes()),
    ]
    while stack:
        parent, items, ventures = stack.pop()
        for venture in ventures.order_by('name'):
            item = MenuItem(
                venture.name,
                name='{}'.format(venture.id),
                subitems=[],
                fugue_icon='fugue-store-medium',
                indent=' ',
                href='{}/{}/'.format(href, venture.id),
                collapsed=True,
                collapsible=True,
            )
            item.parent = parent
            items.append(item)
            stack.append((item, item.subitems, venture.get_children()))
            if item.name == selected:
                while item:
                    item.kwargs['collapsed'] = False
                    item = item.parent
    return top_items
Esempio n. 4
0
 def _get_menu(self, tree):
     items = []
     for bl_id, bl_data in tree.iteritems():
         bl_item = MenuItem(
             label=bl_data['name'],
             name='bl_%s' % bl_id,
             fugue_icon='fugue-tie',
             view_name='services',
             view_args=['bl-%s' % bl_id],
             indent=' ',
             collapsible=True,
             collapsed=False if self.businessline_id == str(bl_id) else True
         )
         bl_item.subitems = []
         for s_id, s_data in bl_data.get('childs', {}).iteritems():
             s_item = MenuItem(
                 label=s_data['name'],
                 name='bl_%s_s_%s' % (bl_id, s_id),
                 fugue_icon='fugue-disc-share',
                 view_name='services',
                 view_args=['bl-%s' % bl_id, 'ser-%s' % s_id],
                 indent=' ',
                 collapsible=True,
                 collapsed=False if self.service_id == str(s_id) else True
             )
             s_item.subitems = []
             for e_id, e_data in s_data.get('childs', {}).iteritems():
                 e_item = MenuItem(
                     label=e_data['name'],
                     name='bl_%s_s_%s_env_%s' % (bl_id, s_id, e_id),
                     fugue_icon='fugue-tree',
                     view_name='services',
                     view_args=[
                         'bl-%s' % bl_id, 'ser-%s' % s_id, 'env-%s' % e_id
                     ],
                     indent=' '
                 )
                 e_item.parent = s_item
                 s_item.subitems.append(e_item)
             s_item.parent = bl_item
             bl_item.subitems.append(s_item)
         items.append(bl_item)
     return items
Esempio n. 5
0
 def _get_menu(self, tree):
     items = []
     for bl_id, bl_data in tree.iteritems():
         bl_item = MenuItem(label=bl_data['name'],
                            name='bl_%s' % bl_id,
                            fugue_icon='fugue-tie',
                            view_name='services',
                            view_args=['bl-%s' % bl_id],
                            indent=' ',
                            collapsible=True,
                            collapsed=False
                            if self.businessline_id == str(bl_id) else True)
         bl_item.subitems = []
         for s_id, s_data in bl_data.get('childs', {}).iteritems():
             s_item = MenuItem(
                 label=s_data['name'],
                 name='bl_%s_s_%s' % (bl_id, s_id),
                 fugue_icon='fugue-disc-share',
                 view_name='services',
                 view_args=['bl-%s' % bl_id,
                            'ser-%s' % s_id],
                 indent=' ',
                 collapsible=True,
                 collapsed=False if self.service_id == str(s_id) else True)
             s_item.subitems = []
             for e_id, e_data in s_data.get('childs', {}).iteritems():
                 e_item = MenuItem(label=e_data['name'],
                                   name='bl_%s_s_%s_env_%s' %
                                   (bl_id, s_id, e_id),
                                   fugue_icon='fugue-tree',
                                   view_name='services',
                                   view_args=[
                                       'bl-%s' % bl_id,
                                       'ser-%s' % s_id,
                                       'env-%s' % e_id
                                   ],
                                   indent=' ')
                 e_item.parent = s_item
                 s_item.subitems.append(e_item)
             s_item.parent = bl_item
             bl_item.subitems.append(s_item)
         items.append(bl_item)
     return items
Esempio n. 6
0
def service_environments(href='', service=None, environment=None):
    service_environments = ServiceEnvironment.objects.all().select_related(
        'service',
        'environment',
    ).order_by('service__name', )
    items = {}
    for service_environment in service_environments:
        if service_environment.service.id in items:
            item = items[service_environment.service.id]
        else:
            item = MenuItem(
                service_environment.service.name,
                name=service_environment.service,
                subitems=[],
                fugue_icon='fugue-user-worker',
                href='{}/{}'.format(href, service_environment.service.id),
                indent=' ',
                collapsed=True,
                collapsible=True,
            )
            items[service_environment.service.id] = item

        if service_environment.service == service:
            item.kwargs['collapsed'] = False

        subitem = MenuItem(
            service_environment.environment.name,
            name="{0}_{1}".format(service_environment.service,
                                  service_environment.environment),
            subitems=[],
            fugue_icon='fugue-clock',
            href='{}/{}/{}'.format(href, service_environment.service.id,
                                   service_environment.environment.id),
            indent=' ',
        )
        subitem.parent = item
        item.subitems.append(subitem)
    return [v for k, v in items.iteritems()]
Esempio n. 7
0
def teams_menu(href, selected=None):
    """
    Generate teams percent definitions submenu

    :param string href: base url for submenu items
    :param string selected: name of selected row
    :returns list: list of menu items
    :rtype list:
    """
    teams = Team.objects.filter(
        billing_type=TeamBillingType.time).order_by('name')
    items = []
    for team in teams:
        item = MenuItem(
            team.name,
            name=team.name,
            subitems=[],
            fugue_icon='fugue-user-worker',
            href='{}/{}'.format(href, team.id),
            indent=' ',
            collapsed=True,
            collapsible=True,
        )
        if item.name == selected:
            item.kwargs['collapsed'] = False
        for dates in team.teamcost_set.values('start', 'end', 'id'):
            daterange = '{0} - {1}'.format(dates['start'], dates['end'])
            subitem = MenuItem(daterange,
                               name=dates['id'],
                               subitems=[],
                               fugue_icon='fugue-clock',
                               href='{}/{}/{}'.format(href, team.id,
                                                      dates['id']),
                               indent=' ')
            subitem.parent = item
            item.subitems.append(subitem)
        items.append(item)
    return items