##// END OF EJS Templates
Removed highlight
neko259 -
r746:80d25404 2.0-dev
parent child Browse files
Show More
@@ -1,41 +1,40 b''
1 from django.shortcuts import render
1 from django.shortcuts import render
2 from django.template import RequestContext
2 from django.template import RequestContext
3 from django.views.generic import View
3 from django.views.generic import View
4 from haystack.query import SearchQuerySet
4 from haystack.query import SearchQuerySet
5 from boards.abstracts.paginator import get_paginator
5 from boards.abstracts.paginator import get_paginator
6 from boards.forms import SearchForm, PlainErrorList
6 from boards.forms import SearchForm, PlainErrorList
7
7
8 FORM_QUERY = 'query'
8 FORM_QUERY = 'query'
9
9
10 CONTEXT_QUERY = 'query'
10 CONTEXT_QUERY = 'query'
11 CONTEXT_FORM = 'form'
11 CONTEXT_FORM = 'form'
12 CONTEXT_PAGE = 'page'
12 CONTEXT_PAGE = 'page'
13
13
14 REQUEST_PAGE = 'page'
14 REQUEST_PAGE = 'page'
15
15
16 __author__ = 'neko259'
16 __author__ = 'neko259'
17
17
18 TEMPLATE = 'search/search.html'
18 TEMPLATE = 'search/search.html'
19
19
20
20
21 class BoardSearchView(View):
21 class BoardSearchView(View):
22 def get(self, request):
22 def get(self, request):
23 context = RequestContext(request)
23 context = RequestContext(request)
24 form = SearchForm(request.GET, error_class=PlainErrorList)
24 form = SearchForm(request.GET, error_class=PlainErrorList)
25 context[CONTEXT_FORM] = form
25 context[CONTEXT_FORM] = form
26
26
27 if form.is_valid():
27 if form.is_valid():
28 query = form.cleaned_data[FORM_QUERY]
28 query = form.cleaned_data[FORM_QUERY]
29 if len(query) >= 3:
29 if len(query) >= 3:
30 results = SearchQuerySet().auto_query(query).order_by('-id') \
30 results = SearchQuerySet().auto_query(query).order_by('-id')
31 .highlight()
32 paginator = get_paginator(results, 10)
31 paginator = get_paginator(results, 10)
33
32
34 if REQUEST_PAGE in request.GET:
33 if REQUEST_PAGE in request.GET:
35 page = int(request.GET[REQUEST_PAGE])
34 page = int(request.GET[REQUEST_PAGE])
36 else:
35 else:
37 page = 1
36 page = 1
38 context[CONTEXT_PAGE] = paginator.page(page)
37 context[CONTEXT_PAGE] = paginator.page(page)
39 context[CONTEXT_QUERY] = query
38 context[CONTEXT_QUERY] = query
40
39
41 return render(request, TEMPLATE, context) No newline at end of file
40 return render(request, TEMPLATE, context)
General Comments 0
You need to be logged in to leave comments. Login now