예제 #1
0
 def get_results(self, request):
     context = self.get_context(request)
     search_term = request.GET.get('search_term', '').strip()
     if not search_term or len(unquote(search_term)) == 1:
         results = self.query_base
     else:
         search = AskSearch(search_term=search_term,
                            query_base=self.query_base)
         results = search.queryset
         if results.count() == 0:
             # No results, so let's try to suggest a better query
             search.suggest(request=request)
             results = search.queryset
             search_term = search.search_term
     search_message = self.results_message(results.count(),
                                           self.get_heading(), search_term)
     paginator = Paginator(results, 10)
     page_number = validate_page_number(request, paginator)
     context.update({
         'search_term': search_term,
         'results_message': search_message,
         'pages': paginator.page(page_number),
         'paginator': paginator,
         'current_page': page_number,
         'get_secondary_nav_items': self.get_nav_items,
     })
     return TemplateResponse(request, 'ask-cfpb/see-all.html', context)
예제 #2
0
파일: pages.py 프로젝트: cfpb/cfgov-refresh
 def get_results(self, request):
     context = self.get_context(request)
     search_term = request.GET.get('search_term', '').strip()
     if not search_term or len(unquote(search_term)) == 1:
         results = self.query_base
     else:
         search = AskSearch(
             search_term=search_term,
             query_base=self.query_base)
         results = search.queryset
         if results.count() == 0:
             # No results, so let's try to suggest a better query
             search.suggest(request=request)
             results = search.queryset
             search_term = search.search_term
     search_message = self.results_message(
         results.count(),
         self.get_heading(),
         search_term)
     paginator = Paginator(results, 10)
     page_number = validate_page_number(request, paginator)
     context.update({
         'search_term': search_term,
         'results_message': search_message,
         'pages': paginator.page(page_number),
         'paginator': paginator,
         'current_page': page_number,
         'get_secondary_nav_items': self.get_nav_items,
     })
     return TemplateResponse(
         request,
         'ask-cfpb/see-all.html',
         context)