diff --git a/combo/apps/search/models.py b/combo/apps/search/models.py
index fc8e56d7..87a1fbac 100644
--- a/combo/apps/search/models.py
+++ b/combo/apps/search/models.py
@@ -146,6 +146,8 @@ class SearchCell(CellBase):
# {{user_nameid}} or {{user_email}}).
kwargs['without_user'] = True
results = requests.get(url, **kwargs).json()
+ if service.get('data_key'):
+ results['data'] = results.get(service['data_key']) or []
hit_templates = {}
if service.get('hit_url_template'):
hit_templates['url'] = Template(service['hit_url_template'])
diff --git a/tests/test_search.py b/tests/test_search.py
index 909cb5af..b841e9c5 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -30,7 +30,12 @@ SEARCH_SERVICES = {
'search_tmpl': {
'label': 'Search with template',
'url': '[search_url]?q=%(q)s',
- }
+ },
+ 'search_alternate_key': {
+ 'label': 'Search with alternate key',
+ 'url': 'http://www.example.net/search/?q=%(q)s',
+ 'data_key': 'results',
+ },
}
TEMPLATE_VARS = {'search_url': 'http://search.example.net/'}
@@ -90,6 +95,14 @@ def test_search_cell(app):
assert '
barbarbar' in resp.text
assert 'this is html' in resp.text
+ cell._search_services = {'data': ['search_alternate_key']}
+ cell.save()
+ response = {'results': [{'url': 'http://test', 'text': 'barbarbar'}]}
+ mock_json.json.return_value = response
+ resp = app.get('/ajax/search/%s/search_alternate_key/?q=foo' % cell.pk, status=200)
+ assert resp.text.count('') == 1
+ assert 'barbarbar' in resp.text
+
with override_settings(TEMPLATE_VARS=TEMPLATE_VARS):
cell._search_services = {'data': ['search_tmpl']}
cell.save()
@@ -331,10 +344,11 @@ def test_manager_search_cell(app, admin_user):
with SearchServices(SEARCH_SERVICES):
resp = app.get('/manage/pages/%s/' % page.id)
- assert len(resp.form['c%s-_search_services' % cells[0].get_reference()].options) == 4
+ assert len(resp.form['c%s-_search_services' % cells[0].get_reference()].options) == 5
# simulate reordering of options
resp.form['c%s-_search_services' % cells[0].get_reference()].options = [
(u'search_tmpl', False, u'Search with template'),
+ (u'search_alternate_key', False, u'Search with alternate key'),
(u'_text', False, u'Page Contents'),
(u'search1', False, u'Search 1')]
resp.form['c%s-_search_services' % cells[0].get_reference()].value = ['search_tmpl', '_text']