Unverified Commit 1dda3fd6 authored by David Read's avatar David Read Committed by GitHub
Browse files

Merge pull request #42 from DataShades/py3

Py3 / CKAN 2.9
parents 27351c70 c36a64ba
......@@ -2,29 +2,28 @@
Displays a tree of organzations
NB This template can be slow because it is recursive and uses link_for. At
DGU we speeded up display of the tree 10 times (necessary as we have 1000
DGU we speeded up display of the tree 10 times (necessary as we have 1000
organizations) by replacing this template with a recursive code routine:
https://github.com/datagovuk/ckanext-dgu/blob/5fb78b354517c2198245bdc9c98fb5d6c82c6bcc/ckanext/dgu/lib/helpers.py#L140
https://github.com/datagovuk/ckanext-dgu/blob/5fb78b354517c2198245bdc9c98fb5d6c82c6bcc/ckanext/dgu/lib/helpers.py#L140
orgs - List of organizations
Example:
{% snippet 'organization/snippets/organization_tree.html', top_nodes=h.group_tree(type_='organization'), use_longnames=False %}
{% snippet 'organization/snippets/organization_tree.html', top_nodes=h.group_tree(type_='organization'), use_longnames=False %}
#}
{% resource 'hierarchy/hierarchy_theme.css' %}
{% resource 'hierarchy/jquery.hierarchy.js' %}
{% set type = 'asset' if h.ckan_version() > '2.9' else 'resource' %}
{% include 'hierarchy/snippets/hierarchy_' ~ type ~ '.html' %}
<ul class="hierarchy-tree-top">
{% for node in top_nodes recursive %}
{% set longname = h.group_tree_get_longname(node.name) %}
{% set display_text = node.title %}
{% set longname = h.group_tree_get_longname(node.name) %}
{% set display_text = node.title %}
{% if use_longnames and longname%}
{% set display_text = longname + " (" + display_text + ")" %}
{% endif %}
{% endif %}
{% if node.highlighted %}
<li class="highlighted" id="node_{{ node.name }}">
{% else %}
......
{% ckan_extends %}
{% block breadcrumb_content %}
{% if pkg %}
{% set dataset = h.dataset_display_name(pkg) %}
{% if pkg.organization %}
{% set organization = pkg.organization.title %}
<li>{% link_for _('Organizations'), controller='organization', action='index' %}</li>
{% set parent_list = h.group_tree_parents(pkg.organization.name) %}
{% for parent_node in parent_list %}
<li>{% link_for parent_node.title|truncate(35), controller='organization', action='read', id=parent_node.name %}</li>
{% endfor %}
<li>{% link_for organization|truncate(30), controller='organization', action='read', id=pkg.organization.name %}</li>
{% if pkg %}
{% set dataset = h.dataset_display_name(pkg) %}
{% if pkg.organization %}
{% set organization = pkg.organization.title %}
<li>{% link_for _('Organizations'), controller='organization', action='index' %}</li>
{% set parent_list = h.group_tree_parents(pkg.organization.name) %}
{% for parent_node in parent_list %}
<li>{% link_for parent_node.title|truncate(35), controller='organization', action='read', id=parent_node.name %}</li>
{% endfor %}
<li>{% link_for organization|truncate(30), controller='organization', action='read', id=pkg.organization.name %}</li>
{% else %}
<li>{% link_for _('Datasets'), controller='package', action='search' %}</li>
{% endif %}
<li{{ self.breadcrumb_content_selected() }}>{% link_for dataset|truncate(30), controller='package', action='read', id=pkg.name %}</li>
{% else %}
<li>{% link_for _('Datasets'), controller='package', action='search' %}</li>
<li>{% link_for _('Datasets'), controller='dataset' if h.ckan_version() > '2.9' else 'package', action='search' %}</li>
<li class="active"><a href="">{{ _('Create Dataset') }}</a></li>
{% endif %}
<li{{ self.breadcrumb_content_selected() }}>{% link_for dataset|truncate(30), controller='package', action='read', id=pkg.name %}</li>
{% else %}
<li>{% link_for _('Datasets'), controller='package', action='search' %}</li>
<li class="active"><a href="">{{ _('Create Dataset') }}</a></li>
{% endif %}
{% endblock %}
{% if allowable_parent_groups is not defined %}{% set allowable_parent_groups = c.allowable_parent_groups %}{% endif %}
<div class="control-group">
<label class="control-label" for="field-parent">{{ _("Parent") }}</label>
<div class="controls">
<select id="field-parent" name="groups__0__name" data-module="autocomplete">
{% set selected_parent = (data.get('groups') or [{'name': ''}])[0]['name'] %} {{ selected_parent }}
<option value="" {% if not selected_parent %} selected="selected" {% endif %}>{{ _('None - top level') }}</option>
{% for group in c.allowable_parent_groups or h.get_allowable_parent_groups(data.id) %}
{% for group in allowable_parent_groups or h.get_allowable_parent_groups(data.id) %}
<option value="{{ group.name }}" {% if group.name == selected_parent %}selected="selected"{% endif %}>{{ group.title }}</option>
{% endfor %}
</select>
......
{% ckan_extends %}
{% if group_dict is not defined %}{% set group_dict = c.group_dict %}{% endif %}
{% block heading %}
<h1 class="heading">
{% if organization.longname %}
......@@ -15,8 +17,8 @@
{% block description %}
{{ super() }}
{% if c.group_dict %}
{% if group_dict %}
<hr>
{% snippet 'organization/snippets/organization_tree.html', top_nodes=[h.group_tree_section(id_=c.group_dict.id, type_=c.group_dict.type, include_siblings=False)], use_shortnames=True %}
{% endif %}
{% 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 %}
{% endif %}
{% endblock %}
{% ckan_extends %}
{% if fields is not defined %}{% set fields = c.fields %}{% endif %}
{% block search_input %}
{{ super() }}
{% if include_children_option %}
{{ form.checkbox('include_children', label="Include Sub-Organizations", checked=(h.is_include_children_selected(c.fields)), value=True, error=error) }}
{{ form.checkbox('include_children', label="Include Sub-Organizations", checked=(h.is_include_children_selected(fields)), value=True, error=error) }}
{% endif %}
{% endblock %}
'''Tests that this extension doesn't break unrelated things'''
from builtins import object
import nose.tools
from ckan.tests import helpers
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment