Esempio n. 1
0
def store(request ,q):
    # if the search term is atleast three chars long , store in the
    if len(q)>2:
        term = SearchTerm()
        term.q = q
        term.user = None
        if request.user.is_authenticated():
            term.user = request.user
        term.save()
Esempio n. 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.user = None
        if request.user.is_authenticated():
            term.user = request.user
            term.save()
Esempio n. 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()
Esempio n. 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)
        if request.user.is_authenticated():
            term.user = request.user
        term.save()
Esempio n. 5
0
def store(request, q, matching):
    """ stores the search text """
    # if search term is at least three chars long, store in db
    if len(q) > 1:
        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
        # salvamos para que no nos salga el error: <SearchTerm: inst> need to have a value for field "searchterm"
        # before this many-to-many relationship can be used.
        term.save()
        for match in matching:
            term.found_products.add(match)
def update_search_stats(query, browser):
    """
    Here we update the stats in the database for the SearchTerm and the browser.

    We start by searching for our SearchTerm and browser in the database.
    In Part 1 we see if the SearchTerm already exists, and if so, we add 1
    to its counter. If not, we create a new SearchTerm in the database and 
    set its count to 1.
    In Part 2 we see if the SearchBrowser already exists, and if so, we add 1
    to its counter. If not, we create a new SearchBrowser in the database and 
    set its count to 1.
    """
    SearchTerm_exists=SearchTerm.objects.filter(name=query).exists()
    SearchBrowser_exists=SearchBrowser.objects.filter(name=browser).exists()
    #1.) The SearchTerm
    #if the search term already exists in the database
    if SearchTerm_exists == True:
        newSearchTerm=SearchTerm.objects.get(name=query)
        #find the count
        count=newSearchTerm.count
        #increase the count by 1
        count+=1
        newSearchTerm.count=count
        newSearchTerm.save()
    #if the search term does not exist yet
    elif (SearchTerm_exists == False):
        newSearchTerm=SearchTerm(name=query)
        newSearchTerm.count=1
        newSearchTerm.save()

    #2.) The SearchBrowser
    #if the browser already exists in the database
    if SearchBrowser_exists == True:
        newSearchBrowser=SearchBrowser.objects.get(name=browser)
        #find the count
        count=newSearchBrowser.count
        #increase the count by 1
        count+=1
        newSearchBrowser.count=count
        newSearchBrowser.save()
    #if the browser does not exist yet
    elif  SearchBrowser_exists == False:
        newSearchBrowser=SearchBrowser(name=browser)
        newSearchBrowser.count=1
        newSearchBrowser.save()