Commit 600e2960 authored by David Read's avatar David Read
Browse files

Merge branch 'apply_flake8' of git://github.com/vrk-kpa/ckanext-hierarchy into vrk-kpa-apply_flake8

parents 4cb5c78d 05ea22b2
......@@ -4,6 +4,7 @@ import ckan.plugins as p
import ckan.model as model
from ckan.common import request
def group_tree(organizations=[], type_='organization'):
full_tree_list = p.toolkit.get_action('group_tree')({}, {'type': type_})
......@@ -31,7 +32,7 @@ def group_tree_filter(organizations, group_tree_list, highlight=False):
for child in group_tree.get('children', []):
traverse_select_highlighted(child, selection)
filtered_tree=[]
filtered_tree = []
# first highlights all the organizations from the list in the three
for group in group_tree_highlight(organizations, group_tree_list):
traverse_select_highlighted(group, filtered_tree, highlight)
......@@ -41,26 +42,28 @@ def group_tree_filter(organizations, group_tree_list, highlight=False):
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})
return group_tree_parents(parent_id) + [parent_node]
else:
return []
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})
return group_tree_parents(parent_id) + [parent_node]
else:
return []
def group_tree_get_longname(id_, default="", type_='organization'):
tree_node = p.toolkit.get_action('organization_show')({},{'id':id_})
longname = tree_node.get("longname", default)
if not longname:
return default
return longname
tree_node = p.toolkit.get_action('organization_show')({}, {'id': id_})
longname = tree_node.get("longname", default)
if not longname:
return default
return longname
def group_tree_highlight(organizations, group_tree_list):
def group_tree_highlight(organizations, group_tree_list):
def traverse_highlight(group_tree, name_list):
if group_tree.get('name', "") in name_list:
group_tree['highlighted'] = True
......@@ -69,13 +72,14 @@ def group_tree_highlight(organizations, group_tree_list):
for child in group_tree.get('children', []):
traverse_highlight(child, name_list)
selected_names = [ o.get('name',None) for o in organizations]
selected_names = [o.get('name', None) for o in organizations]
print(selected_names)
for group in group_tree_list:
traverse_highlight(group, selected_names)
return group_tree_list
def get_allowable_parent_groups(group_id):
if group_id:
group = model.Group.get(group_id)
......@@ -86,6 +90,7 @@ def get_allowable_parent_groups(group_id):
group_type='organization')
return allowable_parent_groups
def is_include_children_selected(fields):
include_children_selected = False
if request.params.get('include_children'):
......
......@@ -38,7 +38,7 @@ def group_tree_section(context, data_dict):
group_type = data_dict.get('type', 'group')
if group.type != group_type:
how_type_was_set = 'was specified' if data_dict.get('type') \
else 'is filtered by default'
else 'is filtered by default'
raise p.toolkit.ValidationError(
'Group type is "%s" not "%s" that %s' %
(group.type, group_type, how_type_was_set))
......@@ -48,15 +48,16 @@ def group_tree_section(context, data_dict):
root_group = (group.get_parent_group_hierarchy(type=group_type) or [group])[0]
else:
root_group = group
if include_siblings or 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,
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)
def _nest_group_tree_list(group_tree_list, group_tree_leaf):
'''Returns a tree branch composed by nesting the groups in the list.
......@@ -69,9 +70,9 @@ def _nest_group_tree_list(group_tree_list, group_tree_leaf):
for group in group_tree_list:
log.debug(group)
node = GroupTreeNode(
{'id': group.id,
'name': group.name,
'title': group.title})
{'id': group.id,
'name': group.name,
'title': group.title})
if not root_node:
root_node = last_node = node
else:
......
......@@ -16,8 +16,8 @@ log = logging.getLogger(__name__)
# This plugin is designed to work only these versions of CKAN
p.toolkit.check_ckan_version(min_version='2.0')
def custom_convert_from_extras(key, data, errors, context):
def custom_convert_from_extras(key, data, errors, context):
'''Converts values from extras, tailored for groups.'''
# Set to empty string to remove Missing objects
......@@ -27,18 +27,18 @@ def custom_convert_from_extras(key, data, errors, context):
for data_key in data.keys():
if (data_key[0] == 'extras'):
data_value = data[data_key]
if( 'key' in data_value and data_value['key'] == key[-1]):
data[key] = data_value['value']
to_remove.append(data_key)
break
if ('key' in data_value and data_value['key'] == key[-1]):
data[key] = data_value['value']
to_remove.append(data_key)
break
else:
return
for remove_key in to_remove:
del data[remove_key]
class HierarchyDisplay(p.SingletonPlugin):
class HierarchyDisplay(p.SingletonPlugin):
p.implements(p.IConfigurer, inherit=True)
p.implements(p.IActions, inherit=True)
p.implements(p.ITemplateHelpers, inherit=True)
......@@ -70,7 +70,6 @@ class HierarchyDisplay(p.SingletonPlugin):
'is_include_children_selected': helpers.is_include_children_selected,
}
# IPackageController
def before_search(self, search_params):
......@@ -95,9 +94,9 @@ class HierarchyDisplay(p.SingletonPlugin):
# Remove the param from the fields - NB no longer works
# e.g. [('include_children', 'True')]
new_fields = set()
for field,value in c.fields:
for field, value in c.fields:
if (field != 'include_children'):
new_fields.add((field,value))
new_fields.add((field, value))
c.fields = list(new_fields)
# parse the query string to check if children are requested
......@@ -140,10 +139,8 @@ class HierarchyDisplay(p.SingletonPlugin):
class HierarchyForm(p.SingletonPlugin, DefaultOrganizationForm):
p.implements(p.IGroupForm, inherit=True)
# IGroupForm
def group_types(self):
......
from setuptools import setup, find_packages
import sys, os
version = '0.1'
......
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