コード例 #1
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()
コード例 #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)
        term.user = None
        if request.user.is_authenticated:
            term.user = request.user
        term.save()
コード例 #3
0
ファイル: search.py プロジェクト: JesseWoods/spirit_buzz
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()
コード例 #4
0
ファイル: searchutils.py プロジェクト: arthurcode/arthurcode
def store(request, q, hits):
    """
     Store the search text in the database
    """
    if len(q) > 1:
        term = SearchTerm()
        term.q = q
        term.ip_address = request.META.get('REMOTE_ADDR')
        term.user = None
        term.hits = hits
        if request.user.is_authenticated():
            term.user = request.user
        term.full_clean()
        term.save()
コード例 #5
0
ファイル: search.py プロジェクト: c-j-j/ecomstore
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()
コード例 #6
0
def store(request, q):
    """
    Store the search text in the database, so that a further research could be
    made.
    """
    # If search text is longer than 3 characters, store it in the DB
    # " TODO: An obvious reimplementation of saving constraints required"
    if len(q) > 2:
        term = SearchTerm()
        term.q = q
        term.ip_address = request.META.get('REMOTE_ADDR')
        # term.tracking_id = stat_utils.get_tracking_id(request)
        term.user = None
        if request.user.is_authenticated():
            term.user = request.user
        # "TODO: serious security isssue. Injection possible. Fix!!"
        term.save()
コード例 #7
0
    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)