diff --git a/ckanext/hierarchy/helpers.py b/ckanext/hierarchy/helpers.py index 1a43e383f..879cd1e9b 100644 --- a/ckanext/hierarchy/helpers.py +++ b/ckanext/hierarchy/helpers.py @@ -98,3 +98,53 @@ def is_include_children_selected(fields): if request.params.get('include_children'): include_children_selected = True return include_children_selected + + +def render_tree(top_nodes=None, group_type='organization'): + '''Returns HTML for a hierarchy of all publishers''' + if not top_nodes: + from ckan.logic import get_action + from ckan import model + context = {'model': model, 'session': model.Session} + top_nodes = get_action('group_tree')(context=context, + data_dict={'type': group_type}) + + + return _render_tree(top_nodes, group_type) + + +def render_tree_list(top_nodes=None, group_type='organization'): + '''Returns HTML for a hierarchy of all publishers''' + if not top_nodes: + return '' + return _render_tree(top_nodes, group_type) + + +def _render_tree(top_nodes, group_type): + '''Renders a tree of nodes. 10x faster than Jinja/organization_tree.html + Note: avoids the slow url_for routine. + ''' + html = '' + +def _render_tree_node(node, group_type): + body = '' + node_name = node['name'] + if node['highlighted']: + body += f'
  • ' + else: + body += f'
  • ' + + if group_type == "organization": + body += '%s' % (node['name'], node['title']) + else: + body += '%s' % (node['name'], node['title']) + if node['children']: + body+= '' + body += "
  • " + return body diff --git a/ckanext/hierarchy/plugin.py b/ckanext/hierarchy/plugin.py index 6cb1f6a28..4e6e3846e 100644 --- a/ckanext/hierarchy/plugin.py +++ b/ckanext/hierarchy/plugin.py @@ -77,6 +77,8 @@ def get_helpers(self): helpers.get_allowable_parent_groups, 'is_include_children_selected': helpers.is_include_children_selected, + 'render_tree': helpers.render_tree, + 'render_tree_list': helpers.render_tree_list } # IPackageController diff --git a/ckanext/hierarchy/templates/group/about.html b/ckanext/hierarchy/templates/group/about.html index 9cb419ed1..d9acb6df0 100644 --- a/ckanext/hierarchy/templates/group/about.html +++ b/ckanext/hierarchy/templates/group/about.html @@ -14,8 +14,10 @@ {% block group_description %} {{ super() }} + {% set type = 'asset' if h.ckan_version() > '2.9' else 'resource' %} + {% include 'hierarchy/snippets/hierarchy_' ~ type ~ '.html' %}
    - {% snippet 'group/snippets/group_tree.html', top_nodes=[h.group_tree_section(id_=group_dict.id, type_=group_dict.type)], use_longnames=True %} + {{ h.render_tree(top_nodes=[h.group_tree_section(id_=group_dict.id, type_=group_dict.type)],group_type="group") | safe }}
    {% endblock %} diff --git a/ckanext/hierarchy/templates/group/snippets/group_list.html b/ckanext/hierarchy/templates/group/snippets/group_list.html index 47f358cbb..55bc6f40b 100644 --- a/ckanext/hierarchy/templates/group/snippets/group_list.html +++ b/ckanext/hierarchy/templates/group/snippets/group_list.html @@ -9,12 +9,13 @@ #} {% if q is not defined %}{% set q = c.q %}{% endif %} - +{% set type = 'asset' if h.ckan_version() > '2.9' else 'resource' %} +{% include 'hierarchy/snippets/hierarchy_' ~ type ~ '.html' %}
    {% if q %} {% set top_nodes = h.group_tree_highlight(groups, h.group_tree(type_='group')) %} {% else %} {% set top_nodes = h.group_tree(organizations=groups, type_='group') %} {% endif %} - {% snippet 'group/snippets/group_tree.html', top_nodes=top_nodes, use_longnames=True %} + {{ h.render_tree_list(top_nodes=top_nodes,group_type="group") | safe }}
    diff --git a/ckanext/hierarchy/templates/group/snippets/info.html b/ckanext/hierarchy/templates/group/snippets/info.html index b1d31a992..4aab46873 100644 --- a/ckanext/hierarchy/templates/group/snippets/info.html +++ b/ckanext/hierarchy/templates/group/snippets/info.html @@ -18,7 +18,9 @@

    {% block description %} {{ super() }} {% if group_dict %} + {% set type = 'asset' if h.ckan_version() > '2.9' else 'resource' %} + {% include 'hierarchy/snippets/hierarchy_' ~ type ~ '.html' %}
    - {% snippet 'group/snippets/group_tree.html', top_nodes=[h.group_tree_section(id_=group_dict.id, type_=group_dict.type, include_siblings=False)], use_shortnames=True %} + {{ h.render_tree(top_nodes=[h.group_tree_section(id_=group_dict.id, type_=group_dict.type, include_siblings=False)],group_type="group") | safe }} {% endif %} {% endblock %} diff --git a/ckanext/hierarchy/templates/organization/about.html b/ckanext/hierarchy/templates/organization/about.html index d85152b03..74ab2887f 100644 --- a/ckanext/hierarchy/templates/organization/about.html +++ b/ckanext/hierarchy/templates/organization/about.html @@ -14,9 +14,10 @@ {% block organization_description %} {{ super() }} - + {% set type = 'asset' if h.ckan_version() > '2.9' else 'resource' %} + {% include 'hierarchy/snippets/hierarchy_' ~ type ~ '.html' %}
    - {% snippet 'organization/snippets/organization_tree.html', top_nodes=[h.group_tree_section(id_=group_dict.id, type_=group_dict.type)], use_longnames=True %} + {{ h.render_tree(top_nodes=[h.group_tree_section(id_=group_dict.id, type_=group_dict.type)]) | safe }}
    {% endblock %} diff --git a/ckanext/hierarchy/templates/organization/snippets/organization_list.html b/ckanext/hierarchy/templates/organization/snippets/organization_list.html index 4e24264ea..d5512df9c 100644 --- a/ckanext/hierarchy/templates/organization/snippets/organization_list.html +++ b/ckanext/hierarchy/templates/organization/snippets/organization_list.html @@ -8,13 +8,14 @@ #} -{% if q is not defined %}{% set q = c.q %}{% endif %} - +{% if q is not defined %}{% set q = g.q %}{% endif %} +{% set type = 'asset' if h.ckan_version() > '2.9' else 'resource' %} +{% include 'hierarchy/snippets/hierarchy_' ~ type ~ '.html' %}
    {% if q %} {% set top_nodes = h.group_tree_highlight(organizations, h.group_tree(type_='organization')) %} {% else %} {% set top_nodes = h.group_tree(organizations=organizations, type_='organization') %} {% endif %} - {% snippet 'organization/snippets/organization_tree.html', top_nodes=top_nodes, use_longnames=True %} + {{ h.render_tree_list(top_nodes=top_nodes) | safe }}
    diff --git a/ckanext/hierarchy/templates/snippets/organization.html b/ckanext/hierarchy/templates/snippets/organization.html index 80ce313b4..3d2a4fae4 100644 --- a/ckanext/hierarchy/templates/snippets/organization.html +++ b/ckanext/hierarchy/templates/snippets/organization.html @@ -18,7 +18,9 @@

    {% block description %} {{ super() }} {% if group_dict %} + {% set type = 'asset' if h.ckan_version() > '2.9' else 'resource' %} + {% include 'hierarchy/snippets/hierarchy_' ~ type ~ '.html' %}
    - {% snippet 'organization/snippets/organization_tree.html', top_nodes=[h.group_tree_section(id_=group_dict.id, type_=group_dict.type, include_siblings=False)], use_shortnames=True %} + {{ h.render_tree(top_nodes=[h.group_tree_section(id_=group_dict.id, type_=group_dict.type, include_siblings=False)]) | safe }} {% endif %} {% endblock %}