add indexing of pages (#6793)
This commit is contained in:
parent
81f8a9a089
commit
3c5644e768
|
@ -25,6 +25,7 @@ from django.db import models
|
|||
from django.db.models import Max
|
||||
from django.forms import models as model_forms
|
||||
from django import template
|
||||
from django.utils.html import strip_tags
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -160,8 +161,11 @@ class Page(models.Model):
|
|||
def is_visible(self, user=None):
|
||||
return element_is_visible(self, user=user)
|
||||
|
||||
def get_cells(self):
|
||||
return CellBase.get_cells(page_id=self.id)
|
||||
|
||||
def get_serialized_page(self):
|
||||
cells = CellBase.get_cells(page_id=self.id)
|
||||
cells = self.get_cells()
|
||||
serialized_page = json.loads(serializers.serialize('json', [self]))[0]
|
||||
del serialized_page['pk']
|
||||
del serialized_page['model']
|
||||
|
@ -342,6 +346,11 @@ class CellBase(models.Model):
|
|||
tmpl = template.loader.get_template(self.template_name)
|
||||
return tmpl.render(context)
|
||||
|
||||
def render_for_search(self):
|
||||
from django.template import Context
|
||||
from HTMLParser import HTMLParser
|
||||
return HTMLParser().unescape(strip_tags(self.render(Context())))
|
||||
|
||||
|
||||
@register_cell_class
|
||||
class TextCell(CellBase):
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
# combo - content management system
|
||||
# Copyright (C) 2014-2015 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from haystack import indexes
|
||||
|
||||
from .models import Page, CellBase
|
||||
|
||||
class PageIndex(indexes.SearchIndex, indexes.Indexable):
|
||||
title = indexes.CharField(model_attr='title', boost=1.5)
|
||||
text = indexes.CharField(document=True, use_template=True,
|
||||
template_name='combo/search/page.txt')
|
||||
url = indexes.CharField(indexed=False)
|
||||
|
||||
def get_model(self):
|
||||
return Page
|
||||
|
||||
def prepare_url(self, obj):
|
||||
return obj.get_online_url()
|
|
@ -0,0 +1,5 @@
|
|||
{{object.title}}
|
||||
|
||||
{% for cell in object.get_cells %}
|
||||
{{ cell.render_for_search }}
|
||||
{% endfor %}
|
|
@ -55,6 +55,7 @@ INSTALLED_APPS = (
|
|||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'ckeditor',
|
||||
'haystack',
|
||||
'gadjo',
|
||||
'cmsplugin_blurp',
|
||||
'combo.data',
|
||||
|
@ -122,6 +123,13 @@ MEDIA_URL = '/media/'
|
|||
|
||||
CKEDITOR_UPLOAD_PATH = 'uploads/'
|
||||
|
||||
HAYSTACK_CONNECTIONS = {
|
||||
'default': {
|
||||
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
|
||||
'PATH': os.path.join(BASE_DIR, 'whoosh_index'),
|
||||
},
|
||||
}
|
||||
|
||||
CKEDITOR_CONFIGS = {
|
||||
'default': {
|
||||
'toolbar_Own': [['Source', 'Format', '-', 'Bold', 'Italic'],
|
||||
|
|
Loading…
Reference in New Issue