0001-kb-use-html.unescape-55535.patch
welco/kb/search_indexes.py | ||
---|---|---|
9 | 9 |
# This program is distributed in the hope that it will be useful, |
10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | 12 |
# GNU Affero General Public License for more details. |
13 | 13 |
# |
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import html |
|
18 | ||
17 | 19 |
from django.utils.html import strip_tags |
18 |
from django.utils.six.moves.html_parser import HTMLParser |
|
19 | 20 | |
20 | 21 |
from haystack import indexes |
21 | 22 | |
22 | 23 |
from .models import Page |
23 | 24 | |
24 | ||
25 | 25 |
class PageIndex(indexes.SearchIndex, indexes.Indexable): |
26 | 26 |
title = indexes.CharField(model_attr='title', boost=3) |
27 | 27 |
text = indexes.CharField(document=True) |
28 | 28 |
text_auto = indexes.EdgeNgramField() |
29 | 29 |
slug = indexes.CharField(model_attr='slug', indexed=False) |
30 | 30 |
tags = indexes.CharField(boost=1.5) |
31 | 31 | |
32 | 32 |
def get_model(self): |
33 | 33 |
return Page |
34 | 34 | |
35 | 35 |
def prepare_text(self, obj): |
36 |
return obj.title + ' ' + self.prepare_tags(obj) + ' ' + HTMLParser().unescape(strip_tags(obj.content))
|
|
36 |
return obj.title + ' ' + self.prepare_tags(obj) + ' ' + html.unescape(strip_tags(obj.content))
|
|
37 | 37 | |
38 | 38 |
def prepare_text_auto(self, obj): |
39 | 39 |
return self.prepare_text(obj) |
40 | 40 | |
41 | 41 |
def prepare_tags(self, obj): |
42 | 42 |
return ' '.join([tag.name for tag in obj.tags.all()]) |
43 |
- |