Example #1
0
def store(request, q):
    if len(q) > 2:
        term = SearchTerm()
        term.q = q
        term.ip_address = request.META.get('REMOTE_ADDR')
        term.tracking_id = stats.tracking_id(request)
        term.user = None
        if request.user.is_authenticated():
            term.user = request.user
        term.save()
Example #2
0
def store(request, q):
    # if search term is at least three chars long, store in db
    if len(q) > 2:
        term = SearchTerm()
        term.q = q
        term.ip_address = request.META.get('REMOTE_ADDR')
        term.tracking_id = stats.tracking_id(request)
        if request.user.is_authenticated():
            term.user = request.user
        term.save()
Example #3
0
def store(request, q):
    if len(q) > 2:
        term = SearchTerm()
        term.q = q
        term.ip_address = request.META.get('REMOTE_ADDR')
        term.tracking_id = stats.tracking_id(request)
        term.user = None
        if request.user.is_authenticated:
            term.user = request.user
        term.save()
Example #4
0
def store(request, q):
    # if search term is at least three chars long, store in db
    if len(q) > 2:
        term = SearchTerm()
        term.q = q
        term.ip_address = request.META.get('REMOTE_ADDR')
        term.tracking_id = stats.tracking_id(request)
        term.user = None
        if request.user.is_authenticated():
            term.user = request.user
        term.save()
Example #5
0
def store(request, q):

    #only store for queries longer than two characters
    if len(q) > 2:
        term = SearchTerm()
        term.q = q
        term.ip_address = request.META.get('REMOTE_ADDR')
        from stats import stats
        term.tracking_id = stats.tracking_id(request)
        term.user = None

        if request.user.is_authenticated():
            term.user = request.user
        term.save()
Example #6
0
def store(request, q):
    """ stores the search text in the database """
    # if search term is at least three chars long, store in db
    if len(q) > 2:
        term = SearchTerm()
        term.q = q
        # Get the ip address of the user conducting the search
        term.ip_address = request.META.get('REMOTE_ADDR')
        # Store a tracking id with each search
        term.tracking_id = stats.tracking_id(request)
        term.user = None
        if request.user.is_authenticated:
            term.user = request.user
        term.save()
    def get(self, request, *args, **kwargs):
        sortForm = SortForm(request.GET or None)
        value = request.GET.get('query', '')
        sort_by = request.GET.get('sort_by', '')
        # store search query in the database
        if len(value) > 2:
            term = SearchTerm()
            term.query = value
            term.ip_address = request.META.get('REMOTE_ADDR')
            term.tracking_id = stats.tracking_id(request)
            term.user = None
            if request.user.is_authenticated:
                term.user = request.user
            term.save()
        products = ProductsSearch(request.GET or None,
                                  queryset=Item.objects.all())
        if sort_by:
            results_qs = products.qs.order_by(sort_by)
        else:
            results_qs = products.qs.order_by('price')
        print(request.get_full_path)
        paginator = Paginator(results_qs, 1)

        page = request.GET.get('page')
        try:
            results = paginator.page(page)
        except PageNotAnInteger:
            results = paginator.page(1)
        except EmptyPage:
            results = paginator.page(paginator.num_pages)

        context = {
            'object_list': products,
            'sortform': sortForm,
            'page': page,
            'results': results
        }
        return render(request, "products/products.html", context)