Example #1
0
    def test_free_text_search(self):
        text = u'''
        This is a text that is not going to make any sense
        '''

        tokens = get_search_terms(text)
        self.assertNotEqual(len(tokens), 0)
Example #2
0
    def test_free_text_search(self):
        text = u'''
        This is a text that is not going to make any sense apart from containing
        a hostname for a server (aka example.com) and a rackunit aka R10U22
        '''

        tokens = get_search_terms(text)
        self.assertNotEqual(len(tokens), 0)
Example #3
0
    def test_free_text_search(self):
        text=u'''
        This is a text that is not going to make any sense apart from containing
        a hostname for a server (aka example.com) and a rackunit aka R10U22
        '''

        tokens = get_search_terms(text)
        self.assertNotEqual(len(tokens), 0)
Example #4
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 sent in a GET it will display results in txt and not in html
    format
    If csv is sent in a GET it will display results in text format separated by comma
    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'
    elif u'csv' in request.GET:
        template = 'results.csv'
        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_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)
Example #5
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 sent in a GET it will display results in txt and not in html
    format
    If csv is sent in a GET it will display results in text format separated by comma
    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'
    elif u'csv' in request.GET:
        template = 'results.csv'
        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',  # noqa
                        'model__vendor', 'allocation')

    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)