##// END OF EJS Templates
Merged with BB
Merged with BB

File last commit:

r917:3aa27a4d default
r1580:8fb1b3b1 merge default
Show More
search.py
43 lines | 1.1 KiB | text/x-python | PythonLexer
from django.shortcuts import render
from django.views.generic import View
from haystack.query import SearchQuerySet
from boards.abstracts.paginator import get_paginator
from boards.forms import SearchForm, PlainErrorList
MIN_QUERY_LENGTH = 3
RESULTS_PER_PAGE = 10
FORM_QUERY = 'query'
CONTEXT_QUERY = 'query'
CONTEXT_FORM = 'form'
CONTEXT_PAGE = 'page'
REQUEST_PAGE = 'page'
__author__ = 'neko259'
TEMPLATE = 'search/search.html'
class BoardSearchView(View):
def get(self, request):
params = dict()
form = SearchForm(request.GET, error_class=PlainErrorList)
params[CONTEXT_FORM] = form
if form.is_valid():
query = form.cleaned_data[FORM_QUERY]
if len(query) >= MIN_QUERY_LENGTH:
results = SearchQuerySet().auto_query(query).order_by('-id')
paginator = get_paginator(results, RESULTS_PER_PAGE)
page = int(request.GET.get(REQUEST_PAGE, '1'))
params[CONTEXT_PAGE] = paginator.page(page)
params[CONTEXT_QUERY] = query
return render(request, TEMPLATE, params)