Commit 0723abb7 authored by Sergey Motornyuk's avatar Sergey Motornyuk
Browse files

Add CKAN 2.9 support

parent 27351c70
ul.hierarchy-tree-top {
list-style-type: disc;
list-style-type: disc;
background: none;
}
ul.hierarchy-tree {
list-style-type: none;
background: url(images/vline.png) repeat-y;
margin: 0; padding: 0;
list-style-type: none;
background: url("images/vline.png") repeat-y;
margin: 0; padding: 0;
}
ul.hierarchy-tree {
margin-left: 10px;
}
margin-left: 10px;
}
ul.hierarchy-tree li {
margin: 0;
padding: 0 12px;
ul.hierarchy-tree li {
margin: 0;
padding: 0 12px;
line-height: 20px;
background: url(images/node.png) no-repeat;
background: url("images/node.png") no-repeat;
}
ul.hierarchy-tree li:last-child {
background: #fff url(images/lastnode.png) no-repeat;
background: #fff url("images/lastnode.png") no-repeat;
}
ul.hierarchy-tree-top li a, ul.hierarchy-tree li a{
......@@ -36,4 +36,3 @@ ul.hierarchy-tree-top li.highlighted > a, ul.hierarchy-tree li.highlighted > a {
/*text-decoration: underline;*/
text-shadow: 1px 1px #dddddd;
}
hierarchy_js:
filter: rjsmin
output: ckanext-hierarchy/%(version)s_hierarchy.js
extra:
preload:
- base/main
contents:
- jquery.hierarchy.js
hierarchy_css:
filters: cssrewrite
output: ckanext-hierarchy/%(version)s_hierarchy.css
contents:
- hierarchy_theme.css
import logging
import os
import ckan.plugins as p
from ckan import model
from ckan.lib.plugins import DefaultOrganizationForm
from ckan.common import c
from ckanext.hierarchy.logic import action
from ckanext.hierarchy import helpers
log = logging.getLogger(__name__)
c = p.toolkit.c
# This plugin is designed to work only these versions of CKAN
p.toolkit.check_ckan_version(min_version='2.0')
......@@ -45,10 +46,19 @@ class HierarchyDisplay(p.SingletonPlugin):
def update_config(self, config):
p.toolkit.add_template_directory(config, 'templates')
p.toolkit.add_template_directory(config, 'public')
p.toolkit.add_resource('public/scripts/vendor/jstree', 'jstree')
p.toolkit.add_public_directory(config, 'fanstatic')
p.toolkit.add_resource('fanstatic', 'hierarchy')
try:
from ckan.lib.webassets_tools import add_public_path
except ImportError:
pass
else:
asset_path = os.path.join(
os.path.dirname(__file__), 'fanstatic'
)
add_public_path(asset_path, '/')
# IActions
def get_actions(self):
......@@ -158,8 +168,6 @@ class HierarchyForm(p.SingletonPlugin, DefaultOrganizationForm):
return 'organization'
def setup_template_variables(self, context, data_dict):
from pylons import tmpl_context as c
group_id = data_dict.get('id')
c.allowable_parent_groups = \
helpers.get_allowable_parent_groups(group_id)
/*
* jsTree default theme 1.0
* Supported features: dots/no-dots, icons/no-icons, focused, loading
* Supported plugins: ui (hovered, clicked), checkbox, contextmenu, search
*/
.jstree-default li,
.jstree-default ins { background-image:url("d.png"); background-repeat:no-repeat; background-color:transparent; }
.jstree-default li { background-position:-90px 0; background-repeat:repeat-y; }
.jstree-default li.jstree-last { background:transparent; }
.jstree-default .jstree-open > ins { background-position:-72px 0; }
.jstree-default .jstree-closed > ins { background-position:-54px 0; }
.jstree-default .jstree-leaf > ins { background-position:-36px 0; }
.jstree-default .jstree-hovered { background:#e7f4f9; border:1px solid #d8f0fa; padding:0 2px 0 1px; }
.jstree-default .jstree-clicked { background:#beebff; border:1px solid #99defd; padding:0 2px 0 1px; }
.jstree-default a .jstree-icon { background-position:-56px -19px; }
.jstree-default a.jstree-loading .jstree-icon { background:url("throbber.gif") center center no-repeat !important; }
.jstree-default.jstree-focused { background:#ffffee; }
.jstree-default .jstree-no-dots li,
.jstree-default .jstree-no-dots .jstree-leaf > ins { background:transparent; }
.jstree-default .jstree-no-dots .jstree-open > ins { background-position:-18px 0; }
.jstree-default .jstree-no-dots .jstree-closed > ins { background-position:0 0; }
.jstree-default .jstree-no-icons a .jstree-icon { display:none; }
.jstree-default .jstree-search { font-style:italic; }
.jstree-default .jstree-no-icons .jstree-checkbox { display:inline-block; }
.jstree-default .jstree-no-checkboxes .jstree-checkbox { display:none !important; }
.jstree-default .jstree-checked > a > .jstree-checkbox { background-position:-38px -19px; }
.jstree-default .jstree-unchecked > a > .jstree-checkbox { background-position:-2px -19px; }
.jstree-default .jstree-undetermined > a > .jstree-checkbox { background-position:-20px -19px; }
.jstree-default .jstree-checked > a > .jstree-checkbox:hover { background-position:-38px -37px; }
.jstree-default .jstree-unchecked > a > .jstree-checkbox:hover { background-position:-2px -37px; }
.jstree-default .jstree-undetermined > a > .jstree-checkbox:hover { background-position:-20px -37px; }
#vakata-dragged.jstree-default ins { background:transparent !important; }
#vakata-dragged.jstree-default .jstree-ok { background:url("d.png") -2px -53px no-repeat !important; }
#vakata-dragged.jstree-default .jstree-invalid { background:url("d.png") -18px -53px no-repeat !important; }
#jstree-marker.jstree-default { background:url("d.png") -41px -57px no-repeat !important; text-indent:-100px; }
.jstree-default a.jstree-search { color:aqua; }
.jstree-default .jstree-locked a { color:silver; cursor:default; }
#vakata-contextmenu.jstree-default-context,
#vakata-contextmenu.jstree-default-context li ul { background:#f0f0f0; border:1px solid #979797; -moz-box-shadow: 1px 1px 2px #999; -webkit-box-shadow: 1px 1px 2px #999; box-shadow: 1px 1px 2px #999; }
#vakata-contextmenu.jstree-default-context li { }
#vakata-contextmenu.jstree-default-context a { color:black; }
#vakata-contextmenu.jstree-default-context a:hover,
#vakata-contextmenu.jstree-default-context .vakata-hover > a { padding:0 5px; background:#e8eff7; border:1px solid #aecff7; color:black; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; }
#vakata-contextmenu.jstree-default-context li.jstree-contextmenu-disabled a,
#vakata-contextmenu.jstree-default-context li.jstree-contextmenu-disabled a:hover { color:silver; background:transparent; border:0; padding:1px 4px; }
#vakata-contextmenu.jstree-default-context li.vakata-separator { background:white; border-top:1px solid #e0e0e0; margin:0; }
#vakata-contextmenu.jstree-default-context li ul { margin-left:-4px; }
/* IE6 BEGIN */
.jstree-default li,
.jstree-default ins,
#vakata-dragged.jstree-default .jstree-invalid,
#vakata-dragged.jstree-default .jstree-ok,
#jstree-marker.jstree-default { _background-image:url("d.gif"); }
.jstree-default .jstree-open ins { _background-position:-72px 0; }
.jstree-default .jstree-closed ins { _background-position:-54px 0; }
.jstree-default .jstree-leaf ins { _background-position:-36px 0; }
.jstree-default a ins.jstree-icon { _background-position:-56px -19px; }
#vakata-contextmenu.jstree-default-context ins { _display:none; }
#vakata-contextmenu.jstree-default-context li { _zoom:1; }
.jstree-default .jstree-undetermined a .jstree-checkbox { _background-position:-20px -19px; }
.jstree-default .jstree-checked a .jstree-checkbox { _background-position:-38px -19px; }
.jstree-default .jstree-unchecked a .jstree-checkbox { _background-position:-2px -19px; }
/* IE6 END */
\ No newline at end of file
{% asset 'hierarchy/hierarchy_js' %}
{% asset 'hierarchy/hierarchy_css' %}
{% resource 'hierarchy/hierarchy_theme.css' %}
{% resource 'hierarchy/jquery.hierarchy.js' %}
{% ckan_extends %}
{% if group_dict is not defined %}
{% set group_dict = c.group_dict %}
{% endif %}
{% block page_heading %}
{% if c.group_dict.longname %}
{{ c.group_dict.longname }} ({{ c.group_dict.display_name }})
{% if group_dict.longname %}
{{ group_dict.longname }} ({{ group_dict.display_name }})
{% else %}
{{ super() }}
{% endif %}
......@@ -10,11 +14,9 @@
{% block organization_description %}
{{ super() }}
{# TODO: Add JSTree #}
<div id="organization-tree">
{% snippet 'organization/snippets/organization_tree.html', top_nodes=[h.group_tree_section(id_=c.group_dict.id, type_=c.group_dict.type)], use_longnames=True %}
{% snippet 'organization/snippets/organization_tree.html', top_nodes=[h.group_tree_section(id_=group_dict.id, type_=group_dict.type)], use_longnames=True %}
</div>
{% endblock %}
{% ckan_extends %}
<!-- JSTree is included, but so far does nothing. Need to encapsulate it in a
'javascript module' -->
{% block scripts %}
{{ super() }}
{% resource 'jstree/jquery.jstree.js' %}
{% endblock %}
{% ckan_extends %}
{% block groups_search_form %}
{# This is the same as the original BUT we also pass the 'include_children_option' parameter to the snippet #}
{% if q is not defined %}{% set q = c.q %}{% endif %}
{% if fields_grouped is not defined %}{% set fields_grouped = c.fields_grouped %}{% endif %}
{% if search_facetssearch_facets is not defined %}{% set search_facets = c.search_facets %}{% endif %}
{% if facet_titles is not defined %}{% set facet_titles = c.facet_titles %}{% endif %}
{% if translated_fields is not defined %}{% set translated_fields = c.translated_fields %}{% endif %}
{% if remove_field is not defined %}{% set remove_field = c.remove_field %}{% endif %}
{% if sort_by_selected is not defined %}{% set sort_by_selected = c.sort_by_selected %}{% endif %}
{% if fields is not defined %}{% set fields = c.fields %}{% endif %}
{% if page is not defined %}{% set page = c.page %}{% endif %}
{% set facets = {
'fields': c.fields_grouped,
'search': c.search_facets,
'titles': c.facet_titles,
'translated_fields': c.translated_fields,
'remove_field': c.remove_field }
%}
{% set sorting = [
{% block groups_search_form %}
{# This is the same as the original BUT we also pass the 'include_children_option' parameter to the snippet #}
{% set facets = {
'fields': fields_grouped,
'search': search_facets,
'titles': facet_titles,
'translated_fields': translated_fields,
'remove_field': remove_field }
%}
{% set sorting = [
(_('Relevance'), 'score desc, metadata_modified desc'),
(_('Name Ascending'), 'title_string asc'),
(_('Name Descending'), 'title_string desc'),
(_('Last Modified'), 'metadata_modified desc'),
(_('Popular'), 'views_recent desc') if g.tracking_enabled else (false, false) ]
%}
{% snippet 'snippets/search_form.html', form_id='organization-datasets-search-form', type='dataset', query=c.q, sorting=sorting, sorting_selected=c.sort_by_selected, count=c.page.item_count, facets=facets, placeholder=_('Search datasets...'), show_empty=request.params, fields=c.fields, include_children_option=true %}
%}
{% snippet 'snippets/search_form.html', form_id='organization-datasets-search-form', type='dataset', query=q, sorting=sorting, sorting_selected=sort_by_selected, count=page.item_count, facets=facets, placeholder=_('Search datasets...'), show_empty=request.params, fields=fields, include_children_option=true %}
{% endblock %}
......@@ -4,11 +4,14 @@ Display a hierarchical tree of organizations
Example:
{% snippet "organization/snippets/organization_list.html" %}
{% snippet "organization/snippets/organization_list.html" %}
#}
{% if q is not defined %}{% set q = c.q %}{% endif %}
<div id="publisher-tree">
{% if c.q %}
{% 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') %}
......
......@@ -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 %}
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