|
1 |
| -from ckan.plugins import toolkit |
2 | 1 | import ckan.plugins as p
|
3 | 2 | import ckan.model as model
|
4 | 3 | from ckan.common import request, is_flask_request
|
@@ -47,45 +46,40 @@ def group_tree_section(id_, type_='organization', include_parents=True,
|
47 | 46 | {'id': id_, 'type': type_, })
|
48 | 47 |
|
49 | 48 |
|
50 |
| -def get_group_type_show(type_): |
51 |
| - """ User with custom group types will be able to |
52 |
| - use a "custom_type_show" action or the base action organization_show |
53 |
| - for each new group type.""" |
54 |
| - custom_show_action = toolkit.config.get( |
55 |
| - 'ckanext.hierarchy.group_type_show_action.{}'.format(type_) |
56 |
| - ) |
57 |
| - return custom_show_action or '{}_show'.format(type_) |
| 49 | +def _get_action_name(group_id): |
| 50 | + model_obj = model.Group.get(group_id) |
| 51 | + return "organization_show" if model_obj.is_organization else "group_show" |
58 | 52 |
|
59 | 53 |
|
60 |
| -def group_tree_parents(id_, type_='organization'): |
61 |
| - show_fn = get_group_type_show(type_) |
| 54 | +def group_tree_parents(id_): |
| 55 | + action_name = _get_action_name(id_) |
62 | 56 | data_dict = {
|
63 | 57 | 'id': id_,
|
64 | 58 | 'include_dataset_count': False,
|
65 | 59 | 'include_users': False,
|
66 | 60 | 'include_followers': False,
|
67 | 61 | 'include_tags': False
|
68 | 62 | }
|
69 |
| - tree_node = p.toolkit.get_action(show_fn)({}, data_dict) |
| 63 | + tree_node = p.toolkit.get_action(action_name)({}, data_dict) |
70 | 64 | if (tree_node['groups']):
|
71 | 65 | parent_id = tree_node['groups'][0]['name']
|
72 | 66 | parent_node = \
|
73 |
| - p.toolkit.get_action(show_fn)({}, {'id': parent_id}) |
| 67 | + p.toolkit.get_action(action_name)({}, {'id': parent_id}) |
74 | 68 | return group_tree_parents(parent_id) + [parent_node]
|
75 | 69 | else:
|
76 | 70 | return []
|
77 | 71 |
|
78 | 72 |
|
79 | 73 | def group_tree_get_longname(id_, default="", type_='organization'):
|
80 |
| - show_fn = get_group_type_show(type_) |
| 74 | + action_name = _get_action_name(id_) |
81 | 75 | data_dict = {
|
82 | 76 | 'id': id_,
|
83 | 77 | 'include_dataset_count': False,
|
84 | 78 | 'include_users': False,
|
85 | 79 | 'include_followers': False,
|
86 | 80 | 'include_tags': False
|
87 | 81 | }
|
88 |
| - tree_node = p.toolkit.get_action(show_fn)({}, data_dict) |
| 82 | + tree_node = p.toolkit.get_action(action_name)({}, data_dict) |
89 | 83 | longname = tree_node.get("longname", default)
|
90 | 84 | if not longname:
|
91 | 85 | return default
|
|
0 commit comments