<commit_before># django imports
from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.template.loader import render_to_string
from django.utils import simplejson

# lfs imports
from lfs.catalog.models import Category
from lfs.catalog.models import Product
from lfs.catalog.settings import STANDARD_PRODUCT, PRODUCT_WITH_VARIANTS, VARIANT

def livesearch(request, template_name="lfs/search/livesearch_results.html"):
    """
    """
    q = request.GET.get("q", "")

    if q == "":
        result = simplejson.dumps({
            "state" : "failure",
        })
    else:
        # Products
        query = Q(active=True) & \
                Q(name__icontains=q) | \
                Q(manufacturer__name__icontains=q) | \
                Q(sku_manufacturer__icontains=q) & \
                Q(sub_type__in = (STANDARD_PRODUCT, PRODUCT_WITH_VARIANTS, VARIANT))
        
        temp = Product.objects.filter(query)
        total = len(temp)
        products = temp[0:5]
        
        products = render_to_string(template_name, RequestContext(request, {
            "products" : products,
            "q" : q,
            "total" : total,
        }))
        
        result = simplejson.dumps({
            "state" : "success",
            "products" : products,
        })
    return HttpResponse(result)
    
def search(request, template_name="lfs/search/search_results.html"):
    """Returns the search result according to given query (via get request) 
    ordered by the globally set sorting.
    """
    q = request.GET.get("q", "")
    
    # Products
    query = Q(active=True) & \
            Q(name__icontains=q) | \
            Q(manufacturer__name__icontains=q) | \
            Q(sku_manufacturer__icontains=q) & \
            Q(sub_type__in = (STANDARD_PRODUCT, PRODUCT_WITH_VARIANTS, VARIANT))
    products = Product.objects.filter(query)

    # Sorting
    sorting = request.session.get("sorting")    
    if sorting: 
        products = products.order_by(sorting)
        
    total = 0
    if products:
        total += len(products)
        
    return render_to_response(template_name, RequestContext(request, {
        "products" : products,
        "q" : q,
        "total" : total,
    }))<commit_msg>fix bug where inactive products were showing up when a blank string was searched for<commit_after># django imports
from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.template.loader import render_to_string
from django.utils import simplejson

# lfs imports
from lfs.catalog.models import Category
from lfs.catalog.models import Product
from lfs.catalog.settings import STANDARD_PRODUCT, PRODUCT_WITH_VARIANTS, VARIANT

def livesearch(request, template_name="lfs/search/livesearch_results.html"):
    """
    """
    q = request.GET.get("q", "")

    if q == "":
        result = simplejson.dumps({
            "state" : "failure",
        })
    else:
        # Products
        query = Q(active=True) & \
                Q(name__icontains=q) | \
                Q(manufacturer__name__icontains=q) | \
                Q(sku_manufacturer__icontains=q) & \
                Q(sub_type__in = (STANDARD_PRODUCT, PRODUCT_WITH_VARIANTS, VARIANT))
        
        temp = Product.objects.filter(query)
        total = len(temp)
        products = temp[0:5]
        
        products = render_to_string(template_name, RequestContext(request, {
            "products" : products,
            "q" : q,
            "total" : total,
        }))
        
        result = simplejson.dumps({
            "state" : "success",
            "products" : products,
        })
    return HttpResponse(result)
    
def search(request, template_name="lfs/search/search_results.html"):
    """Returns the search result according to given query (via get request) 
    ordered by the globally set sorting.
    """
    q = request.GET.get("q", "")
    
    # Products
    query = Q(name__icontains=q) | \
            Q(manufacturer__name__icontains=q) | \
            Q(sku_manufacturer__icontains=q) & \
            Q(sub_type__in = (STANDARD_PRODUCT, PRODUCT_WITH_VARIANTS, VARIANT))
    products = Product.objects.filter(query).filter(active=True)

    # Sorting
    sorting = request.session.get("sorting")    
    if sorting: 
        products = products.order_by(sorting)
        
    total = 0
    if products:
        total += len(products)
        
    return render_to_response(template_name, RequestContext(request, {
        "products" : products,
        "q" : q,
        "total" : total,
    }))
{'fraction_non_alphanumeric': 0.10392074198988195, 'fraction_numerical': 0.0012647554806070826, 'mean_word_length': 2.384450784593438, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5244170', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1410, 'n_words': 301}