##// END OF EJS Templates
Refactoring
Refactoring

File last commit:

r917:3aa27a4d default
r917:3aa27a4d default
Show More
search.py
43 lines | 1.1 KiB | text/x-python | PythonLexer
neko259
Use own search form and view
r718 from django.shortcuts import render
from django.views.generic import View
from haystack.query import SearchQuerySet
neko259
Refactoring
r917
neko259
Use own search form and view
r718 from boards.abstracts.paginator import get_paginator
from boards.forms import SearchForm, PlainErrorList
neko259
Refactoring
r917
MIN_QUERY_LENGTH = 3
RESULTS_PER_PAGE = 10
neko259
Small code cleanups
r721 FORM_QUERY = 'query'
CONTEXT_QUERY = 'query'
CONTEXT_FORM = 'form'
CONTEXT_PAGE = 'page'
REQUEST_PAGE = 'page'
neko259
Use own search form and view
r718 __author__ = 'neko259'
TEMPLATE = 'search/search.html'
class BoardSearchView(View):
def get(self, request):
neko259
Refactoring
r917 params = dict()
neko259
Use own search form and view
r718 form = SearchForm(request.GET, error_class=PlainErrorList)
neko259
Refactoring
r917 params[CONTEXT_FORM] = form
neko259
Use own search form and view
r718
if form.is_valid():
neko259
Small code cleanups
r721 query = form.cleaned_data[FORM_QUERY]
neko259
Refactoring
r917 if len(query) >= MIN_QUERY_LENGTH:
neko259
Removed load_all from search. Fixed the debug toolbar setting to be true when debug is on
r862 results = SearchQuerySet().auto_query(query).order_by('-id')
neko259
Refactoring
r917 paginator = get_paginator(results, RESULTS_PER_PAGE)
neko259
Use own search form and view
r718
neko259
Refactoring
r917 page = int(request.GET.get(REQUEST_PAGE, '1'))
neko259
Use own search form and view
r718
neko259
Refactoring
r917 params[CONTEXT_PAGE] = paginator.page(page)
params[CONTEXT_QUERY] = query
return render(request, TEMPLATE, params)