Пример #1
0
def city_search(request):
    context = {}
    context['request'] = request
    # states = State.objects.all().order_by("name")
    # context['states'] = states
    states = []
    

    if (request.method == 'POST'):
        form = Search(request.POST)
        context['form'] = form
        if (form.is_valid()):
            search = form.cleaned_data['search']
            context['search'] = search
            if (search != None):
                cities = Area.objects.filter(city__icontains=search).order_by("city")
                states = State.objects.filter(id__in=cities.values_list('state_id', flat=True))

                context['states'] = states.order_by("name")

            else:
                # cities = Area.objects.all().order_by("city")[:100]
                cities = None
                context['states'] = State.objects.all().order_by("name")
    else:
        form = Search()
        context['form'] = form
        cities = None
           

    context['cities'] = cities
    return render_to_response('city_search.html',context, context_instance=RequestContext(request))
Пример #2
0
def search_func(request, films_on_page=10):
    if request.GET.get("page",
                       False) and int(request.GET.get("page", False)) != 1:
        query_page = "[int(request.GET.get('page', False)) * films_on_page - films_on_page:int(request.GET.get('page', False)) * films_on_page ]"
    else:
        query_page = "[:films_on_page]"
    search_query = "Films.objects"
    search_form = Search(request.GET)
    if search_form.is_valid():
        form = search_form.cleaned_data
    if form["name"] != "":
        search_query += ".filter(name='" + form["name"].strip() + "')"
    if form["director"] != "":
        search_query += ".filter(director='" + form["director"].strip() + "')"
    for item in request.GET:
        if "author_" in item:
            search_query += ".filter(authors__name__exact='" + devideAuthors(
                item).strip() + "')"
        if "actor_" in item:
            search_query += ".filter(actors__name__exact='" + devideActors(
                item).strip() + "')"
    if "genre" in request.GET:
        search_query += ".filter(genre__name='" + request.GET["genre"] + "')"
    if "start_date" in request.GET:
        search_query += ".filter(release_date__range=('" + request.GET[
            "start_date"] + "-01-01','" + request.GET["end_date"] + "-12-31'))"
    films_list = eval(search_query + query_page)
    films_count = eval(search_query).count()
    return films_list, range((films_count / films_on_page) + 1 if films_count % films_on_page == 0\
                                                               else (films_count / films_on_page) + 2), True
Пример #3
0
def search_func(request, films_on_page = 10):
    if request.GET.get("page", False) and int(request.GET.get("page", False)) != 1:
        query_page = "[int(request.GET.get('page', False)) * films_on_page - films_on_page:int(request.GET.get('page', False)) * films_on_page ]"
    else:
        query_page = "[:films_on_page]"
    search_query = "Films.objects"
    search_form = Search(request.GET)
    if search_form.is_valid():
        form = search_form.cleaned_data
    if form["name"] != "":
        search_query += ".filter(name='" + form["name"].strip() + "')"
    if form["director"] != "":
        search_query += ".filter(director='" + form["director"].strip() + "')"
    for item in request.GET:
        if "author_" in item:
            search_query += ".filter(authors__name__exact='" + devideAuthors(item).strip() + "')"
        if "actor_" in item:
            search_query += ".filter(actors__name__exact='" + devideActors(item).strip() + "')"
    if "genre" in request.GET:
        search_query += ".filter(genre__name='" + request.GET["genre"] + "')"
    if "start_date" in request.GET:
        search_query += ".filter(release_date__range=('"+ request.GET["start_date"] + "-01-01','" + request.GET["end_date"] + "-12-31'))"
    films_list = eval(search_query + query_page)
    films_count = eval(search_query).count()
    return films_list, range((films_count / films_on_page) + 1 if films_count % films_on_page == 0\
                                                               else (films_count / films_on_page) + 2), True
Пример #4
0
def city_search(request):
    context = {}
    context['request'] = request
    # states = State.objects.all().order_by("name")
    # context['states'] = states
    states = []

    if (request.method == 'POST'):
        form = Search(request.POST)
        context['form'] = form
        if (form.is_valid()):
            search = form.cleaned_data['search']
            context['search'] = search
            if (search != None):
                cities = Area.objects.filter(
                    city__icontains=search).order_by("city")
                states = State.objects.filter(
                    id__in=cities.values_list('state_id', flat=True))

                context['states'] = states.order_by("name")

            else:
                # cities = Area.objects.all().order_by("city")[:100]
                cities = None
                context['states'] = State.objects.all().order_by("name")
    else:
        form = Search()
        context['form'] = form
        cities = None

    context['cities'] = cities
    return render_to_response('city_search.html',
                              context,
                              context_instance=RequestContext(request))
Пример #5
0
 def post(self,request):
     form = Search(request.POST)
     if form.is_valid():
         cat_name = form.cleaned_data['category']
         key = form.cleaned_data['enter_keyword']
         p = models.Products.objects.searchall(key)
         q = models.Products.objects.searchcat(key,cat_name)
         if cat_name =='0':
             return render(request,'showproduct.html',{'products':p,'media_url':settings.MEDIA_URL})
         else:
             return render(request,'showproduct.html',{'products':q,'media_url':settings.MEDIA_URL})
     return render(request,'base.html',{'form':form,'title':'search','head':'search','value':'search'})