示例#1
0
def search(request):
    """Search for an IP device"""

    titles = NAVPATH
    errors = []
    netboxes = None
    query = None

    if 'query' in request.GET:
        search_form = SearchForm(request.GET)
        if search_form.is_valid():
            # Preprocess query string
            query = search_form.cleaned_data['query'].strip().lower()
            titles = titles + [("Search for %s" % query, )]
            netboxes = find_netboxes(errors, query)

            # If only one hit, redirect to details view
            if netboxes and len(netboxes) == 1:
                return ipdev_details(request, name=netboxes[0].sysname)
    else:
        search_form = SearchForm()

    return render_to_response('ipdevinfo/search.html', {
        'errors': errors,
        'netboxes': netboxes,
        'navpath': NAVPATH,
        'query': query,
        'title': create_title(titles),
        'search_form': search_form
    },
                              context_instance=RequestContext(
                                  request, processors=[search_form_processor]))
示例#2
0
def search(request):
    """Search for an IP device"""

    titles = NAVPATH
    errors = []
    netboxes = None
    query = None

    if 'query' in request.GET:
        search_form = SearchForm(request.GET)
        if search_form.is_valid():
            # Preprocess query string
            query = search_form.cleaned_data['query'].strip().lower()
            titles = titles + [("Search for %s" % query,)]
            netboxes = find_netboxes(errors, query)

            # If only one hit, redirect to details view
            if netboxes and len(netboxes) == 1:
                return ipdev_details(request, name=netboxes[0].sysname)
    else:
        search_form = SearchForm()

    return render_to_response('ipdevinfo/search.html',
                              {'errors': errors, 'netboxes': netboxes,
                               'navpath': NAVPATH, 'query': query,
                               'title': create_title(titles),
                               'search_form': search_form},
                              context_instance=RequestContext(
                                  request, processors=[search_form_processor]))
示例#3
0
def search_form_processor(request):
    """Add populated search form to context"""
    context_extras = {}
    # FIXME Use request.REQUEST?
    if request.method == 'GET':
        context_extras['search_form'] = SearchForm(request.GET, auto_id=False)
    elif request.method == 'POST':
        context_extras['search_form'] = SearchForm(request.POST, auto_id=False)
    return context_extras