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