From 69f7ef8f80dd1bf7740f80566da3973a881b373e Mon Sep 17 00:00:00 2001 From: steveoni Date: Mon, 30 May 2022 14:58:11 +0100 Subject: [PATCH] update subthemes and themes list under package --- ckanext/hierarchy/helpers.py | 38 +++++++++++++++++++ ckanext/hierarchy/plugin.py | 3 +- .../templates/group/snippets/group_list.html | 6 ++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/ckanext/hierarchy/helpers.py b/ckanext/hierarchy/helpers.py index 879cd1e9..8df48eba 100644 --- a/ckanext/hierarchy/helpers.py +++ b/ckanext/hierarchy/helpers.py @@ -148,3 +148,41 @@ def _render_tree_node(node, group_type): body += '' body += "" return body + + + +def package_themes_list(groups): + group_rel_dict = {} + + for group in groups: + group_id = group.get("id") + + if group_id not in group_rel_dict: + group_dict = group_tree_section(id_=group_id, type_= "group") + parent_id = group_dict.get("id") + + if parent_id in group_rel_dict: + parent_data = group_rel_dict[parent_id].get("data") + child_dict = [ch for ch in parent_data.get("children") if ch.get("id")== group_id] + child_dict[0]['highlighted'] = True + + else: + id = group_id if group_id == parent_id else parent_id + group_rel_dict[id] = { + "data": group_dict, + "child": [ch.get("id") for ch in group_dict["children"]] + } + else: + higlighted = group_rel_dict[group_id]["data"].get("higlighted") + if not higlighted: + highlighted = True + + group_list = [] + for _, values in group_rel_dict.items(): + group_list.append(values.get('data')) + + return group_list + + + + \ No newline at end of file diff --git a/ckanext/hierarchy/plugin.py b/ckanext/hierarchy/plugin.py index 4e6e3846..04d39d88 100644 --- a/ckanext/hierarchy/plugin.py +++ b/ckanext/hierarchy/plugin.py @@ -78,7 +78,8 @@ def get_helpers(self): 'is_include_children_selected': helpers.is_include_children_selected, 'render_tree': helpers.render_tree, - 'render_tree_list': helpers.render_tree_list + 'render_tree_list': helpers.render_tree_list, + 'package_themes_list': helpers.package_themes_list } # IPackageController diff --git a/ckanext/hierarchy/templates/group/snippets/group_list.html b/ckanext/hierarchy/templates/group/snippets/group_list.html index 55bc6f40..6e137bc3 100644 --- a/ckanext/hierarchy/templates/group/snippets/group_list.html +++ b/ckanext/hierarchy/templates/group/snippets/group_list.html @@ -17,5 +17,9 @@ {% else %} {% set top_nodes = h.group_tree(organizations=groups, type_='group') %} {% endif %} - {{ h.render_tree_list(top_nodes=top_nodes,group_type="group") | safe }} + {% if pkg_dict %} + {{ h.render_tree_list(top_nodes=h.package_themes_list(groups),group_type="group") | safe }} + {% else %} + {{ h.render_tree_list(top_nodes=top_nodes,group_type="group") | safe }} + {% endif %}