diff --git a/combo/apps/search/models.py b/combo/apps/search/models.py index 87a1fbac..fc4aecf2 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 75e29681..dae4acb7 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 %}

{{ search_service.label }}

{% endif %} {% if results.data %} {% endif %} +{% endif %} diff --git a/tests/test_search.py b/tests/test_search.py index 5bd8bc89..005755cc 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 '
  • ' 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 '
  • ' 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('
  • ') == 1 assert '
  • barbarbar' in resp.text + assert 'no result found' not in resp.text response['data'] = [{'url': 'http://test', 'text': 'barbarbar', 'description': 'this is html'}] @@ -95,6 +98,11 @@ def test_search_cell(app): assert resp.text.count('
  • ') == 1 assert '
  • barbarbar' in resp.text assert 'this is html' in resp.text + assert 'no result found' not in resp.text + + resp = app.get('/ajax/search/%s/search1/?q=' % cell.pk, status=200) + assert '
  • ' not in resp.text + assert 'no result found' not in resp.text cell._search_services = {'data': ['search_alternate_key']} cell.save()