Commit 1fa0d6fa authored by David Read's avatar David Read
Browse files

flake8

parent 52c6a1cf
import re
import ckan.plugins as p
import ckan.model as model
from ckan.common import request
......@@ -16,9 +14,9 @@ def group_tree(organizations=[], type_='organization'):
def group_tree_filter(organizations, group_tree_list, highlight=False):
# this method leaves only the sections of the tree corresponding to the list
# since it was developed for the users, all children organizations from the
# organizations in the list are included
# this method leaves only the sections of the tree corresponding to the
# list since it was developed for the users, all children organizations
# from the organizations in the list are included
def traverse_select_highlighted(group_tree, selection=[], highlight=False):
# add highlighted branches to the filtered tree
if group_tree['highlighted']:
......@@ -40,16 +38,20 @@ def group_tree_filter(organizations, group_tree_list, highlight=False):
return filtered_tree
def group_tree_section(id_, type_='organization', include_parents=True, include_siblings=True):
def group_tree_section(id_, type_='organization', include_parents=True,
include_siblings=True):
return p.toolkit.get_action('group_tree_section')(
{'include_parents': include_parents, 'include_siblings': include_siblings}, {'id': id_, 'type': type_, })
{'include_parents': include_parents,
'include_siblings': include_siblings},
{'id': id_, 'type': type_, })
def group_tree_parents(id_, type_='organization'):
tree_node = p.toolkit.get_action('organization_show')({}, {'id': id_})
if (tree_node['groups']):
parent_id = tree_node['groups'][0]['name']
parent_node = p.toolkit.get_action('organization_show')({}, {'id': parent_id})
parent_node = \
p.toolkit.get_action('organization_show')({}, {'id': parent_id})
return group_tree_parents(parent_id) + [parent_node]
else:
return []
......
......@@ -45,16 +45,19 @@ def group_tree_section(context, data_dict):
include_parents = context.get('include_parents', True)
include_siblings = context.get('include_siblings', True)
if include_parents:
root_group = (group.get_parent_group_hierarchy(type=group_type) or [group])[0]
root_group = (group.get_parent_group_hierarchy(type=group_type)
or [group])[0]
else:
root_group = group
if include_siblings or root_group == group:
return _group_tree_branch(root_group, highlight_group_name=group.name,
type=group_type)
else:
section_subtree = _group_tree_branch(group, highlight_group_name=group.name,
section_subtree = _group_tree_branch(group,
highlight_group_name=group.name,
type=group_type)
return _nest_group_tree_list(group.get_parent_group_hierarchy(type=group_type),
return _nest_group_tree_list(
group.get_parent_group_hierarchy(type=group_type),
section_subtree)
......
......@@ -2,8 +2,6 @@ import nose.tools
from bs4 import BeautifulSoup
from ckan.tests import helpers, factories
from ckan.lib import search
from ckan.common import c
from ckan import model
......@@ -54,31 +52,14 @@ class TestSearchApi(object):
def create_fixtures():
parent_org = factories.Organization(name='parent_org', title='Parent')
child_org = factories.Organization(name='child_org', title='child')
member = model.Member(group=model.Group.get(child_org['id']), table_id=parent_org['id'], table_name='group', capacity='parent')
member = model.Member(
group=model.Group.get(child_org['id']),
table_id=parent_org['id'], table_name='group', capacity='parent')
model.Session.add(member)
model.Session.commit()
parent_dataset = factories.Dataset(name='parent', title='Parent',
owner_org=parent_org['id'])
child_dataset = factories.Dataset(name='child', title='Child',
owner_org=child_org['id'])
decoy_dataset = factories.Dataset(name='decoy', title='Decoy')
factories.Dataset(name='decoy', title='Decoy')
return parent_org, child_org, parent_dataset, child_dataset
class LoadPluginsBase(object):
@classmethod
def setup_class(cls):
'''Load plugins'''
import ckan.plugins as p
try:
config['ckan.plugins'] = ' '.join(cls._load_plugins)
except AttributeError:
pass
cls._get_test_app()
@classmethod
def teardown_class(cls):
import ckan.plugins as p
for plugin in reversed(getattr(cls, '_load_plugins', [])):
p.unload(plugin)
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