def search_listresult(request): if request.POST.get('params', None) is not None: params = ','.join(request.POST.getlist('params')) a = params.split(',') sorttype = request.POST.get('sorttype', None) sortorder = request.POST.get('sortorder', None) amount = request.POST.get('amount', None) if amount: try : int(amount) results = Bid.objects.filter(amount__gte=amount).order_by("random_rank") except ValueError: results = Bid.objects.all().order_by("random_rank") else: results = Bid.objects.all().order_by("random_rank") filters = DimensionChoice.objects.filter(id__in=a) results = data_filter(results, filters) if sorttype is not None and sortorder is not None: results = result_sort(results, sorttype, sortorder) ppp = Paginator(results, 3) try: page = int(request.POST.get('page', '1')) except ValueError: page = 1 try: results = ppp.page(page) except (EmptyPage, InvalidPage): results = ppp.page(ppp.num_pages) last_page = ppp.page_range[len(ppp.page_range) - 1] page_set = get_pageset(last_page, page) return render_to_response('search_result_m.html',{'params':request.POST.get('params'),'results': results, 'last_page': last_page, 'page_set': page_set}, context_instance=RequestContext(request)) else: print "ttttttttttttttttttttttttt" try: page = int(request.POST.get('page', '1')) except ValueError: page = 1 index_parts = index_loading_m(0, None, page) return render_to_response('search_result_m.html', {'results': index_parts.get('results'), 'last_page': index_parts.get('last_page'), 'page_set': index_parts.get('page_set')}, context_instance=RequestContext(request))
def index(request): hotspots = WeekHotSpot.objects.filter(status=1).order_by('?') if hotspots.exists(): hs = random.sample(hotspots, 4) else: hs = [] if request.method == 'POST': # print(request.POST.get('params', None)) form = SearchForm(request.POST) if form.is_valid(): cd = form.cleaned_data amount = cd['searchWord'] else: return render_to_response('index.html', {'form': form, 'hs': hs}, context_instance=RequestContext(request)) try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 index_parts = index_loading(amount, None, page) return render_to_response('search_result.html', {'results': index_parts.get('results'), 'dimensions': index_parts.get('dimensions'), 'c_results': index_parts.get('c_result'), 'last_page': index_parts.get('last_page'), 'page_set': index_parts.get('page_set'), 'form': form}, context_instance=RequestContext(request)) elif request.GET.get('params[]', None) is not None: params = ','.join(request.GET.getlist('params[]')) a = params.split(',') sorttype = request.REQUEST.get('sorttype', None) sortorder = request.REQUEST.get('sortorder', None) amount = request.REQUEST.get('amount', None) if amount: results = Bid.objects.filter(amount__gte=amount).order_by("random_rank") else: results = Bid.objects.all().order_by("random_rank") filters = DimensionChoice.objects.filter(id__in=a) results = data_filter(results, filters) if sorttype is not None and sortorder is not None: results = result_sort(results, sorttype, sortorder) ppp = Paginator(results, 5) try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 try: results = ppp.page(page) except (EmptyPage, InvalidPage): results = ppp.page(ppp.num_pages) last_page = ppp.page_range[len(ppp.page_range) - 1] page_set = get_pageset(last_page, page) t = get_template('search_result_single.html') content_html = t.render( RequestContext(request, {'results': results, 'last_page': last_page, 'page_set': page_set})) payload = { 'content_html': content_html, 'success': True } return HttpResponse(json.dumps(payload), content_type="application/json") else: form = SearchForm() user = auth.get_user(request) if user.id is not None: f_l = get_user_filter(user) return render_to_response('index.html', {'form': form, 'f_ls': f_l, 'hs': hs}, context_instance=RequestContext(request)) else: return render_to_response('index.html', {'form': form, 'hs': hs}, context_instance=RequestContext(request))
def detail_search(request): if request.POST.get('params', None) is not None: params = ','.join(request.POST.getlist('params')) a = params.split(',') sorttype = request.POST.get('sorttype', None) sortorder = request.POST.get('sortorder', None) amount = request.POST.get('amount', None) if amount: try : int(amount) results = Bid.objects.filter(amount__gte=amount).order_by("random_rank") except ValueError: results = Bid.objects.all().order_by("random_rank") else: results = Bid.objects.all().order_by("random_rank") filters = DimensionChoice.objects.filter(id__in=a) results = data_filter(results, filters) if sorttype is not None and sortorder is not None: results = result_sort(results, sorttype, sortorder) ppp = Paginator(results, 3) try: page = int(request.POST.get('page', '1')) except ValueError: page = 1 try: results = ppp.page(page) except (EmptyPage, InvalidPage): results = ppp.page(ppp.num_pages) last_page = ppp.page_range[len(ppp.page_range) - 1] page_set = get_pageset(last_page, page) form = SearchForm() return render_to_response('search_result_m.html',{'form':form,'params':request.POST.get('params'),'results': results, 'last_page': last_page, 'page_set': page_set}, context_instance=RequestContext(request)) elif request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): cd = form.cleaned_data amount = cd['searchWord'] try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 a = [1,7,13,16,22,28,36] sorttype = 0 sortorder = 0 if amount: try : int(amount) results = Bid.objects.filter(amount__gte=amount).order_by("random_rank") except ValueError: results = Bid.objects.all().order_by("random_rank") else: results = Bid.objects.all().order_by("random_rank") filters = DimensionChoice.objects.filter(id__in=a) results = data_filter(results, filters) if sorttype is not None and sortorder is not None: results = result_sort(results, sorttype, sortorder) ppp = Paginator(results, 3) try: page = int(request.POST.get('page', '1')) except ValueError: page = 1 try: results = ppp.page(page) except (EmptyPage, InvalidPage): results = ppp.page(ppp.num_pages) last_page = ppp.page_range[len(ppp.page_range) - 1] page_set = get_pageset(last_page, page) return render_to_response('search_result_m.html', {'params':a,'results': results, 'last_page': last_page,'page_set': page_set,'form':form}, context_instance=RequestContext(request)) else: form = SearchForm() return render_to_response('detail_search_m.html',{'form',form}, context_instance=RequestContext(request))
def search_result(request): if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): cd = form.cleaned_data amount = cd['searchWord'] try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 index_parts = index_loading_m(amount, None, page) return render_to_response('search_result_m.html', {'results': index_parts.get('results'), 'dimensions': index_parts.get('dimensions'), 'c_results': index_parts.get('c_result'), 'last_page': index_parts.get('last_page'), 'page_set': index_parts.get('page_set'), 'form': form}, context_instance=RequestContext(request)) else: try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 index_parts = index_loading_m(0, None, page) return render_to_response('search_result_m.html', {'results': index_parts.get('results'), 'dimensions': index_parts.get('dimensions'), 'c_results': index_parts.get('c_result'), 'last_page': index_parts.get('last_page'), 'page_set': index_parts.get('page_set'), 'form': form}, context_instance=RequestContext(request)) elif request.GET.get('params[]', None) is not None: params = ','.join(request.GET.getlist('params[]')) a = params.split(',') sorttype = request.REQUEST.get('sorttype', None) sortorder = request.REQUEST.get('sortorder', None) amount = request.REQUEST.get('amount', None) if amount: results = Bid.objects.filter(amount__gte=amount).order_by("random_rank") else: results = Bid.objects.all().order_by("random_rank") filters = DimensionChoice.objects.filter(id__in=a) results = data_filter(results, filters) if sorttype is not None and sortorder is not None: results = result_sort(results, sorttype, sortorder) ppp = Paginator(results, 3) try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 try: results = ppp.page(page) except (EmptyPage, InvalidPage): results = ppp.page(ppp.num_pages) last_page = ppp.page_range[len(ppp.page_range) - 1] page_set = get_pageset(last_page, page) t = get_template('search_result_single_m.html') content_html = t.render( RequestContext(request, {'results': results, 'last_page': last_page, 'page_set': page_set})) payload = { 'content_html': content_html, 'success': True } return HttpResponse(json.dumps(payload), content_type="application/json") else: try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 index_parts = index_loading_m(0, None, page) print 'page isxxxxxxxxxxxxx',page #return render_to_response('searchResult_m.html', context_instance=RequestContext(request)) return render_to_response('search_result_m.html', {'results': index_parts.get('results'), 'dimensions': index_parts.get('dimensions'), 'c_results': index_parts.get('c_result'), 'last_page': index_parts.get('last_page'), 'page_set': index_parts.get('page_set')}, context_instance=RequestContext(request))
def result(request): if request.method == 'POST': hotspots = WeekHotSpot.objects.filter(status=1).order_by('?') if hotspots.exists(): hs = random.sample(hotspots, 5) else: hs = [] # print(request.POST.get('params', None)) try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 form = SearchForm(request.POST) if form.is_valid(): cd = form.cleaned_data amount = cd['searchWord'] else: amount = 0 index_parts = index_loading(amount, None, page) return render_to_response('search_result.html', { 'results': index_parts.get('results'), 'dimensions': index_parts.get('dimensions'), 'c_results': index_parts.get('c_result'), 'last_page': index_parts.get('last_page'), 'page_set': index_parts.get('page_set'), 'form': form }, context_instance=RequestContext(request)) elif request.GET.get('params[]', None) is not None: params = ','.join(request.GET.getlist('params[]')) a = params.split(',') sorttype = request.REQUEST.get('sorttype', None) sortorder = request.REQUEST.get('sortorder', None) amount = request.REQUEST.get('amount', None) if amount: try: int(amount) results = Bid.objects.filter(process__lt=100).filter( amount__gte=amount).order_by("random_rank") except ValueError: results = Bid.objects.filter( process__lt=100).order_by("random_rank") else: results = Bid.objects.filter( process__lt=100).order_by("random_rank") filters = DimensionChoice.objects.filter(id__in=a) results = data_filter(results, filters) if sorttype is not None and sortorder is not None: results = result_sort(results, sorttype, sortorder) ppp = Paginator(results, 8) try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 try: results = ppp.page(page) except (EmptyPage, InvalidPage): results = ppp.page(ppp.num_pages) last_page = ppp.page_range[len(ppp.page_range) - 1] page_set = get_pageset(last_page, page) t = get_template('search_result_single.html') content_html = t.render( RequestContext(request, { 'results': results, 'last_page': last_page, 'page_set': page_set })) payload = {'content_html': content_html, 'success': True} return HttpResponse(json.dumps(payload), content_type="application/json") elif request.GET.get('rank', None) is not None: rank = request.GET.get('rank') index_parts = index_loading_rank(None, None, 1, "%s" % rank) return render_to_response('search_result.html', { 'results': index_parts.get('results'), 'dimensions': index_parts.get('dimensions'), 'c_results': index_parts.get('c_result'), 'last_page': index_parts.get('last_page'), 'page_set': index_parts.get('page_set') }, context_instance=RequestContext(request)) else: index_parts = index_loading_rank(None, None, 1, "-income_rate") return render_to_response('search_result.html', { 'results': index_parts.get('results'), 'dimensions': index_parts.get('dimensions'), 'c_results': index_parts.get('c_result'), 'last_page': index_parts.get('last_page'), 'page_set': index_parts.get('page_set') }, context_instance=RequestContext(request))