| author | ymh <ymh.work@gmail.com> |
| Thu, 06 Nov 2014 02:07:07 +0100 | |
| changeset 175 | 1ff6533ba75d |
| parent 146 | 3d20cdc9be3d |
| permissions | -rw-r--r-- |
|
113
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
| 126 | 2 |
# |
| 131 | 3 |
# Copyright IRI (c) 2013 |
| 126 | 4 |
# |
5 |
# contact@iri.centrepompidou.fr |
|
6 |
# |
|
7 |
# This software is governed by the CeCILL-B license under French law and |
|
8 |
# abiding by the rules of distribution of free software. You can use, |
|
9 |
# modify and/ or redistribute the software under the terms of the CeCILL-B |
|
10 |
# license as circulated by CEA, CNRS and INRIA at the following URL |
|
11 |
# "http://www.cecill.info". |
|
12 |
# |
|
13 |
# As a counterpart to the access to the source code and rights to copy, |
|
14 |
# modify and redistribute granted by the license, users are provided only |
|
15 |
# with a limited warranty and the software's author, the holder of the |
|
16 |
# economic rights, and the successive licensors have only limited |
|
17 |
# liability. |
|
18 |
# |
|
19 |
# In this respect, the user's attention is drawn to the risks associated |
|
20 |
# with loading, using, modifying and/or developing or reproducing the |
|
21 |
# software by the user in light of its specific status of free software, |
|
22 |
# that may mean that it is complicated to manipulate, and that also |
|
23 |
# therefore means that it is reserved for developers and experienced |
|
24 |
# professionals having in-depth computer knowledge. Users are therefore |
|
25 |
# encouraged to load and test the software's suitability as regards their |
|
26 |
# requirements in conditions enabling the security of their systems and/or |
|
27 |
# data to be ensured and, more generally, to use and operate it in the |
|
28 |
# same conditions as regards security. |
|
29 |
# |
|
30 |
# The fact that you are presently reading this means that you have had |
|
31 |
# knowledge of the CeCILL-B license and that you accept its terms. |
|
32 |
# |
|
|
113
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
|
| 126 | 34 |
|
|
113
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
from haystack.forms import SearchForm |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
|
| 115 | 37 |
from p4l.models.data import Record |
38 |
from p4l.search.query_parser import QueryParser |
|
|
113
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
from p4l.utils import strip_accents |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
class RecordSearchForm(SearchForm): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
def __init__(self, *args, **kwargs): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
SearchForm.__init__(self, *args, **kwargs) |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
def no_query_found(self): |
|
146
3d20cdc9be3d
Change notice list order on a search to the order returned by the indexation engine. Fix #5 (https://github.com/IRI-Research/plan4learning/issues/5)
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
48 |
return self.searchqueryset.order_by('identifier').all() |
|
113
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
def search(self): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
if not self.is_valid(): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
return self.no_query_found() |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
if not self.cleaned_data.get('q'): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
return self.no_query_found() |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
|
| 115 | 57 |
qp = QueryParser("text") |
58 |
sqs = self.searchqueryset.models(Record).filter(qp.parse(strip_accents(self.cleaned_data['q']))) |
|
|
113
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
if self.load_all: |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
sqs = sqs.load_all() |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
return sqs |