Example #1
0
def results(request):
    #get the current search words
    q = request.GET.get('q', '')
    #get current page number, set to 1 if missing
    try:
        page = int(request.GET.get('page', 1))
    except ValueError:
        page = 1
    #retrieve the matching products
    matching = search.products(q).get('products')
    #generate the paginator object
    paginator = Paginator(matching, settings.PRODUCTS_PER_PAGE)
    try:
        results = paginator.page(page).object_list
    except (InvalidPage, EmptyPage):
        results = paginator.page(1).object_list
    #store the search
    search.store(request, q)
    page_title = 'Search Results for:' + q
    template = 'search/results.html'
    context = {
        'page_title': page_title,
        'q': q,
        'page': page,
        'paginator': paginator,
        'results': results,
    }
    return render(request, template, context)
Example #2
0
def results(request):
    # get current search phrase
    q = request.GET.get('q', '')

    if q:
        request.session['search_key'] = q
    else:
        q = request.session.get('search_key', '')
    cache_key = 'search_cache' + q
    matching = cache.get(cache_key)
    if not matching:
        matching = search.products(q)
        cache.set(cache_key, matching, settings.CACHE_TIMEOUT)
    if matching:
        products, order_by_form = order_products(request, matching)
        num_x_pag, product_per_pag_form = get_num_x_pag(request)
        products, order_by_brand_form = filter_products(request, products)
        paginator, products_per_pag = get_paginator(request, products,
                                                    num_x_pag)
        show_toolbar = True
    else:
        show_toolbar = False
        paginator, products_per_pag = get_paginator(request, [], 1)

    product_row = get_product_row(products_per_pag)

    search.store(request, q, matching)
    page_title = 'Search Results for: ' + q
    title_head = "Resultados"
    return render_to_response("tags/product_list.html",
                              locals(),
                              context_instance=RequestContext(request))
Example #3
0
def results(request, template_name="search/results.html"):
    q = request.GET.get('q', '')
    try:
        page = int(request.GET.get('page', 1))
    except ValueError:
        page = 1
    matching = search.products(q).get('products')
    paginator = Paginator(matching,
                          settings.PRODUCTS_PER_PAGE)
    try:
        results = paginator.page(page).object_list
    except (InvalidPage, EmptyPage):
        results = paginator.page(1).object_list
    search.store(request, q)
    page_title = 'Search Results for: ' + q
    return render_to_response(template_name, locals(),
                              context_instance=RequestContext(request))
Example #4
0
def results(request, template_name="search/results.html"):
    # get current search phrase
    q = request.GET.get('q', '')
    # get current page number. Set to 1 is missing or invalid
    try:
        page = int(request.GET.get('page', 1))
    except ValueError:
        page = 1
    # retrieve the matching products
    matching = search.products(q).get('products')
    # generate the pagintor object
    paginator = Paginator(matching,settings.PRODUCTS_PER_PAGE)
    try:
        results = paginator.page(page).object_list
    except (InvalidPage, EmptyPage):
        results = paginator.page(1).object_list
    # store the search
    search.store(request, q)
    page_title = 'Search Results for: ' + q
    return render_to_response(template_name, locals(), context_instance=RequestContext(request)) 
Example #5
0
def results(request):
    # get current search phrase
    q = request.GET.get('q', '')
    # get current page number. Set to ! missng or invalid
    try:
        page = int(request.GET.get('page', 1))
    except ValueError:
        page = 1
    # retrieve the matching products
    matching = search.products(q).get('products')
    # generate the paginator object
    paginator = Paginator(matching, settings.PRODUCTS_PER_PAGE)
    try:
        results = paginator.page(page).object_list
    except (InvalidPage, EmptyPage):
        results = paginator.page(1).object_list
    #store the search
    search.store(request, q)
    # the usual
    page_title = 'Search Results for:' + q
    return render(request, 'search/results.html', locals())
Example #6
0
def results(request, template_name="search/results.html"):
    # get current search phrase
    q = request.GET.get('q', '')
    # get current page number. Set to 1 is missing or invalid
    try:
        page = int(request.GET.get('page', 1))
    except ValueError:
        page = 1
    # retrieve the matching products
    matching = search.products(q).get('products')
    # generate the pagintor object
    paginator = Paginator(matching, settings.PRODUCTS_PER_PAGE)
    try:
        results = paginator.page(page).object_list
    except (InvalidPage, EmptyPage):
        results = paginator.page(1).object_list
    # store the search
    search.store(request, q)
    page_title = 'Search Results for: ' + q
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))