def key_results(request): """ This responds to keyword search request (typically from the entry box on the jumbotron but could be anywhere. If there is more than one page, this routine may be re-entered to process other pages. """ start_time = time.time() page = request.GET.get('page') if page is None: form = KeySearchForm(request.GET) if form.is_valid(): # Uses session cookies to track the query between pages. request.session['keywords'] = form.cleaned_data['keywords'] # If ther are no keywords here, the user entered nothing or the # form was not valid. keywords = request.session.get('keywords', '') try: query = SearchTerm.search(keywords) except ProgrammingError: context = { 'active': 'None', 'message': 'Unable to parse keywords search terms', 'keyform': KeySearchForm(), } return render(request, 'results.html', context) paginator = Paginator(query, 25) try: pieces = paginator.page(page) except PageNotAnInteger: # typically the first page of results pieces = paginator.page(1) except EmptyPage: pieces = paginator.page(paginator.num_pages) end_time = time.time() context = { 'active': 'None', 'pieces': pieces, 'keyform': KeySearchForm(), 'pager': pieces, 'keywords': keywords, 'search_time': '%2.4g' % (end_time - start_time), } return render(request, 'results.html', context)
def key_results(request): """ This responds to keyword search request (typically from the entry box on the jumbotron but could be anywhere. If there is more than one page, this routine may be re-entered to process other pages. """ start_time = time.time() page = request.GET.get('page') if page is None: form = KeySearchForm(request.GET) if form.is_valid(): # Uses session cookies to track the query between pages. request.session['keywords'] = form.cleaned_data['keywords'] # If ther are no keywords here, the user entered nothing or the # form was not valid. keywords = request.session.get('keywords', '') try: query = SearchTerm.search(keywords) except ProgrammingError: context = { 'active' : 'None', 'message': 'Unable to parse keywords search terms', 'keyform': KeySearchForm(), } return render(request, 'results.html', context) paginator = Paginator(query, 25) try: pieces = paginator.page(page) except PageNotAnInteger: # typically the first page of results pieces = paginator.page(1) except EmptyPage: pieces = paginator.page(paginator.num_pages) end_time = time.time() context = { 'active' : 'None', 'pieces': pieces, 'keyform': KeySearchForm(), 'pager': pieces, 'keywords': keywords, 'search_time': '%2.4g' % (end_time - start_time), } return render(request, 'results.html', context)
def key_results(request): start_time = time.time() # Uses a session cookies to track the query between pages. page = request.GET.get('page') if page is None: form = KeySearchForm(request.GET) if form.is_valid(): request.session['keywords'] = form.cleaned_data['keywords'] # If this is blank, the user entered nothing or the form was not valid keywords = request.session.get('keywords', '') try: q = fts_search(keywords) except ProgrammingError: context = { 'active' : 'None', 'message': 'Unable to parse keywords search terms', 'keyform': KeySearchForm(), } return render(request, 'results.html', context) paginator = Paginator(q, 25) try: pieces = paginator.page(page) except PageNotAnInteger: # typically the first page of results pieces = paginator.page(1) except EmptyPage: pieces = paginator.page(paginator.num_pages) end_time = time.time() context = { 'active' : 'None', 'pieces': pieces, 'keyform': KeySearchForm(), 'pager': pieces, 'keywords': keywords, 'search_time': '%2.4g' % (end_time - start_time), } return render(request, 'results.html', context)
def key_results(request): start_time = time.time() # Uses a session cookies to track the query between pages. page = request.GET.get('page') if page is None: form = KeySearchForm(request.GET) if form.is_valid(): request.session['keywords'] = form.cleaned_data['keywords'] # If this is blank, the user entered nothing or the form was not valid keywords = request.session.get('keywords', '') try: q = fts_search(keywords) except ProgrammingError: context = { 'active': 'None', 'message': 'Unable to parse keywords search terms', 'keyform': KeySearchForm(), } return render(request, 'results.html', context) paginator = Paginator(q, 25) try: pieces = paginator.page(page) except PageNotAnInteger: # typically the first page of results pieces = paginator.page(1) except EmptyPage: pieces = paginator.page(paginator.num_pages) end_time = time.time() context = { 'active': 'None', 'pieces': pieces, 'keyform': KeySearchForm(), 'pager': pieces, 'keywords': keywords, 'search_time': '%2.4g' % (end_time - start_time), } return render(request, 'results.html', context)