summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2019-04-06 12:16:37 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2019-04-15 18:06:57 (GMT)
commit83d37967ebb1aa6a9e6ff7617c7cf6dacf34ed2c (patch)
tree6810845837e4e3f56a2583595f0b01460dd7ac4a
parent51c877099e1875e1238afdc335369c191f816b84 (diff)
downloadcombo-83d37967ebb1aa6a9e6ff7617c7cf6dacf34ed2c.zip
combo-83d37967ebb1aa6a9e6ff7617c7cf6dacf34ed2c.tar.gz
combo-83d37967ebb1aa6a9e6ff7617c7cf6dacf34ed2c.tar.bz2
search: add "wait for index" message to search cell configuration form (#32031)
-rw-r--r--combo/apps/search/models.py10
-rw-r--r--combo/apps/search/templates/combo/manager/search-cell-form.html16
-rw-r--r--tests/test_search.py36
3 files changed, 62 insertions, 0 deletions
diff --git a/combo/apps/search/models.py b/combo/apps/search/models.py
index fc4aecf..c06147f 100644
--- a/combo/apps/search/models.py
+++ b/combo/apps/search/models.py
@@ -14,6 +14,8 @@
# 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/>.
+import os
+
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django import template
@@ -24,6 +26,7 @@ from django.utils.http import quote
from django.template import Context, Template
from jsonfield import JSONField
+from haystack import connections
from combo.utils import requests
from combo.data.models import CellBase
@@ -36,6 +39,7 @@ from . import engines
@register_cell_class
class SearchCell(CellBase):
template_name = 'combo/search-cell.html'
+ manager_form_template = 'combo/manager/search-cell-form.html'
_search_services = JSONField(_('Search Services'), default=dict, blank=True)
@@ -166,3 +170,9 @@ class SearchCell(CellBase):
for k, v in hit_templates.items():
hit[k] = v.render(Context(hit))
return render_response(service, results)
+
+ def has_text_search_service(self):
+ return '_text' in self._search_services.get('data', [])
+
+ def missing_index(self):
+ return not os.path.exists(connections['default'].get_backend().path)
diff --git a/combo/apps/search/templates/combo/manager/search-cell-form.html b/combo/apps/search/templates/combo/manager/search-cell-form.html
new file mode 100644
index 0000000..8e71fb3
--- /dev/null
+++ b/combo/apps/search/templates/combo/manager/search-cell-form.html
@@ -0,0 +1,16 @@
+{% extends "combo/cell_form.html" %}
+{% load i18n %}
+
+{% block cell-form %}
+{% if cell.has_text_search_service and cell.missing_index %}
+<div class="infonotice">
+ <p>
+ {% blocktrans %}
+ Content indexing has been scheduled and should happen within an hour; search
+ results will then be available.
+ {% endblocktrans %}
+ </p>
+</div>
+{% endif %}
+{{ block.super }}
+{% endblock %}
diff --git a/tests/test_search.py b/tests/test_search.py
index 005755c..987cb39 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -2,6 +2,7 @@ import json
import os
import pytest
import re
+import shutil
import mock
from django.conf import settings
@@ -376,6 +377,41 @@ def test_manager_search_cell(app, admin_user):
assert resp.form['c%s-_search_services' % cells[0].get_reference()].value == ['_text']
+def test_manager_waiting_index_message(app, admin_user):
+ from haystack import connections
+ shutil.rmtree(connections['default'].get_backend().path)
+
+ Page.objects.all().delete()
+ page = Page(title='One', slug='one', template_name='standard')
+ page.save()
+ app = login(app)
+ resp = app.get('/manage/pages/%s/' % page.id)
+ resp = app.get(resp.html.find('option',
+ **{'data-add-url': re.compile('search_searchcell')})['data-add-url'])
+ resp = resp.follow()
+ assert 'Content indexing has been scheduled' not in resp.text
+
+ cells = Page.objects.get(id=page.id).get_cells()
+ resp.form['c%s-_search_services' % cells[0].get_reference()] = ['_text']
+ resp = resp.form.submit().follow()
+ assert 'Content indexing has been scheduled' in resp.text
+
+ call_command('update_index')
+ resp = app.get('/manage/pages/%s/' % page.id)
+ assert 'Content indexing has been scheduled' not in resp.text
+
+
+def test_manager_search_cell(app, admin_user):
+ Page.objects.all().delete()
+ page = Page(title='One', slug='one', template_name='standard')
+ page.save()
+ app = login(app)
+ resp = app.get('/manage/pages/%s/' % page.id)
+ resp = app.get(resp.html.find('option',
+ **{'data-add-url': re.compile('search_searchcell')})['data-add-url'])
+
+
+
def test_wcs_search_engines(app):
with override_settings(KNOWN_SERVICES={}):
search_engines = engines.get_engines()