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
......@@ -87,6 +87,7 @@ To install ckanext-hierarchy:
cd /usr/lib/ckan/default/src
pip install -e "git+https://github.com/davidread/ckanext-hierarchy.git#egg=ckanext-hierarchy"
pip install -r ckanext-hierarchy/requirements.txt
3. Add ``hierarchy_display`` and ``hierarchy_form`` to the ``ckan.plugins`` setting in your CKAN
config file (by default the config file is located at
......@@ -156,4 +157,3 @@ To publish a new version to PyPI follow these steps:
This module is openly licensed with AGPLv3 - see LICENSE file.
Copyright belongs to commit authors. Commits 2013-2017 by @davidread are Crown Copyright.
......@@ -62,6 +62,7 @@ cd -
echo "Installing ckanext-hierarchy and its requirements..."
python setup.py develop
pip install -r dev-requirements.txt
pip install -r requirements.txt
echo "Moving test.ini into a subdir..."
mkdir subdir
......
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')
......@@ -21,7 +22,7 @@ def custom_convert_from_extras(key, data, errors, context):
data[key] = ""
to_remove = []
for data_key in data.keys():
for data_key in list(data.keys()):
if (data_key[0] == 'extras'):
data_value = data[data_key]
if 'key' in data_value and data_value['key'] == key[-1]:
......@@ -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 1.0-rc3
* http://jstree.com/
*
* Copyright (c) 2010 Ivan Bozhanov (vakata.com)
*
* Licensed same as jquery - under the terms of either the MIT License or the GPL Version 2 License
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* $Date: 2011-02-09 01:17:14 +0200 (ср, 09 февр 2011) $
* $Revision: 236 $
*/
/*jslint browser: true, onevar: true, undef: true, bitwise: true, strict: true */
/*global window : false, clearInterval: false, clearTimeout: false, document: false, setInterval: false, setTimeout: false, jQuery: false, navigator: false, XSLTProcessor: false, DOMParser: false, XMLSerializer: false*/
"use strict";
// top wrapper to prevent multiple inclusion (is this OK?)
(function () { if(jQuery && jQuery.jstree) { return; }
var is_ie6 = false, is_ie7 = false, is_ff2 = false;
/*
* jsTree core
*/
(function ($) {
// Common functions not related to jsTree
// decided to move them to a `vakata` "namespace"
$.vakata = {};
// CSS related functions
$.vakata.css = {
get_css : function(rule_name, delete_flag, sheet) {
rule_name = rule_name.toLowerCase();
var css_rules = sheet.cssRules || sheet.rules,
j = 0;
do {
if(css_rules.length && j > css_rules.length + 5) { return false; }
if(css_rules[j].selectorText && css_rules[j].selectorText.toLowerCase() == rule_name) {
if(delete_flag === true) {
if(sheet.removeRule) { sheet.removeRule(j); }
if(sheet.deleteRule) { sheet.deleteRule(j); }
return true;
}
else { return css_rules[j]; }
}
}
while (css_rules[++j]);
return false;
},
add_css : function(rule_name, sheet) {
if($.jstree.css.get_css(rule_name, false, sheet)) { return false; }
if(sheet.insertRule) { sheet.insertRule(rule_name + ' { }', 0); } else { sheet.addRule(rule_name, null, 0); }
return $.vakata.css.get_css(rule_name);
},
remove_css : function(rule_name, sheet) {
return $.vakata.css.get_css(rule_name, true, sheet);
},
add_sheet : function(opts) {
var tmp = false, is_new = true;
if(opts.str) {
if(opts.title) { tmp = $("style[id='" + opts.title + "-stylesheet']")[0]; }
if(tmp) { is_new = false; }
else {
tmp = document.createElement("style");
tmp.setAttribute('type',"text/css");
if(opts.title) { tmp.setAttribute("id", opts.title + "-stylesheet"); }
}
if(tmp.styleSheet) {
if(is_new) {
document.getElementsByTagName("head")[0].appendChild(tmp);
tmp.styleSheet.cssText = opts.str;
}
else {
tmp.styleSheet.cssText = tmp.styleSheet.cssText + " " + opts.str;
}
}
else {
tmp.appendChild(document.createTextNode(opts.str));
document.getElementsByTagName("head")[0].appendChild(tmp);
}
return tmp.sheet || tmp.styleSheet;
}
if(opts.url) {
if(document.createStyleSheet) {
try { tmp = document.createStyleSheet(opts.url); } catch (e) { }
}
else {
tmp = document.createElement('link');
tmp.rel = 'stylesheet';
tmp.type = 'text/css';
tmp.media = "all";
tmp.href = opts.url;
document.getElementsByTagName("head")[0].appendChild(tmp);
return tmp.styleSheet;
}
}
}
};
// private variables
var instances = [], // instance array (used by $.jstree.reference/create/focused)
focused_instance = -1, // the index in the instance array of the currently focused instance
plugins = {}, // list of included plugins
prepared_move = {}; // for the move_node function
// jQuery plugin wrapper (thanks to jquery UI widget function)
$.fn.jstree = function (settings) {
var isMethodCall = (typeof settings == 'string'), // is this a method call like $().jstree("open_node")
args = Array.prototype.slice.call(arguments, 1),
returnValue = this;
// if a method call execute the method on all selected instances
if(isMethodCall) {
if(settings.substring(0, 1) == '_') { return returnValue; }
this.each(function() {
var instance = instances[$.data(this, "jstree_instance_id")],
methodValue = (instance && $.isFunction(instance[settings])) ? instance[settings].apply(instance, args) : instance;
if(typeof methodValue !== "undefined" && (settings.indexOf("is_") === 0 || (methodValue !== true && methodValue !== false))) { returnValue = methodValue; return false; }
});
}
else {
this.each(function() {
// extend settings and allow for multiple hashes and $.data
var instance_id = $.data(this, "jstree_instance_id"),
a = [],
b = settings ? $.extend({}, true, settings) : {},
c = $(this),
s = false,
t = [];
a = a.concat(args);
if(c.data("jstree")) { a.push(c.data("jstree")); }
b = a.length ? $.extend.apply(null, [true, b].concat(a)) : b;
// if an instance already exists, destroy it first
if(typeof instance_id !== "undefined" && instances[instance_id]) { instances[instance_id].destroy(); }
// push a new empty object to the instances array
instance_id = parseInt(instances.push({}),10) - 1;
// store the jstree instance id to the container element
$.data(this, "jstree_instance_id", instance_id);
// clean up all plugins
b.plugins = $.isArray(b.plugins) ? b.plugins : $.jstree.defaults.plugins.slice();
b.plugins.unshift("core");
// only unique plugins
b.plugins = b.plugins.sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",");
// extend defaults with passed data
s = $.extend(true, {}, $.jstree.defaults, b);
s.plugins = b.plugins;
$.each(plugins, function (i, val) {
if($.inArray(i, s.plugins) === -1) { s[i] = null; delete s[i]; }
else { t.push(i); }
});
s.plugins = t;
// push the new object to the instances array (at the same time set the default classes to the container) and init
instances[instance_id] = new $.jstree._instance(instance_id, $(this).addClass("jstree jstree-" + instance_id), s);
// init all activated plugins for this instance
$.each(instances[instance_id]._get_settings().plugins, function (i, val) { instances[instance_id].data[val] = {}; });
$.each(instances[instance_id]._get_settings().plugins, function (i, val) { if(plugins[val]) { plugins[val].__init.apply(instances[instance_id]); } });
// initialize the instance
setTimeout(function() { if(instances[instance_id]) { instances[instance_id].init(); } }, 0);
});
}
// return the jquery selection (or if it was a method call that returned a value - the returned value)
return returnValue;
};
// object to store exposed functions and objects
$.jstree = {
defaults : {
plugins : []
},
_focused : function () { return instances[focused_instance] || null; },
_reference : function (needle) {
// get by instance id
if(instances[needle]) { return instances[needle]; }
// get by DOM (if still no luck - return null
var o = $(needle);
if(!o.length && typeof needle === "string") { o = $("#" + needle); }
if(!o.length) { return null; }
return instances[o.closest(".jstree").data("jstree_instance_id")] || null;
},
_instance : function (index, container, settings) {
// for plugins to store data in
this.data = { core : {} };
this.get_settings = function () { return $.extend(true, {}, settings); };
this._get_settings = function () { return settings; };
this.get_index = function () { return index; };
this.get_container = function () { return container; };
this.get_container_ul = function () { return container.children("ul:eq(0)"); };
this._set_settings = function (s) {
settings = $.extend(true, {}, settings, s);
};
},
_fn : { },
plugin : function (pname, pdata) {
pdata = $.extend({}, {
__init : $.noop,
__destroy : $.noop,
_fn : {},
defaults : false
}, pdata);
plugins[pname] = pdata;
$.jstree.defaults[pname] = pdata.defaults;
$.each(pdata._fn, function (i, val) {
val.plugin = pname;
val.old = $.jstree._fn[i];
$.jstree._fn[i] = function () {
var rslt,
func = val,
args = Array.prototype.slice.call(arguments),
evnt = new $.Event("before.jstree"),
rlbk = false;
if(this.data.core.locked === true && i !== "unlock" && i !== "is_locked") { return; }
// Check if function belongs to the included plugins of this instance
do {
if(func && func.plugin && $.inArray(func.plugin, this._get_settings().plugins) !== -1) { break; }
func = func.old;
} while(func);
if(!func) { return; }
// context and function to trigger events, then finally call the function
if(i.indexOf("_") === 0) {
rslt = func.apply(this, args);
}
else {
rslt = this.get_container().triggerHandler(evnt, { "func" : i, "inst" : this, "args" : args, "plugin" : func.plugin });
if(rslt === false) { return; }
if(typeof rslt !== "undefined") { args = rslt; }
rslt = func.apply(
$.extend({}, this, {
__callback : function (data) {
this.get_container().triggerHandler( i + '.jstree', { "inst" : this, "args" : args, "rslt" : data, "rlbk" : rlbk });
},
__rollback : function () {
rlbk = this.get_rollback();
return rlbk;
},
__call_old : function (replace_arguments) {
return func.old.apply(this, (replace_arguments ? Array.prototype.slice.call(arguments, 1) : args ) );
}
}), args);
}
// return the result
return rslt;
};
$.jstree._fn[i].old = val.old;
$.jstree._fn[i].plugin = pname;
});
},
rollback : function (rb) {
if(rb) {
if(!$.isArray(rb)) { rb = [ rb ]; }
$.each(rb, function (i, val) {
instances[val.i].set_rollback(val.h, val.d);
});
}
}
};
// set the prototype for all instances
$.jstree._fn = $.jstree._instance.prototype = {};
// load the css when DOM is ready
$(function() {
// code is copied from jQuery ($.browser is deprecated + there is a bug in IE)
var u = navigator.userAgent.toLowerCase(),
v = (u.match( /.+?(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
css_string = '' +
'.jstree ul, .jstree li { display:block; margin:0 0 0 0; padding:0 0 0 0; list-style-type:none; } ' +
'.jstree li { display:block; min-height:18px; line-height:18px; white-space:nowrap; margin-left:18px; min-width:18px; } ' +
'.jstree-rtl li { margin-left:0; margin-right:18px; } ' +
'.jstree > ul > li { margin-left:0px; } ' +
'.jstree-rtl > ul > li { margin-right:0px; } ' +
'.jstree ins { display:inline-block; text-decoration:none; width:18px; height:18px; margin:0 0 0 0; padding:0; } ' +
'.jstree a { display:inline-block; line-height:16px; height:16px; color:black; white-space:nowrap; text-decoration:none; padding:1px 2px; margin:0; } ' +
'.jstree a:focus { outline: none; } ' +
'.jstree a > ins { height:16px; width:16px; } ' +
'.jstree a > .jstree-icon { margin-right:3px; } ' +
'.jstree-rtl a > .jstree-icon { margin-left:3px; margin-right:0; } ' +
'li.jstree-open > ul { display:block; } ' +
'li.jstree-closed > ul { display:none; } ';
// Correct IE 6 (does not support the > CSS selector)
if(/msie/.test(u) && parseInt(v, 10) == 6) {
is_ie6 = true;
// fix image flicker and lack of caching
try {
document.execCommand("BackgroundImageCache", false, true);
} catch (err) { }
css_string += '' +
'.jstree li { height:18px; margin-left:0; margin-right:0; } ' +
'.jstree li li { margin-left:18px; } ' +
'.jstree-rtl li li { margin-left:0px; margin-right:18px; } ' +
'li.jstree-open ul { display:block; } ' +
'li.jstree-closed ul { display:none !important; } ' +
'.jstree li a { display:inline; border-width:0 !important; padding:0px 2px !important; } ' +
'.jstree li a ins { height:16px; width:16px; margin-right:3px; } ' +
'.jstree-rtl li a ins { margin-right:0px; margin-left:3px; } ';
}
// Correct IE 7 (shifts anchor nodes onhover)
if(/msie/.test(u) && parseInt(v, 10) == 7) {
is_ie7 = true;
css_string += '.jstree li a { border-width:0 !important; padding:0px 2px !important; } ';
}
// correct ff2 lack of display:inline-block
if(!/compatible/.test(u) && /mozilla/.test(u) && parseFloat(v, 10) < 1.9) {
is_ff2 = true;
css_string += '' +
'.jstree ins { display:-moz-inline-box; } ' +
'.jstree li { line-height:12px; } ' + // WHY??
'.jstree a { display:-moz-inline-box; } ' +
'.jstree .jstree-no-icons .jstree-checkbox { display:-moz-inline-stack !important; } ';
/* this shouldn't be here as it is theme specific */
}
// the default stylesheet
$.vakata.css.add_sheet({ str : css_string, title : "jstree" });
});
// core functions (open, close, create, update, delete)
$.jstree.plugin("core", {
__init : function () {
this.data.core.locked = false;
this.data.core.to_open = this.get_settings().core.initially_open;
this.data.core.to_load = this.get_settings().core.initially_load;
},
defaults : {
html_titles : false,
animation : 500,
initially_open : [],
initially_load : [],
open_parents : true,
notify_plugins : true,
rtl : false,
load_open : false,
strings : {
loading : "Loading ...",
new_node : "New node",
multiple_selection : "Multiple selection"
}
},
_fn : {
init : function () {
this.set_focus();
if(this._get_settings().core.rtl) {
this.get_container().addClass("jstree-rtl").css("direction", "rtl");
}
this.get_container().html("<ul><li class='jstree-last jstree-leaf'><ins>&#160;</ins><a class='jstree-loading' href='#'><ins class='jstree-icon'>&#160;</ins>" + this._get_string("loading") + "</a></li></ul>");
this.data.core.li_height = this.get_container_ul().find("li.jstree-closed, li.jstree-leaf").eq(0).height() || 18;
this.get_container()
.delegate("li > ins", "click.jstree", $.proxy(function (event) {
var trgt = $(event.target);
// if(trgt.is("ins") && event.pageY - trgt.offset().top < this.data.core.li_height) { this.toggle_node(trgt); }
this.toggle_node(trgt);
}, this))
.bind("mousedown.jstree", $.proxy(function () {
this.set_focus(); // This used to be setTimeout(set_focus,0) - why?
}, this))
.bind("dblclick.jstree", function (event) {
var sel;
if(document.selection && document.selection.empty) { document.selection.empty(); }
else {
if(window.getSelection) {
sel = window.getSelection();
try {
sel.removeAllRanges();
sel.collapse();
} catch (err) { }
}
}
});
if(this._get_settings().core.notify_plugins) {
this.get_container()
.bind("load_node.jstree", $.proxy(function (e, data) {
var o = this._get_node(data.rslt.obj),
t = this;
if(o === -1) { o = this.get_container_ul(); }
if(!o.length) { return; }
o.find("li").each(function () {
var th = $(this);
if(th.data("jstree")) {
$.each(th.data("jstree"), function (plugin, values) {
if(t.data[plugin] && $.isFunction(t["_" + plugin + "_notify"])) {
t["_" + plugin + "_notify"].call(t, th, values);
}
});
}
});
}, this));
}
if(this._get_settings().core.load_open) {
this.get_container()
.bind("load_node.jstree", $.proxy(function (e, data) {
var o = this._get_node(data.rslt.obj),
t = this;
if(o === -1) { o = this.get_container_ul(); }
if(!o.length) { return; }
o.find("li.jstree-open:not(:has(ul))").each(function () {
t.load_node(this, $.noop, $.noop);
});
}, this));
}
this.__callback();
this.load_node(-1, function () { this.loaded(); this.reload_nodes(); });
},
destroy : function () {
var i,
n = this.get_index(),
s = this._get_settings(),
_this = this;
$.each(s.plugins, function (i, val) {
try { plugins[val].__destroy.apply(_this); } catch(err) { }
});
this.__callback();