search: add "wait for index" message to search cell configuration form (#32031)

This commit is contained in:
Frédéric Péters 2019-04-06 14:16:37 +02:00
parent 51c877099e
commit 83d37967eb
3 changed files with 62 additions and 0 deletions

View File

@ -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)

View File

@ -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 %}

View File

@ -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()