Show More
@@ -1,45 +1,46 b'' | |||
|
1 | 1 | from django.shortcuts import render |
|
2 | 2 | from django.views.generic import View |
|
3 | 3 | from django.db.models import Q |
|
4 | 4 | |
|
5 | 5 | from boards.abstracts.paginator import get_paginator |
|
6 | 6 | from boards.forms import SearchForm, PlainErrorList |
|
7 | 7 | from boards.models import Post |
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | MIN_QUERY_LENGTH = 3 |
|
11 | 11 | RESULTS_PER_PAGE = 10 |
|
12 | 12 | |
|
13 | 13 | FORM_QUERY = 'query' |
|
14 | 14 | |
|
15 | 15 | CONTEXT_QUERY = 'query' |
|
16 | 16 | CONTEXT_FORM = 'form' |
|
17 | 17 | CONTEXT_PAGE = 'page' |
|
18 | 18 | |
|
19 | 19 | REQUEST_PAGE = 'page' |
|
20 | 20 | |
|
21 | 21 | __author__ = 'neko259' |
|
22 | 22 | |
|
23 | 23 | TEMPLATE = 'search/search.html' |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | class BoardSearchView(View): |
|
27 | 27 | def get(self, request): |
|
28 | 28 | params = dict() |
|
29 | 29 | |
|
30 | 30 | form = SearchForm(request.GET, error_class=PlainErrorList) |
|
31 | 31 | params[CONTEXT_FORM] = form |
|
32 | 32 | |
|
33 | 33 | if form.is_valid(): |
|
34 | 34 | query = form.cleaned_data[FORM_QUERY] |
|
35 | 35 | if len(query) >= MIN_QUERY_LENGTH: |
|
36 |
results = Post.objects.filter(Q(text__icontains=query) |
|
|
37 |
Q(title__icontains=query) |
|
|
36 | results = Post.objects.filter(Q(text__icontains=query) | |
|
37 | | Q(title__icontains=query) | Q(opening=True, | |
|
38 | thread__tags__aliases__name__icontains=query)).order_by('-id').distinct() | |
|
38 | 39 | paginator = get_paginator(results, RESULTS_PER_PAGE) |
|
39 | 40 | |
|
40 | 41 | page = int(request.GET.get(REQUEST_PAGE, '1')) |
|
41 | 42 | |
|
42 | 43 | params[CONTEXT_PAGE] = paginator.page(page) |
|
43 | 44 | params[CONTEXT_QUERY] = query |
|
44 | 45 | |
|
45 | 46 | return render(request, TEMPLATE, params) |
General Comments 0
You need to be logged in to leave comments.
Login now