Commit bf7b2df3 authored by David Read's avatar David Read
Browse files

Solve error when current organization does not have children - see...

Solve error when current organization does not have children - see https://github.com/davidread/ckanext-hierarchy/pull/27
parent c1196d8f
......@@ -110,13 +110,15 @@ class HierarchyDisplay(p.SingletonPlugin):
get_children_group_hierarchy(type='organization')
children_names = [org[1] for org in children_org_hierarchy]
# remove include_children clause - it is a message for this func,
# not solr
query = query.replace('include_children: "True"', '')
if children_names:
# remove existing owner_org:"<parent>" clause - we'll replace
# it with the tree of orgs in a moment
query = query.replace(
'owner_org:"{}"'.format(c.group_dict.get('id')), '')
# remove include_children clause
query = query.replace('include_children: "True"', '')
# add the org clause
query = query.strip()
......@@ -127,7 +129,9 @@ class HierarchyDisplay(p.SingletonPlugin):
'organization:{}'.format(org_name)
for org_name in [c.group_dict.get('name')] +
children_names))
search_params['q'] = query
search_params['q'] = query
# add it back to fields
# c.fields += [('include_children', 'True')]
......
......@@ -21,6 +21,28 @@ class TestOrgPage(helpers.FunctionalTestBase):
search_results = scrape_search_results(response)
eq(search_results, set(('parent', 'child')))
def test_search_parent_excluding_children(self):
parent_org, child_org, parent_dataset, child_dataset = \
create_fixtures()
app = self._get_test_app()
response = app.get(
url='/organization/parent_org')
search_results = scrape_search_results(response)
eq(search_results, set(('parent',)))
def test_search_child_including_children(self):
parent_org, child_org, parent_dataset, child_dataset = \
create_fixtures()
app = self._get_test_app()
response = app.get(
url='/organization/child_org?include_children=True')
search_results = scrape_search_results(response)
eq(search_results, set(('child',)))
def scrape_search_results(response):
soup = BeautifulSoup(response.body)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment