Пример #1
0
def rack(request, rack_id):
    '''
    Rack view. It should display all non-authenticated user viewable data

    @type   request: HTTPRequest
    @param  request: Django HTTPRequest object
    @rtype: HTTPResponse
    @return: HTTPResponse object rendering corresponding HTML
    '''

    template = 'rack.html'

    rack = get_object_or_404(Rack, pk=rack_id)
    try:
        rack.prev = Rack.objects.filter(
                rackposition__position__lt=rack.rackposition.position,
                rackposition__rr=rack.rackposition.rr
                ).order_by('-rackposition__position')[0]
    except (IndexError, RackPosition.DoesNotExist):
        rack.prev = None
    try:
        rack.next = Rack.objects.filter(
                rackposition__position__gt=rack.rackposition.position,
                rackposition__rr=rack.rackposition.rr
                ).order_by('rackposition__position')[0]
    except (IndexError, RackPosition.DoesNotExist):
        rack.next = None

    equipments = functions.search(str(rack.name))
    equipments = functions.populate_tickets(equipments)
    equipments = functions.populate_hostnames(equipments)

    equipments = { 'hwdoc': functions.calculate_empty_units(rack, equipments), }

    return render(request, template, { 'rack': rack, 'equipments': equipments })
Пример #2
0
def search(request):
    '''
    Search view. Scans request for q (GET case) or qarea (POST case) and
    searches for corresponding instances in all subapps matching the query
    If txt is send in a GET it will display results in txt and not in html
    format

    @type   request: HTTPRequest
    @param  request: Django HTTPRequest object
    @rtype: HTTPResponse
    @return: HTTPResponse object rendering corresponding HTML
    '''

    if u'txt' in request.GET:
        template = 'results.txt'
        content_type = 'text/plain'
    else:
        template = 'results.html'
        content_type = 'text/html'

    if u'q' in request.GET:
        key = request.GET['q']
    elif u'qarea' in request.POST:
        key = projectwide_functions.get_search_terms(request.POST['qarea'])
    else:
        key = None

    results = {
        'hwdoc': None,
        'puppet': None,
        'updates': None,
        }

    results['puppet'] = puppet_functions.search(key).select_related()
    results['hwdoc'] = hwdoc_functions.search(key).select_related(
                        'servermanagement', 'rack', 'model',
                        'model__vendor', 'allocation')

    results['hwdoc'] = hwdoc_functions.populate_tickets(results['hwdoc'])
    results['hwdoc'] = hwdoc_functions.populate_hostnames(results['hwdoc'])

    try:
        return render(request, template,
                    { 'results': results, },
                    content_type=content_type)
    except TemplateSyntaxError as e:
        if re.search('too many SQL variables', e.message):
            return render(request, 'error.html', content_type=content_type)
Пример #3
0
def ticketed_equipment(request):
    '''
    Equipment with tickets view. It should display all non-authenticated user viewable data

    @type   request: HTTPRequest
    @param  request: Django HTTPRequest object
    @rtype: HTTPResponse
    @return: HTTPResponse object rendering corresponding HTML
    '''
    template = 'interesting_equipment.html'

    equipments = Equipment.objects.exclude(comments='')
    equipments = functions.populate_tickets(equipments)
    equipments = [x for x in equipments if hasattr(x, 'tickets')]
    equipments = { 'hwdoc': equipments }
    return render(request, template, { 'equipments': equipments })
Пример #4
0
def rack(request, rack_id):
    '''
    Rack view. It should display all non-authenticated user viewable data

    @type   request: HTTPRequest 
    @param  request: Django HTTPRequest object
    @rtype: HTTPResponse
    @return: HTTPResponse object rendering corresponding HTML
    '''

    template = 'rack.html'

    rack = get_object_or_404(Rack, pk=rack_id)
    equipments = functions.search(str(rack.pk))
    equipments = functions.populate_tickets(equipments)

    return render(request, template, { 'rack': rack, 'equipments': equipments })
Пример #5
0
def rackrow(request, rackrow_id):
    '''
    Rackrow view. It should display all non-authenticated user viewable data

    @type   request: HTTPRequest 
    @param  request: Django HTTPRequest object
    @rtype: HTTPResponse
    @return: HTTPResponse object rendering corresponding HTML
    '''

    template = 'rackrow.html'

    rackrow = get_object_or_404(RackRow, pk=rackrow_id)
    racks = rackrow.rackposition_set.select_related()
    for rack in racks:
        rack.equipments = functions.populate_tickets(
                rack.rack.equipment_set.select_related('model__vendor', 'model'))
    return render(request, template, {
        'rackrow': rackrow,
        'racks': racks,
        })
Пример #6
0
def equipment(request, equipment_id):
    '''
    Equipment view. It should display all non-authenticated user viewable data

    @type   request: HTTPRequest 
    @param  request: Django HTTPRequest object
    @rtype: HTTPResponse
    @return: HTTPResponse object rendering corresponding HTML
    '''

    template = 'equipment.html'

    equipment = get_object_or_404(Equipment,pk=equipment_id)
    equipment = functions.populate_tickets((equipment,))[0]
    try:
        equipment.prev = Equipment.objects.filter(rack=equipment.rack, unit__lt=equipment.unit).order_by('-unit')[0]
    except IndexError:
        equipment.prev = None
    try:
        equipment.next = Equipment.objects.filter(rack=equipment.rack, unit__gt=equipment.unit).order_by('unit')[0]
    except IndexError:
        equipment.next = None

    return render(request, template, { 'equipment': equipment, })
Пример #7
0
def search(request):
    '''
    Search view. Scans request for q (GET case) or qarea (POST case) and
    searches for corresponding Equipment instances matching the query
    If txt is send in a GET it will display results in txt and not in html
    format

    @type   request: HTTPRequest 
    @param  request: Django HTTPRequest object
    @rtype: HTTPResponse
    @return: HTTPResponse object rendering corresponding HTML
    '''

    if u'txt' in request.GET:
        template = 'results.txt'
        mimetype = 'text/plain'
    else:
        template = 'results.html'
        mimetype = 'text/html'

    if u'q' in request.GET:
        key = request.GET['q']
    elif u'qarea' in request.POST:
        key = functions.get_search_terms(request.POST['qarea'])
    else:
        key = None

    results = functions.search(key).select_related(
            'servermanagement', 'rack', 'model',
            'model__vendor', 'allocation') 

    results = functions.populate_tickets(results)

    return render(request, template,
            { 'results': results, },
            mimetype=mimetype)