Exemple #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)
Exemple #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))
Exemple #3
0
def results(request, template_name="search/results.html"):
    # get current search phrase
    q = request.GET.get('q', '')
    reload(sys)
    sys.setdefaultencoding("latin-1")
    q = encode(str(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 = posts(q).get('posts')
    # generate the pagintor object
    paginator = Paginator(matching, POST_PER_PAGE)
    try:
        results = paginator.page(page).object_list
    except (InvalidPage, EmptyPage):
        results = paginator.page(1).object_list
    # store the search
    store(request, q)
    # the usual...
    page_title = 'Search Results for: ' + q
    return render_to_response(template_name, locals(),
    context_instance=RequestContext(request))
Exemple #4
0
def results(request, template_name="search/results.html"):
    # get current search phrase
    q = request.GET.get('q', '')
    reload(sys)
    sys.setdefaultencoding("latin-1")
    q = encode(str(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 = posts(q).get('posts')
    # generate the pagintor object
    paginator = Paginator(matching, POST_PER_PAGE)
    try:
        results = paginator.page(page).object_list
    except (InvalidPage, EmptyPage):
        results = paginator.page(1).object_list
    # store the search
    store(request, q)
    # the usual...
    page_title = 'Search Results for: ' + q
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))
Exemple #5
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))
Exemple #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)) 
Exemple #7
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())
Exemple #8
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))