Skip to content

Commit 9078e8e

Browse files
authored
Merge pull request #64 from ckan/improve_show_function
Back to base show functions
2 parents 65c2382 + c0c3a8d commit 9078e8e

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,7 @@ should come before hierarchy_form and hierarchy_group_form
108108

109109
## Config settings
110110

111-
### Custom group_type_show_action
112-
113-
If you use custom group types you'll need to define which `show`
114-
action to use for each group type. For example, if you have a
115-
group type called `country` you'll need to create a new action
116-
called `country_show` in you extension. This is the default behaviour
117-
and in this case you don't need to add any settings to your config file.
118-
On the contrary, if you prefer to continue using the base action `organization_show`
119-
you'll need to add the following setting to your config file:
120-
121-
ckanext.hierarchy.group_type_show_action.country = organization_show
122-
123-
You can define a different action for each group type.
111+
None at present
124112

125113
## Tests
126114

ckanext/hierarchy/helpers.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from ckan.plugins import toolkit
21
import ckan.plugins as p
32
import ckan.model as model
43
from ckan.common import request, is_flask_request
@@ -47,45 +46,40 @@ def group_tree_section(id_, type_='organization', include_parents=True,
4746
{'id': id_, 'type': type_, })
4847

4948

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"
5852

5953

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_)
6256
data_dict = {
6357
'id': id_,
6458
'include_dataset_count': False,
6559
'include_users': False,
6660
'include_followers': False,
6761
'include_tags': False
6862
}
69-
tree_node = p.toolkit.get_action(show_fn)({}, data_dict)
63+
tree_node = p.toolkit.get_action(action_name)({}, data_dict)
7064
if (tree_node['groups']):
7165
parent_id = tree_node['groups'][0]['name']
7266
parent_node = \
73-
p.toolkit.get_action(show_fn)({}, {'id': parent_id})
67+
p.toolkit.get_action(action_name)({}, {'id': parent_id})
7468
return group_tree_parents(parent_id) + [parent_node]
7569
else:
7670
return []
7771

7872

7973
def group_tree_get_longname(id_, default="", type_='organization'):
80-
show_fn = get_group_type_show(type_)
74+
action_name = _get_action_name(id_)
8175
data_dict = {
8276
'id': id_,
8377
'include_dataset_count': False,
8478
'include_users': False,
8579
'include_followers': False,
8680
'include_tags': False
8781
}
88-
tree_node = p.toolkit.get_action(show_fn)({}, data_dict)
82+
tree_node = p.toolkit.get_action(action_name)({}, data_dict)
8983
longname = tree_node.get("longname", default)
9084
if not longname:
9185
return default

ckanext/hierarchy/templates/package/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{% set organization = pkg.organization.title %}
88
{% set group_type = pkg.organization.type %}
99
<li>{% link_for _('Organizations'), controller=group_type, action='index' %}</li>
10-
{% set parent_list = h.group_tree_parents(pkg.organization.name, type_=group_type) %}
10+
{% set parent_list = h.group_tree_parents(pkg.organization.name) %}
1111
{% for parent_node in parent_list %}
1212
<li>{% link_for parent_node.title|truncate(35), controller=group_type, action='read', id=parent_node.name %}</li>
1313
{% endfor %}

0 commit comments

Comments
 (0)