Beispiel #1
0
Datei: list.py Projekt: emjemj/ni
def list_rooms(request):
    q = """
        MATCH (room:Room)
        RETURN room
        ORDER BY room.name
        """

    room_list = nc.query_to_list(nc.graphdb.manager, q)
    urls = get_node_urls(room_list)

    table = Table('Name', 'Location')
    for item in room_list:
        room = item.get('room')
        nh = get_object_or_404(NodeHandle, pk=room.get('handle_id'))
        node = nh.get_node()
        location_path = node.get_location_path()
        table.rows.append(
            TableRow(item['room'], location_path.get('location_path')))

    table.no_badges = True

    return render(request, 'noclook/list/list_generic.html', {
        'table': table,
        'name': 'Rooms',
        'urls': urls
    })
Beispiel #2
0
def role_detail(request, handle_id):
    role = get_object_or_404(Role, pk=handle_id)

    con_list = nc.models.RoleRelationship.get_contacts_with_role_name(
        role.name)
    urls = []
    rows = []

    for x, y in con_list:
        con_node = NodeHandle.objects.get(handle_id=x.data['handle_id'])
        org_node = NodeHandle.objects.get(handle_id=y.data['handle_id'])
        urls.append((con_node.get_absolute_url(), org_node.get_absolute_url()))
        rows.append(_contact_with_role_table(con_node, org_node))

    table = Table('Name', 'Organization')
    table.rows = rows
    table.no_badges = True

    return render(
        request, 'noclook/detail/role_detail.html', {
            'table': table,
            'name': role.name,
            'slug': 'role',
            'urls': urls,
            'node_handle': role
        })
Beispiel #3
0
Datei: list.py Projekt: emjemj/ni
def list_racks(request):
    q = """
        MATCH (rack:Rack)
        OPTIONAL MATCH (rack)<-[:Has]-(loc)
        OPTIONAL MATCH p=(loc)<-[:Has*0..20]-()
        WITH COLLECT(nodes(p)) as paths, MAX(length(nodes(p))) AS maxLength, rack AS rack
        WITH FILTER(path IN paths WHERE length(path)=maxLength) AS longestPaths, rack AS rack
        UNWIND CASE WHEN longestPaths = [] THEN [null] ELSE longestPaths END as location_path
        RETURN rack, reverse(location_path) as location_path
        ORDER BY rack.name
        """

    rack_list = nc.query_to_list(nc.graphdb.manager, q)
    urls = get_node_urls(rack_list)

    table = Table('Name', 'Location')
    table.no_badges = True

    for item in rack_list:
        rack = item.get('rack')
        location_path = item.get('location_path')
        table.rows.append(TableRow(rack, location_path))

    return render(request, 'noclook/list/list_generic.html', {
        'table': table,
        'name': 'Racks',
        'urls': urls
    })
Beispiel #4
0
Datei: list.py Projekt: SUNET/ni
def list_roles(request):
    role_list = Role.objects.all()

    table = Table('Name', 'Description')
    table.rows = [_role_table(role) for role in role_list]
    table.no_badges = True

    return render(request, 'noclook/list/list_generic.html', {
        'table': table,
        'name': 'Roles',
        'urls': role_list
    })
Beispiel #5
0
def list_customers(request):
    q = """
        MATCH (customer:Customer)
        RETURN customer
        ORDER BY customer.name
        """
    customer_list = nc.query_to_list(nc.graphdb.manager, q)
    urls = get_node_urls(customer_list)

    table = Table('Name', 'Description')
    table.rows = [_customer_table(customer) for customer in customer_list]
    table.no_badges = True

    return render(request, 'noclook/list/list_generic.html', {
        'table': table,
        'name': 'Customers',
        'urls': urls
    })
Beispiel #6
0
def list_sites(request):
    q = """
        MATCH (site:Site)
        RETURN site
        ORDER BY site.country_code, site.name
        """

    site_list = nc.query_to_list(nc.graphdb.manager, q)
    urls = get_node_urls(site_list)

    table = Table('Country', 'Site name', 'Area')
    table.rows = [_site_table(item['site']) for item in site_list]
    table.no_badges = True

    return render(request, 'noclook/list/list_generic.html', {
        'table': table,
        'name': 'Sites',
        'urls': urls
    })
Beispiel #7
0
Datei: list.py Projekt: SUNET/ni
def list_contacts(request):
    q = """
        MATCH (con:Contact)
        OPTIONAL MATCH (con)-[:Works_for]->(org:Organization)
        RETURN con.handle_id AS con_handle_id, con, count(DISTINCT org), org
        """

    con_list = nc.query_to_list(nc.graphdb.manager, q)
    contact_list = {}

    for row in con_list:
        con_handle_id = row['con_handle_id']
        org_list = []

        if con_handle_id in contact_list.keys():
            org_list = contact_list[con_handle_id]['org_list']

        new_org_name = ''
        if 'org' in row and row['org']:
            new_org_name = row['org'].get('name', '')

        org_list.append(new_org_name)

        contact_list[con_handle_id] = {
            'con': row['con'],
            'org_list': org_list,
            'org': ', '.join(org_list)
        }

    con_list = contact_list.values()
    urls = get_node_urls(con_list)

    table = Table('Name', 'Organization')
    table.rows = [
        _contact_table(item['con'], item['org']) for item in con_list
    ]
    table.no_badges = True

    return render(request, 'noclook/list/list_generic.html', {
        'table': table,
        'name': 'Contacts',
        'urls': urls
    })
Beispiel #8
0
def list_racks(request):
    q = """
        MATCH (rack:Rack)
        OPTIONAL MATCH (rack)<-[:Has]-(site)
        RETURN rack, site
        ORDER BY site.name, rack.name
        """

    rack_list = nc.query_to_list(nc.graphdb.manager, q)
    urls = get_node_urls(rack_list)

    table = Table('Site', 'Name')
    table.rows = [TableRow(item['site'], item['rack']) for item in rack_list]
    table.no_badges = True

    return render(request, 'noclook/list/list_generic.html', {
        'table': table,
        'name': 'Racks',
        'urls': urls
    })
Beispiel #9
0
Datei: list.py Projekt: SUNET/ni
def list_organizations(request):
    q = """
        MATCH (org:Organization)
        OPTIONAL MATCH (parent_org)-[:Parent_of]->(org:Organization)
        RETURN org, parent_org
        ORDER BY org.name
        """

    org_list = nc.query_to_list(nc.graphdb.manager, q)
    urls = get_node_urls(org_list)

    table = Table('Name', 'Parent Org.')
    table.rows = []
    orgs_dict = {}

    for item in org_list:
        org = item['org']
        parent_org = item['parent_org']
        org_handle_id = org.get('handle_id')

        if org_handle_id not in orgs_dict:
            orgs_dict[org_handle_id] = {'org': org, 'parent_orgs': []}

        if item['parent_org']:
            orgs_dict[org_handle_id]['parent_orgs'].append(item['parent_org'])

    for org_dict in orgs_dict.values():
        table.rows.append(
            _organization_table(org_dict['org'], org_dict['parent_orgs']))

    table.no_badges = True

    return render(request, 'noclook/list/list_generic.html', {
        'table': table,
        'name': 'Organizations',
        'urls': urls
    })