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

Merge branch 'apply_flake8' of git:// 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 = []
# 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_})
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]
return []
def group_tree_get_longname(id_, default="", type_='organization'):
tree_node = p.toolkit.get_action('organization_show')({},{'id':id_})
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]
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):
return allowable_parent_groups
def is_include_children_selected(fields):
include_children_selected = False
if request.params.get('include_children'):
......@@ -48,7 +48,7 @@ def group_tree_section(context, data_dict):
root_group = (group.get_parent_group_hierarchy(type=group_type) or [group])[0]
root_group = group
if include_siblings or root_group==group:
if include_siblings or root_group == group:
return _group_tree_branch(root_group,,
......@@ -57,6 +57,7 @@ def group_tree_section(context, data_dict):
return _nest_group_tree_list(group.get_parent_group_hierarchy(type=group_type),
def _nest_group_tree_list(group_tree_list, group_tree_leaf):
'''Returns a tree branch composed by nesting the groups in the list.
......@@ -16,8 +16,8 @@ log = logging.getLogger(__name__)
# This plugin is designed to work only these versions of CKAN
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,7 +27,7 @@ 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]):
if ('key' in data_value and data_value['key'] == key[-1]):
data[key] = data_value['value']
......@@ -37,8 +37,8 @@ def custom_convert_from_extras(key, data, errors, context):
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))
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