summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2019-04-06 12:26:12 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2019-04-09 16:28:20 (GMT)
commit8d9a03f57c4175ec645c221bd5d325550b30698d (patch)
treef45fc0a3093b6017b342dfdf570da476eb0e3249
parent77b5977c1f54511f1ca9a7e4726eefdaa1666e96 (diff)
downloadcombo-8d9a03f57c4175ec645c221bd5d325550b30698d.zip
combo-8d9a03f57c4175ec645c221bd5d325550b30698d.tar.gz
combo-8d9a03f57c4175ec645c221bd5d325550b30698d.tar.bz2
search: don't display "no result found" when there is no query (#32038)
-rw-r--r--combo/apps/search/models.py10
-rw-r--r--combo/apps/search/templates/combo/search-cell-results.html2
-rw-r--r--tests/test_search.py8
3 files changed, 18 insertions, 2 deletions
diff --git a/combo/apps/search/models.py b/combo/apps/search/models.py
index 87a1fba..fc4aecf 100644
--- a/combo/apps/search/models.py
+++ b/combo/apps/search/models.py
@@ -111,12 +111,19 @@ class SearchCell(CellBase):
if not cell.is_visible(request.user) or not cell.page.is_visible(request.user):
raise PermissionDenied
+ query = request.GET.get('q')
+
def render_response(service={}, results={'err': 0, 'data': []}):
template_names = ['combo/search-cell-results.html']
if cell.slug:
template_names.insert(0, 'combo/cells/%s/search-cell-results.html' % cell.slug)
tmpl = template.loader.select_template(template_names)
- context = {'cell': cell, 'results': results, 'search_service': service}
+ context = {
+ 'cell': cell,
+ 'results': results,
+ 'search_service': service,
+ 'query': query
+ }
return HttpResponse(tmpl.render(context, request), content_type='text/html')
for service in cell.search_services:
@@ -125,7 +132,6 @@ class SearchCell(CellBase):
else:
return render_response()
- query = request.GET.get('q')
if not query:
return render_response(service)
diff --git a/combo/apps/search/templates/combo/search-cell-results.html b/combo/apps/search/templates/combo/search-cell-results.html
index 75e2968..dae4acb 100644
--- a/combo/apps/search/templates/combo/search-cell-results.html
+++ b/combo/apps/search/templates/combo/search-cell-results.html
@@ -1,4 +1,5 @@
{% load i18n %}
+{% if query %}
{% if cell.has_multiple_search_services %}<p class="search-service-label">{{ search_service.label }}</p>{% endif %}
{% if results.data %}
<div class="links-list">
@@ -15,3 +16,4 @@
{% trans "…no result found." %}
</div>
{% endif %}
+{% endif %}
diff --git a/tests/test_search.py b/tests/test_search.py
index 5bd8bc8..005755c 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -79,15 +79,18 @@ def test_search_cell(app):
resp = app.get('/ajax/search/%s/search1/?q=foo' % cell.pk, status=200)
assert requests_get.call_args[0][0] == 'http://www.example.net/search/?q=foo'
assert '<li>' not in resp.text
+ assert 'no result found' in resp.text
resp = app.get('/ajax/search/%s/search1/?q=foo%%23bar' % cell.pk, status=200)
assert requests_get.call_args[0][0] == 'http://www.example.net/search/?q=foo%23bar'
assert '<li>' not in resp.text
+ assert 'no result found' in resp.text
response['data'] = [{'url': 'http://test', 'text': 'barbarbar'}]
resp = app.get('/ajax/search/%s/search1/?q=foo' % cell.pk, status=200)
assert resp.text.count('<li>') == 1
assert '<li><a href="http://test">barbarbar</a>' in resp.text
+ assert 'no result found' not in resp.text
response['data'] = [{'url': 'http://test', 'text': 'barbarbar',
'description': 'this is <b>html</b>'}]
@@ -95,6 +98,11 @@ def test_search_cell(app):
assert resp.text.count('<li>') == 1
assert '<li><a href="http://test">barbarbar</a>' in resp.text
assert 'this is <b>html</b>' in resp.text
+ assert 'no result found' not in resp.text
+
+ resp = app.get('/ajax/search/%s/search1/?q=' % cell.pk, status=200)
+ assert '<li>' not in resp.text
+ assert 'no result found' not in resp.text
cell._search_services = {'data': ['search_alternate_key']}
cell.save()