0001-search-don-t-display-no-result-found-when-there-is-n.patch
combo/apps/search/models.py | ||
---|---|---|
115 | 115 |
if not cell.is_visible(request.user) or not cell.page.is_visible(request.user): |
116 | 116 |
raise PermissionDenied |
117 | 117 | |
118 |
query = request.GET.get('q') |
|
119 | ||
118 | 120 |
def render_response(service={}, results={'err': 0, 'data': []}): |
119 | 121 |
template_names = ['combo/search-cell-results.html'] |
120 | 122 |
if cell.slug: |
121 | 123 |
template_names.insert(0, 'combo/cells/%s/search-cell-results.html' % cell.slug) |
122 | 124 |
tmpl = template.loader.select_template(template_names) |
123 |
context = {'cell': cell, 'results': results, 'search_service': service} |
|
125 |
context = { |
|
126 |
'cell': cell, |
|
127 |
'results': results, |
|
128 |
'search_service': service, |
|
129 |
'query': query |
|
130 |
} |
|
124 | 131 |
return HttpResponse(tmpl.render(context, request), content_type='text/html') |
125 | 132 | |
126 | 133 |
for service in cell.search_services: |
... | ... | |
129 | 136 |
else: |
130 | 137 |
return render_response() |
131 | 138 | |
132 |
query = request.GET.get('q') |
|
133 | 139 |
if not query: |
134 | 140 |
return render_response(service) |
135 | 141 |
combo/apps/search/templates/combo/search-cell-results.html | ||
---|---|---|
10 | 10 |
{% endfor %} |
11 | 11 |
</ul> |
12 | 12 |
</div> |
13 |
{% else %}
|
|
13 |
{% elif query %}
|
|
14 | 14 |
<div class="infonotice"> |
15 | 15 |
{% trans "…no result found." %} |
16 | 16 |
</div> |
tests/test_search.py | ||
---|---|---|
80 | 80 |
resp = app.get('/ajax/search/%s/search1/?q=foo' % cell.pk, status=200) |
81 | 81 |
assert requests_get.call_args[0][0] == 'http://www.example.net/search/?q=foo' |
82 | 82 |
assert '<li>' not in resp.text |
83 |
assert 'no result found' in resp.text |
|
83 | 84 | |
84 | 85 |
resp = app.get('/ajax/search/%s/search1/?q=foo%%23bar' % cell.pk, status=200) |
85 | 86 |
assert requests_get.call_args[0][0] == 'http://www.example.net/search/?q=foo%23bar' |
86 | 87 |
assert '<li>' not in resp.text |
88 |
assert 'no result found' in resp.text |
|
87 | 89 | |
88 | 90 |
response['data'] = [{'url': 'http://test', 'text': 'barbarbar'}] |
89 | 91 |
resp = app.get('/ajax/search/%s/search1/?q=foo' % cell.pk, status=200) |
90 | 92 |
assert resp.text.count('<li>') == 1 |
91 | 93 |
assert '<li><a href="http://test">barbarbar</a>' in resp.text |
94 |
assert 'no result found' not in resp.text |
|
92 | 95 | |
93 | 96 |
response['data'] = [{'url': 'http://test', 'text': 'barbarbar', |
94 | 97 |
'description': 'this is <b>html</b>'}] |
... | ... | |
96 | 99 |
assert resp.text.count('<li>') == 1 |
97 | 100 |
assert '<li><a href="http://test">barbarbar</a>' in resp.text |
98 | 101 |
assert 'this is <b>html</b>' in resp.text |
102 |
assert 'no result found' not in resp.text |
|
103 | ||
104 |
resp = app.get('/ajax/search/%s/search1/?q=' % cell.pk, status=200) |
|
105 |
assert '<li>' not in resp.text |
|
106 |
assert 'no result found' not in resp.text |
|
99 | 107 | |
100 | 108 |
cell._search_services = {'data': ['search_alternate_key']} |
101 | 109 |
cell.save() |
102 |
- |