def get_queryset(self): form = SearchForm(self.request.GET or None) query = form.query_value if query: return super(SearcherView, self).get_queryset().filter(title__icontains=query) return super(SearcherView, self).get_queryset()
def index(request): results_right = Bid.objects.filter(process__lt=100).filter(term__gt=0).order_by("random_rank").order_by("term")[0:4] results_right.query.group_by = ['platform_id'] results_left = Bid.objects.filter(process__lt=100).order_by("random_rank").order_by("-income_rate")[0:4] results_left.query.group_by = ['platform_id'] form = SearchForm() return render_to_response('index_m.html', {'results_left':results_left,'results_right':results_right,'form':form}, context_instance=RequestContext(request))
def search(request): form = SearchForm() t = get_template('search_m.html') content_html = t.render(RequestContext(request, {'form': form})) payload = { 'content_html': content_html, 'success': True, } return HttpResponse(json.dumps(payload), content_type="application/json")
def hotspot(request): hotspots = WeekHotSpot.objects.filter(status=1).order_by('?') if hotspots.exists(): hs = random.sample(hotspots, 4) else: hs = [] print hs form = SearchForm() t = get_template('hotspot.html') content_html = t.render(RequestContext(request, {'hs': hs, 'form': form})) payload = { 'content_html': content_html, 'success': True, } return HttpResponse(json.dumps(payload), content_type="application/json")
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 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 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 get_context_data(self, **kwargs): context = super(SearcherView, self).get_context_data(**kwargs) form = SearchForm(self.request.GET or None) context['query'] = form.query_value or "" return context
def index(request): hotspots = WeekHotSpot.objects.filter(status=1).order_by('?') if hotspots.exists(): hs = random.sample(hotspots, 5) else: hs = [] user = auth.get_user(request) print "ttttttttttttttt" results_right = Bid.objects.filter(process__lt=100).filter( term__gt=0).order_by("random_rank").order_by("term")[0:4] results_right.query.group_by = ['platform_id'] results_left = Bid.objects.filter( process__lt=100).order_by("random_rank").order_by("-income_rate")[0:4] results_left.query.group_by = ['platform_id'] if request.GET.get('register_success', None) is not None: form = SearchForm() f_l = get_user_filter(user) p = re.compile( '^13[4-9][0-9]{8}|^15[0,1,2,7,8,9][0-9]{8}|^18[2,7,8][0-9]{8}|^147[0-9]{8}|^178[0-9]{8}' ) p1 = re.compile( '^18[0,1,9][0-9]{8}|^133[0-9]{8}|^153[0-9]{8}|^177[0-9]{8}') phone = user.username if p.match(str(phone)): flag1 = 1 elif p1.match(str(phone)): flag1 = 2 else: flag1 = 3 return render_to_response('index.html', { 'flag1': flag1, 'register_success': 1, 'form': form, 'f_ls': f_l, 'hs': hs, 'results_left': results_left, 'results_right': results_right }, context_instance=RequestContext(request)) if user.id is not None: form = SearchForm() f_l = get_user_filter(user) return render_to_response('index.html', { 'form': form, 'f_ls': f_l, 'hs': hs, 'results_left': results_left, 'results_right': results_right }, context_instance=RequestContext(request)) else: form = RegisterForm() form_login = LoginForm() return render_to_response('index.html', { 'form': form, 'form_login': form_login, 'hs': hs, 'results_left': results_left, 'results_right': results_right }, 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))