Skip to content

Commit

Permalink
Merge pull request #5 from FCSCOpendata/orgs
Browse files Browse the repository at this point in the history
Fix Themes and Subthemes under package
  • Loading branch information
MuhammadIsmailShahzad authored May 31, 2022
2 parents bff718f + e831114 commit 3e165fd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
38 changes: 38 additions & 0 deletions ckanext/hierarchy/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,41 @@ def _render_tree_node(node, group_type):
body += '</ul>'
body += "</li>"
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




3 changes: 2 additions & 1 deletion ckanext/hierarchy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion ckanext/hierarchy/templates/group/snippets/group_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
</div>

0 comments on commit 3e165fd

Please sign in to comment.