Move to new layout
authorNoe Gaumont <ngaumont@logilab.fr>
Fri, 21 Jun 2019 11:15:30 +0200
changeset 53 7f5ea945ea6b
parent 52 80e25f895d87
child 54 4ba1dc67cc6e
Move to new layout
MANIFEST.in
__init__.py
__pkginfo__.py
adapters.py
cubicweb_treeview/__init__.py
cubicweb_treeview/__pkginfo__.py
cubicweb_treeview/adapters.py
cubicweb_treeview/data/cubes.treeview.css
cubicweb_treeview/data/cubes.treeview.js
cubicweb_treeview/i18n/en.po
cubicweb_treeview/i18n/es.po
cubicweb_treeview/i18n/fr.po
cubicweb_treeview/migration/postcreate.py
cubicweb_treeview/views/__init__.py
cubicweb_treeview/views/formwidgets.py
cubicweb_treeview/views/treeview.py
data/cubes.treeview.css
data/cubes.treeview.js
i18n/en.po
i18n/es.po
i18n/fr.po
migration/postcreate.py
setup.py
test/test_treeview.py
tox.ini
views/__init__.py
views/formwidgets.py
views/treeview.py
--- a/MANIFEST.in	Fri Jun 21 11:09:18 2019 +0200
+++ b/MANIFEST.in	Fri Jun 21 11:15:30 2019 +0200
@@ -1,5 +1,10 @@
 include *.py
 include */*.py
-recursive-include data *.gif *.png *.ico *.css *.js
-recursive-include i18n *.po
-recursive-include wdoc *
+recursive-include cubicweb_treeview *.py
+recursive-include cubicweb_treeview/data *.gif *.png *.ico *.css *.js
+recursive-include cubicweb_treeview/i18n *.po
+recursive-include cubicweb_treeview/wdoc *
+recursive-include test/data bootstrap_cubes *.py
+include *.ini
+recursive-include debian changelog compat control copyright rules
+include cubicweb-treeview.spec
--- a/__init__.py	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-"""cubicweb-treeview application package
-
-tree-building adapters, widgets
-"""
--- a/__pkginfo__.py	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-# pylint: disable=W0622
-"""cubicweb-treeview application packaging information"""
-
-modname = 'treeview'
-distname = 'cubicweb-treeview'
-
-numversion = (0, 1, 1)
-version = '.'.join(str(num) for num in numversion)
-
-license = 'LGPL'
-author = 'LOGILAB S.A. (Paris, FRANCE)'
-author_email = 'contact@logilab.fr'
-description = 'tree-building adapters, widgets, views'
-web = 'http://www.cubicweb.org/project/%s' % distname
-
-__depends__ =  {'cubicweb': '>= 3.16.0'}
-__recommends__ = {}
-
-classifiers = [
-    'Environment :: Web Environment',
-    'Framework :: CubicWeb',
-    'Programming Language :: Python',
-    'Programming Language :: JavaScript',
-    ]
-
-from os import listdir as _listdir
-from os.path import join, isdir
-from glob import glob
-
-THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname)
-
-def listdir(dirpath):
-    return [join(dirpath, fname) for fname in _listdir(dirpath)
-            if fname[0] != '.' and not fname.endswith('.pyc')
-            and not fname.endswith('~')
-            and not isdir(join(dirpath, fname))]
-
-data_files = [
-    # common files
-    [THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']],
-    ]
-# check for possible extended cube layout
-for dname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'wdoc', 'i18n', 'migration'):
-    if isdir(dname):
-        data_files.append([join(THIS_CUBE_DIR, dname), listdir(dname)])
-# Note: here, you'll need to add subdirectories if you want
-# them to be included in the debian package
-
--- a/adapters.py	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-
-__docformat__ = "restructuredtext en"
-
-from cubicweb.entities.adapters import ITreeAdapter
-
-class TVITreeAdapter(ITreeAdapter):
-    def is_editable_leaf(self):
-        return len(self.same_type_children()) == 0
-
-    def editable_children(self, entities=False):
-        return self.same_type_children(entities=entities)
-
-def registration_callback(vreg):
-    vreg.register_all(globals().values(), __name__, (TVITreeAdapter,))
-    vreg.register_and_replace(TVITreeAdapter, ITreeAdapter)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/__init__.py	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,4 @@
+"""cubicweb-treeview application package
+
+tree-building adapters, widgets
+"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/__pkginfo__.py	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,24 @@
+# pylint: disable=W0622
+"""cubicweb-treeview application packaging information"""
+
+modname = 'treeview'
+distname = 'cubicweb-treeview'
+
+numversion = (0, 1, 1)
+version = '.'.join(str(num) for num in numversion)
+
+license = 'LGPL'
+author = 'LOGILAB S.A. (Paris, FRANCE)'
+author_email = 'contact@logilab.fr'
+description = 'tree-building adapters, widgets, views'
+web = 'http://www.cubicweb.org/project/%s' % distname
+
+__depends__ = {'cubicweb': '>= 3.24.0'}
+__recommends__ = {}
+
+classifiers = [
+    'Environment :: Web Environment',
+    'Framework :: CubicWeb',
+    'Programming Language :: Python',
+    'Programming Language :: JavaScript',
+]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/adapters.py	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,30 @@
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+
+__docformat__ = "restructuredtext en"
+
+from cubicweb.entities.adapters import ITreeAdapter
+
+class TVITreeAdapter(ITreeAdapter):
+    def is_editable_leaf(self):
+        return len(self.same_type_children()) == 0
+
+    def editable_children(self, entities=False):
+        return self.same_type_children(entities=entities)
+
+def registration_callback(vreg):
+    vreg.register_all(globals().values(), __name__, (TVITreeAdapter,))
+    vreg.register_and_replace(TVITreeAdapter, ITreeAdapter)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/data/cubes.treeview.css	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,28 @@
+/* css for treeview widget */
+
+div.msg{
+ color : red;
+ margin: 1em 0;
+}
+.ui-dialog.ui-widget{
+ background:#fff;
+ }
+
+.ui-dialog ul.treeview {
+ background-color: transparent;
+}
+
+.ui-dialog ul.treeview li a.selectable,
+.ui-dialog ul.treeview li a.selectable:hover{
+ color:#E6820E;
+}
+
+.ui-dialog ul.treeview span,
+.ui-dialog ul.treeview span:hover{
+ color:#666;
+}
+
+/* bootstrap compatibility */
+.cw-folder input[type='checkbox'] {
+ margin: 0px;
+ height:inherit; }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/data/cubes.treeview.js	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,86 @@
+cw.treewidget = new Namespace('cw.treewidget');
+
+$.extend(cw.treewidget, {
+    validateCheckBox: function(tree_uid, required){
+        var related = [[],[]];
+        $('#holder_' + tree_uid + ' input:checked').each(function(){
+            related[0].push($(this).val());
+            related[1].push($(this).siblings('span[class="hidden"]').text());
+        });
+        cw.treewidget.validateRelated(null, required, tree_uid, related );
+    },
+
+    validateRelated: function(thisnode, required, tree_uid, related){
+        if (thisnode){
+            related[1].push($(thisnode).text());
+        }
+        if(required && related[0].length == 0){
+            cw.treewidget.updateTreeWidgetMessage(tree_uid, "please, select at least one value");
+            return;
+        }
+        var $holder = $('#sel_' + tree_uid);
+        var rname = tree_uid.replace('--', ':');
+        for(var i=0; i<related[0].length; i++){
+            var $div = $('<div />');
+            $div.append($('<input/>').attr({
+                id: rname, name: rname,
+                type: "hidden", value: related[0][i]}));
+            $div.append('<a href="javascript:$.noop()" onclick="$(this).parent().remove()">[x] </a>');
+            $div.append($('<span/>').html(related[1][i]));
+            $holder.append($div);
+        }
+        $holder.trigger('md.close');
+    },
+
+    updateTreeWidgetMessage: function(tree_uid, msg){
+       $('#' + tree_uid + ' div.error').empty().html(msg);
+    }
+});
+
+(function ($) {
+    var defaultSettings = {
+        modal: true,
+        width: 600,
+        height: 600,
+        cancelButton: 'button_cancel',
+        okButton: 'button_ok',
+        buttons: []
+    };
+
+    var methods = {
+        __init__: function(required, multiple, url, options) {
+            var tree_uid = $(this).attr('id');
+            var settings = methods.initSettings(tree_uid, required, multiple, options);
+            var dialog = $(this).dialog(settings);
+            if(url){
+                var d = $(this).loadxhtml(url);
+            };
+            var $holder = $('#sel_' + tree_uid);
+            $holder.bind("md.close", function() {
+                dialog.dialog('close');
+            });
+        },
+
+        initSettings: function(tree_uid, required, multiple, options) {
+            var settings = $.extend({}, defaultSettings, options);
+            if (!settings.buttons.length) {
+                if (multiple) {
+                    settings.buttons.push({id: "btn-validate",
+                                           text: settings.okButton,
+                                           click: function() {
+                                               cw.treewidget.validateCheckBox(tree_uid, required);
+                                           }});
+                }
+                settings.buttons.push({id: "btn-cancel", text: settings.cancelButton,
+                                       click: function() {
+                                           $(this).dialog("close");
+                                       }});
+            }
+            return settings;
+        }
+    };
+
+    $.fn.treewidget = function(required, multiple, url, options) {
+        return methods.__init__.apply(this, [required, multiple, url, options]);
+    };
+})(jQuery);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/i18n/en.po	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,19 @@
+msgid ""
+msgstr ""
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: pygettext.py 1.5\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+msgid "no available values"
+msgstr ""
+
+msgid "please, select at least one value"
+msgstr ""
+
+msgid "remove"
+msgstr ""
+
+msgid "select"
+msgstr ""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/i18n/es.po	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,19 @@
+msgid ""
+msgstr ""
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: pygettext.py 1.5\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+msgid "no available values"
+msgstr ""
+
+msgid "please, select at least one value"
+msgstr ""
+
+msgid "remove"
+msgstr ""
+
+msgid "select"
+msgstr ""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/i18n/fr.po	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,19 @@
+msgid ""
+msgstr ""
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: pygettext.py 1.5\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+msgid "no available values"
+msgstr "pas de données disponibles"
+
+msgid "please, select at least one value"
+msgstr "au moins une valeur doit être sélectionnée"
+
+msgid "remove"
+msgstr "supprimer"
+
+msgid "select"
+msgstr "sélectionner"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/migration/postcreate.py	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# copyright 2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr -- mailto:contact@logilab.fr
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""cubicweb-treeview postcreate script, executed at instance creation time or when
+the cube is added to an existing instance.
+
+You could setup site properties or a workflow here for example.
+"""
+
+# Example of site property change
+#set_property('ui.site-title', "<sitename>")
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/views/formwidgets.py	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,131 @@
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""Set of tree-building widgets, some based on jQuery treeview
+plugin.
+"""
+
+__docformat__ = "restructuredtext en"
+_ = unicode
+
+from logilab.mtconverter import xml_escape
+
+from cubicweb import tags
+from cubicweb.web import formwidgets as fwdgs
+
+class TreeViewWidget(fwdgs.FieldWidget):
+    """form widget to link to keywords of a given classification"""
+
+    subvid = 'oneline_edit'
+
+    needs_js = ('cubicweb.ajax.js', 'cubicweb.widgets.js',
+                'jquery.treeview.js', 'jquery.ui.js', 'cubes.treeview.js')
+    needs_css = ('jquery.treeview.css', 'jquery.ui.css', 'cubes.treeview.css')
+
+    html = (u'''<a href="javascript:$.noop()" '''
+            u'''onclick="$('#%(tree_uid)s').treewidget(%(required)s, %(multiple)s, false, {'cancelButton': '%(cancel)s', 'okButton': '%(ok)s'}) ;return false;">'''
+            u'''%(open_link)s&nbsp;%(remove_link)s</a>'''
+            u'''<div id="sel_%(tree_uid)s">%(selected)s</div>'''
+            u'''<div id="%(tree_uid)s" style="display: none;">'''
+            u'''<div class="error"></div><div id="holder_%(tree_uid)s">%(form)s</div></div>''') #'
+
+    remove_link_html = u'''<a href="javascript:$.noop()" cubicweb:link="%s" class="remove_link"
+    onclick="$('#sel_%s').empty()">[%s]</a>'''
+
+    def __init__(self, leavesonly=False,
+                 multiple=None, level=None, **kwargs):
+        """
+        :param leavesonly: True if only leaves can be selected
+        :param multiple: True if more than one value can be selected. If this parameter is set,
+                         the rtype's cardinality is ignored
+        :param level: only select values on the given tree level
+        """
+        super(TreeViewWidget, self).__init__(**kwargs)
+        self.leavesonly = int(leavesonly)
+        self.multiple = multiple
+        self.level = level
+
+    def _render(self, form, field, renderer):
+        _ = form._cw._
+        treerset = self._filter_rset(field, form)
+        if not treerset:
+            return _(u"no available values")
+        self.required = int(field.required)
+        self.guess_multiple(field, form)
+        tree_uid = field.input_name(form, self.suffix).replace(':', '--')
+        related = self.compute_related(form, field)
+        treeform = self.render_treeform(form, treerset, tree_uid, related)
+        remove_link = self.remove_link_html % (field.name, tree_uid, _('remove'))
+        return self.html % {
+            'required': self.required,
+            'multiple': self.multiple,
+            'selected': u'\n'.join(self.render_selected(field.input_name(form, self.suffix), related)),
+            'tree_uid': tree_uid, 'form': treeform,
+            'open_link': xml_escape(_('select').capitalize()),
+            'remove_link': remove_link,
+            'cancel': _('button_cancel'),
+            'ok': _('button_ok'),
+            }
+
+    def guess_multiple(self, field, form):
+        if self.multiple is None:
+            eschema = form._cw.vreg.schema.eschema(form.edited_entity.__regid__)
+            rschema = eschema.schema.rschema(field.name)
+            rdef = eschema.rdef(rschema, field.role)
+            card = rdef.role_cardinality(field.role)
+            self.multiple = card in '*+'
+        self.multiple = int(self.multiple)
+
+    def _filter_rset(self, field, form):
+        """filter the rset to only get the root entities"""
+        vocab = field.vocabulary(form)
+        if vocab:
+            entities = [form._cw.entity_from_eid(i[1]) for i in vocab]
+            eids = ', '.join(str(e.eid) for e in entities
+                             if e.cw_adapt_to('ITree') and e.cw_adapt_to('ITree').is_root())
+            return form._cw.execute('Any X WHERE X eid IN (%(e)s)' % {'e':eids})
+        return None
+
+    def render_treeform(self, form, treerset, tree_uid, related):
+        return form._cw.view('treeview_edit',  treerset, subvid="oneline_edit",
+                             tree_uid=tree_uid,
+                             related=[k.eid for k in related],
+                             leavesonly=self.leavesonly,
+                             required=self.required,
+                             multiple=self.multiple,
+                             level=self.level)
+
+    def compute_related(self, form, field):
+        if not hasattr(form, 'edited_entity'):
+            return ()
+        # set initial values if exist
+        initial_values = self.values(form, field)
+        if initial_values:
+            related = form._cw.execute('Any K WHERE K eid IN (%(eid)s)' %
+                                       {'eid':','.join([str(v) for v in initial_values])})
+        else:
+            related = form.edited_entity.related(field.name, field.role)
+        if related:
+            return list(related.entities())
+        return ()
+
+    def render_selected(self, name, related):
+        if not related:
+            yield tags.input(id=name, name=name, value='', type='hidden')
+        for keyword in related:
+            input = tags.input(id=name, name=name, value=keyword.eid, type='hidden')
+            yield tags.div(u'<a href="javascript:$.noop()" onclick="$(this).parent().remove()">[x]</a>'
+                           u'%(input)s %(title)s' % {'input':input,
+                                                     'title': xml_escape(keyword.dc_title())})
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_treeview/views/treeview.py	Fri Jun 21 11:15:30 2019 +0200
@@ -0,0 +1,219 @@
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""Set of tree
+"""
+
+__docformat__ = "restructuredtext en"
+_ = unicode
+
+import json
+
+from logilab.mtconverter import xml_escape
+
+from cubicweb.predicates import is_instance, match_kwargs, adaptable
+from cubicweb.web.views import baseviews, treeview
+from cubicweb.uilib import cut
+
+class TVTreeViewItemView(treeview.TreeViewItemView):
+
+    def _is_leaf(self, itree):
+        return itree is None or itree.is_leaf()
+
+    def _children(self, itree):
+        return itree.children(entities=False)
+
+    def cell_call(self, row, col, treeid, vid='oneline',
+                  parentvid='treeview',
+                  is_last=False, **morekwargs):
+        w = self.w
+        entity = self.cw_rset.get_entity(row, col)
+        itree = entity.cw_adapt_to('ITree')
+        # XXX treeview customization : add css class
+        liclasses = [u'cw-%s' % entity.__regid__.lower()]
+        # XXX
+        is_open = self.open_state(entity.eid, treeid)
+        is_leaf = self._is_leaf(itree)
+        if is_leaf:
+            if is_last:
+                liclasses.append('last')
+            w(u'<li class="%s">' % u' '.join(liclasses))
+        else:
+            rql = itree.children_rql() % {'x': entity.eid}
+            url = xml_escape(self._cw.build_url('json', rql=rql, vid=parentvid,
+                                                pageid=self._cw.pageid,
+                                                treeid=treeid,
+                                                fname='view',
+                                                treesubvid=vid,
+                                                morekwargs=json.dumps(morekwargs)))
+            divclasses = ['hitarea']
+            if is_open:
+                liclasses.append('collapsable')
+                divclasses.append('collapsable-hitarea')
+            else:
+                liclasses.append('expandable')
+                divclasses.append('expandable-hitarea')
+            if is_last:
+                if is_open:
+                    liclasses.append('lastCollapsable')
+                    divclasses.append('lastCollapsable-hitarea')
+                else:
+                    liclasses.append('lastExpandable')
+                    divclasses.append('lastExpandable-hitarea')
+            if is_open:
+                w(u'<li class="%s">' % u' '.join(liclasses))
+            else:
+                w(u'<li cubicweb:loadurl="%s" class="%s">' % (url, u' '.join(liclasses)))
+            if treeid.startswith('throw_away'):
+                divtail = ''
+            else:
+                divtail = """ onclick="asyncRemoteExec('node_clicked', '%s', '%s')" """ % (
+                    treeid, entity.eid)
+            w(u'<div class="%s"%s></div>' % (u' '.join(divclasses), divtail))
+
+            # add empty <ul> because jquery's treeview plugin checks for
+            # sublists presence
+            if not is_open:
+                w(u'<ul class="placeholder"><li>place holder</li></ul>')
+        # the local node info
+        self.wview(vid, self.cw_rset, row=row, col=col, **morekwargs)
+        if is_open and not is_leaf: #  => rql is defined
+            self.wview(parentvid, self._children(itree), subvid=vid,
+                       treeid=treeid, initial_load=False, **morekwargs)
+        w(u'</li>')
+
+class TVDefaultTreeViewItemView(treeview.DefaultTreeViewItemView):
+
+    def cell_call(self, row, col, vid='oneline', treeid=None, **morekwargs):
+        assert treeid is not None
+        entity =  self.cw_rset.get_entity(row, col)
+        itemview = entity.view(vid, **morekwargs)
+        # treeview customization : add css classe
+        liclasses = [u'cw-%s' % entity.__regid__.lower()]
+        if morekwargs['is_last']:
+            liclasses.append('last')
+        self.w(u'<li class="%s">%s</li>' % ( u' '.join(liclasses), itemview))
+
+class TVTreeViewEditItemView(TVTreeViewItemView):
+    """keeps track of which branches to open according to the X rtype
+    Y value given to the TreeView
+    """
+    __regid__ = 'itemvid_edit'
+    __select__ = (treeview.TreeView.__select__ &
+                  (match_kwargs('related', 'required', 'multiple', 'leavesonly',
+                                'tree_uid', 'level')))
+    _open_branch_memo = None
+
+    def open_state(self, eeid, treeid):
+        return eeid in self._open_branch_memo
+
+    def cell_call(self, row, col, treeid, vid='oneline_edit', parentvid='treeview_edit',
+                  is_last=False, **morekwargs):
+        entity = self.cw_rset.get_entity(row, col)
+        self._open_branch_memo = set(entity.cw_adapt_to('ITree').path())
+        return super(TVTreeViewEditItemView, self).cell_call(row, col, treeid, vid=vid, parentvid=parentvid,
+                  is_last=is_last, **morekwargs)
+
+    def _is_leaf(self, itree):
+        return itree is None or itree.is_editable_leaf()
+
+    def _children(self, itree):
+        return itree.editable_children(entities=False)
+
+class TVTreeEditView(treeview.TreeView):
+    __regid__ = 'treeview_edit'
+    subvid = 'oneline_edit'
+    itemvid = 'itemvid_edit'
+    __select__ = (treeview.TreeView.__select__ &
+                  (match_kwargs('related', 'required', 'multiple', 'leavesonly',
+                                'tree_uid', 'level')) & adaptable('ITree'))
+
+    def _init_params(self, subvid, treeid, initial_load, initial_thru_ajax, morekwargs):
+        form = self._cw.form
+        initial_fname = form.get('fname', None)
+        if initial_fname == 'reledit_form':
+            form.pop('fname')
+        return super(TVTreeEditView, self)._init_params(subvid, treeid, initial_load, initial_thru_ajax, morekwargs)
+
+class TVNotTreeEditView(treeview.DefaultTreeViewItemView):
+    __regid__ = 'treeview_edit'
+    __select__ = ~adaptable('ITree')
+    itemvid = 'itemvid_edit'
+
+    def cell_call(self, row, col, vid='oneline', treeid=None, **morekwargs):
+        return u''
+
+class TVNotTreeviewOneLineEditView(baseviews.InContextView):
+    __regid__ = 'oneline_edit'
+    __select__ = ~adaptable('ITree')
+
+    def cell_call(self, row, col, tree_uid, multiple,
+                  leavesonly, related, required, level):
+        return u''
+
+class TVTreeviewOneLineEditView(baseviews.InContextView):
+    __regid__ = 'oneline_edit'
+    __select__ = adaptable('ITree')
+
+    def cell_call(self, row, col, tree_uid, multiple,
+                  leavesonly, related, required, level):
+        entity = self.cw_rset.get_entity(row,col)
+        entity_name =  xml_escape(entity.dc_title())
+        itree = entity.cw_adapt_to('ITree')
+        is_leaf = itree.is_editable_leaf()
+        entity_level = self.entity_level(itree)
+        if multiple:
+            if level and entity_level != level:
+                self.w(u'<span>%s</span>' % entity_name)
+            elif not leavesonly or is_leaf:
+                self.w(u'<input type="checkbox" name="selitems" value="%(eid)s" '
+                       u'%(sel)s id="treeitem_%(eid)s"/>&nbsp;' \
+                           % {'eid':entity.eid,'sel':entity.eid
+                              in related and u'checked="checked"' or u''})
+                self.w(u'<span class="hidden">%s</span>' % entity_name)
+                self.w(u'<a href="javascript:$.noop()" onclick="$(\'#treeitem_%s\').click()" class="selectable">'
+                       u'%s</a>' % (entity.eid, entity_name))
+            else:
+                self.w(u'<span>%s</span>' % (entity_name))
+        else:
+            cssclass = u"selected " if entity.eid in related else u""
+            if level and entity_level.level != level:
+                self.w(u'<span class="%s">%s</span>' % (cssclass, entity_name))
+            elif not leavesonly or is_leaf:
+                cssclass += u' selectable"'
+                onclick = u"cw.treewidget.validateRelated(this, %s, \'%s\', %s)" % (
+                    required, tree_uid, [[str(entity.eid)], []])
+                self.w(u'<a href="javascript:$.noop()" onclick="%s" class="%s" '
+                       % (onclick, cssclass))
+                description = entity.dc_description()
+                if description:
+                    description = cut(description, 50)
+                    self.w(u' title="%s"' % xml_escape(description))
+                self.w(u'>%s</a>' % entity_name)
+            else:
+                self.w(u'<span class="%s">%s</span>' % (cssclass, entity_name))
+
+    def entity_level(self, itree):
+        if hasattr(itree, 'level'):
+            return itree.level
+        return None
+
+def registration_callback(vreg):
+    vreg.register_all(globals().values(), __name__, (
+        TVTreeViewItemView,
+        TVDefaultTreeViewItemView,
+        ))
+    vreg.register_and_replace(TVTreeViewItemView, treeview.TreeViewItemView)
+    vreg.register_and_replace(TVDefaultTreeViewItemView, treeview.DefaultTreeViewItemView)
--- a/data/cubes.treeview.css	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-/* css for treeview widget */
-
-div.msg{
- color : red;
- margin: 1em 0;
-}
-.ui-dialog.ui-widget{
- background:#fff;
- }
-
-.ui-dialog ul.treeview {
- background-color: transparent;
-}
-
-.ui-dialog ul.treeview li a.selectable,
-.ui-dialog ul.treeview li a.selectable:hover{
- color:#E6820E;
-}
-
-.ui-dialog ul.treeview span,
-.ui-dialog ul.treeview span:hover{
- color:#666;
-}
-
-/* bootstrap compatibility */
-.cw-folder input[type='checkbox'] {
- margin: 0px;
- height:inherit; }
\ No newline at end of file
--- a/data/cubes.treeview.js	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-cw.treewidget = new Namespace('cw.treewidget');
-
-$.extend(cw.treewidget, {
-    validateCheckBox: function(tree_uid, required){
-        var related = [[],[]];
-        $('#holder_' + tree_uid + ' input:checked').each(function(){
-            related[0].push($(this).val());
-            related[1].push($(this).siblings('span[class="hidden"]').text());
-        });
-        cw.treewidget.validateRelated(null, required, tree_uid, related );
-    },
-
-    validateRelated: function(thisnode, required, tree_uid, related){
-        if (thisnode){
-            related[1].push($(thisnode).text());
-        }
-        if(required && related[0].length == 0){
-            cw.treewidget.updateTreeWidgetMessage(tree_uid, "please, select at least one value");
-            return;
-        }
-        var $holder = $('#sel_' + tree_uid);
-        var rname = tree_uid.replace('--', ':');
-        for(var i=0; i<related[0].length; i++){
-            var $div = $('<div />');
-            $div.append($('<input/>').attr({
-                id: rname, name: rname,
-                type: "hidden", value: related[0][i]}));
-            $div.append('<a href="javascript:$.noop()" onclick="$(this).parent().remove()">[x] </a>');
-            $div.append($('<span/>').html(related[1][i]));
-            $holder.append($div);
-        }
-        $holder.trigger('md.close');
-    },
-
-    updateTreeWidgetMessage: function(tree_uid, msg){
-       $('#' + tree_uid + ' div.error').empty().html(msg);
-    }
-});
-
-(function ($) {
-    var defaultSettings = {
-        modal: true,
-        width: 600,
-        height: 600,
-        cancelButton: 'button_cancel',
-        okButton: 'button_ok',
-        buttons: []
-    };
-
-    var methods = {
-        __init__: function(required, multiple, url, options) {
-            var tree_uid = $(this).attr('id');
-            var settings = methods.initSettings(tree_uid, required, multiple, options);
-            var dialog = $(this).dialog(settings);
-            if(url){
-                var d = $(this).loadxhtml(url);
-            };
-            var $holder = $('#sel_' + tree_uid);
-            $holder.bind("md.close", function() {
-                dialog.dialog('close');
-            });
-        },
-
-        initSettings: function(tree_uid, required, multiple, options) {
-            var settings = $.extend({}, defaultSettings, options);
-            if (!settings.buttons.length) {
-                if (multiple) {
-                    settings.buttons.push({id: "btn-validate",
-                                           text: settings.okButton,
-                                           click: function() {
-                                               cw.treewidget.validateCheckBox(tree_uid, required);
-                                           }});
-                }
-                settings.buttons.push({id: "btn-cancel", text: settings.cancelButton,
-                                       click: function() {
-                                           $(this).dialog("close");
-                                       }});
-            }
-            return settings;
-        }
-    };
-
-    $.fn.treewidget = function(required, multiple, url, options) {
-        return methods.__init__.apply(this, [required, multiple, url, options]);
-    };
-})(jQuery);
--- a/i18n/en.po	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-msgid ""
-msgstr ""
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Generated-By: pygettext.py 1.5\n"
-"Plural-Forms: nplurals=2; plural=(n > 1);\n"
-
-msgid "no available values"
-msgstr ""
-
-msgid "please, select at least one value"
-msgstr ""
-
-msgid "remove"
-msgstr ""
-
-msgid "select"
-msgstr ""
--- a/i18n/es.po	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-msgid ""
-msgstr ""
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Generated-By: pygettext.py 1.5\n"
-"Plural-Forms: nplurals=2; plural=(n > 1);\n"
-
-msgid "no available values"
-msgstr ""
-
-msgid "please, select at least one value"
-msgstr ""
-
-msgid "remove"
-msgstr ""
-
-msgid "select"
-msgstr ""
--- a/i18n/fr.po	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-msgid ""
-msgstr ""
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Generated-By: pygettext.py 1.5\n"
-"Plural-Forms: nplurals=2; plural=(n > 1);\n"
-
-msgid "no available values"
-msgstr "pas de données disponibles"
-
-msgid "please, select at least one value"
-msgstr "au moins une valeur doit être sélectionnée"
-
-msgid "remove"
-msgstr "supprimer"
-
-msgid "select"
-msgstr "sélectionner"
--- a/migration/postcreate.py	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-# -*- coding: utf-8 -*-
-# copyright 2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr -- mailto:contact@logilab.fr
-#
-# This program is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with this program. If not, see <http://www.gnu.org/licenses/>.
-
-"""cubicweb-treeview postcreate script, executed at instance creation time or when
-the cube is added to an existing instance.
-
-You could setup site properties or a workflow here for example.
-"""
-
-# Example of site property change
-#set_property('ui.site-title', "<sitename>")
-
--- a/setup.py	Fri Jun 21 11:09:18 2019 +0200
+++ b/setup.py	Fri Jun 21 11:15:30 2019 +0200
@@ -1,10 +1,10 @@
 #!/usr/bin/env python
 # pylint: disable=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
 #
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2019 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
-# This file is part of CubicWeb tag cube.
+# This file is part of cubicweb-treeview.
 #
 # CubicWeb is free software: you can redistribute it and/or modify it under the
 # terms of the GNU Lesser General Public License as published by the Free
@@ -16,186 +16,67 @@
 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 # details.
 #
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""Generic Setup script, takes package info from __pkginfo__.py file
+# You should have received a copy of the GNU Lesser General Public License
+# along with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""cubicweb_treeview setup module using data from
+cubicweb_treeview/__pkginfo__.py file
 """
-__docformat__ = "restructuredtext en"
-
-import os
-import sys
-import shutil
-from os.path import isdir, exists, join, walk
-
-try:
-    if os.environ.get('NO_SETUPTOOLS'):
-        raise ImportError() # do as there is no setuptools
-    from setuptools import setup
-    from setuptools.command import install_lib
-    USE_SETUPTOOLS = True
-except ImportError:
-    from distutils.core import setup
-    from distutils.command import install_lib
-    USE_SETUPTOOLS = False
-from distutils.command import install_data
 
-# import required features
-from __pkginfo__ import modname, version, license, description, web, \
-     author, author_email, classifiers
-
-if exists('README'):
-    long_description = file('README').read()
-else:
-    long_description = ''
+from os.path import join, dirname
 
-# import optional features
-import __pkginfo__
-if USE_SETUPTOOLS:
-    requires = {}
-    for entry in ("__depends__",): # "__recommends__"):
-        requires.update(getattr(__pkginfo__, entry, {}))
-    install_requires = [("%s %s" % (d, v and v or "")).strip()
-                       for d, v in requires.iteritems()]
-else:
-    install_requires = []
-
-distname = getattr(__pkginfo__, 'distname', modname)
-scripts = getattr(__pkginfo__, 'scripts', ())
-include_dirs = getattr(__pkginfo__, 'include_dirs', ())
-data_files = getattr(__pkginfo__, 'data_files', None)
-ext_modules = getattr(__pkginfo__, 'ext_modules', None)
-dependency_links = getattr(__pkginfo__, 'dependency_links', ())
-
-BASE_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build')
-IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
+from setuptools import find_packages, setup
 
 
-def ensure_scripts(linux_scripts):
-    """
-    Creates the proper script names required for each platform
-    (taken from 4Suite)
-    """
-    from distutils import util
-    if util.get_platform()[:3] == 'win':
-        scripts_ = [script + '.bat' for script in linux_scripts]
-    else:
-        scripts_ = linux_scripts
-    return scripts_
+here = dirname(__file__)
+
+# load metadata from the __pkginfo__.py file so there is no risk of conflict
+# see https://packaging.python.org/en/latest/single_source_version.html
+pkginfo = join(here, 'cubicweb_treeview', '__pkginfo__.py')
+__pkginfo__ = {}
+with open(pkginfo) as f:
+    exec(f.read(), __pkginfo__)
 
-def export(from_dir, to_dir,
-           blacklist=BASE_BLACKLIST,
-           ignore_ext=IGNORED_EXTENSIONS,
-           verbose=True):
-    """make a mirror of from_dir in to_dir, omitting directories and files
-    listed in the black list
-    """
-    def make_mirror(arg, directory, fnames):
-        """walk handler"""
-        for norecurs in blacklist:
-            try:
-                fnames.remove(norecurs)
-            except ValueError:
-                pass
-        for filename in fnames:
-            # don't include binary files
-            if filename[-4:] in ignore_ext:
-                continue
-            if filename[-1] == '~':
-                continue
-            src = join(directory, filename)
-            dest = to_dir + src[len(from_dir):]
-            if verbose:
-                sys.stderr.write('%s -> %s\n' % (src, dest))
-            if os.path.isdir(src):
-                if not exists(dest):
-                    os.mkdir(dest)
-            else:
-                if exists(dest):
-                    os.remove(dest)
-                shutil.copy2(src, dest)
-    try:
-        os.mkdir(to_dir)
-    except OSError as ex:
-        # file exists ?
-        import errno
-        if ex.errno != errno.EEXIST:
-            raise
-    walk(from_dir, make_mirror, None)
+# get required metadatas
+distname = __pkginfo__['distname']
+version = __pkginfo__['version']
+license = __pkginfo__['license']
+description = __pkginfo__['description']
+web = __pkginfo__['web']
+author = __pkginfo__['author']
+author_email = __pkginfo__['author_email']
+classifiers = __pkginfo__['classifiers']
+
+with open(join(here, 'README')) as f:
+    long_description = f.read()
+
+# get optional metadatas
+data_files = __pkginfo__.get('data_files', None)
+dependency_links = __pkginfo__.get('dependency_links', ())
+
+requires = {}
+for entry in ("__depends__",):  # "__recommends__"):
+    requires.update(__pkginfo__.get(entry, {}))
+install_requires = ["{0} {1}".format(d, v and v or "").strip()
+                    for d, v in requires.items()]
 
 
-class MyInstallLib(install_lib.install_lib):
-    """extend install_lib command to handle  package __init__.py and
-    include_dirs variable if necessary
-    """
-    def run(self):
-        """overridden from install_lib class"""
-        install_lib.install_lib.run(self)
-        # manually install included directories if any
-        if include_dirs:
-            base = modname
-            for directory in include_dirs:
-                dest = join(self.install_dir, base, directory)
-                export(directory, dest, verbose=False)
-
-# re-enable copying data files in sys.prefix
-old_install_data = install_data.install_data
-if USE_SETUPTOOLS:
-    # overwrite InstallData to use sys.prefix instead of the egg directory
-    class MyInstallData(old_install_data):
-        """A class that manages data files installation"""
-        def run(self):
-            _old_install_dir = self.install_dir
-            if self.install_dir.endswith('egg'):
-                self.install_dir = sys.prefix
-            old_install_data.run(self)
-            self.install_dir = _old_install_dir
-    try:
-        import setuptools.command.easy_install # only if easy_install avaible
-        # monkey patch: Crack SandboxViolation verification
-        from setuptools.sandbox import DirectorySandbox as DS
-        old_ok = DS._ok
-        def _ok(self, path):
-            """Return True if ``path`` can be written during installation."""
-            out = old_ok(self, path) # here for side effect from setuptools
-            realpath = os.path.normcase(os.path.realpath(path))
-            allowed_path = os.path.normcase(sys.prefix)
-            if realpath.startswith(allowed_path):
-                out = True
-            return out
-        DS._ok = _ok
-    except ImportError:
-        pass
-
-def install(**kwargs):
-    """setup entry point"""
-    if USE_SETUPTOOLS:
-        if '--force-manifest' in sys.argv:
-            sys.argv.remove('--force-manifest')
-    # install-layout option was introduced in 2.5.3-1~exp1
-    elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv:
-        sys.argv.remove('--install-layout=deb')
-    cmdclass = {'install_lib': MyInstallLib}
-    if USE_SETUPTOOLS:
-        kwargs['install_requires'] = install_requires
-        kwargs['dependency_links'] = dependency_links
-        kwargs['zip_safe'] = False
-        cmdclass['install_data'] = MyInstallData
-
-    return setup(name = distname,
-                 version = version,
-                 license = license,
-                 description = description,
-                 long_description = long_description,
-                 author = author,
-                 author_email = author_email,
-                 url = web,
-                 scripts = ensure_scripts(scripts),
-                 data_files = data_files,
-                 ext_modules = ext_modules,
-                 cmdclass = cmdclass,
-                 classifiers = classifiers,
-                 **kwargs
-                 )
-
-if __name__ == '__main__' :
-    install()
+setup(
+    name=distname,
+    version=version,
+    license=license,
+    description=description,
+    long_description=long_description,
+    author=author,
+    author_email=author_email,
+    url=web,
+    classifiers=classifiers,
+    packages=find_packages(exclude=['test']),
+    install_requires=install_requires,
+    include_package_data=True,
+    entry_points={
+        'cubicweb.cubes': [
+            'treeview=cubicweb_treeview',
+        ],
+    },
+    zip_safe=False,
+)
--- a/test/test_treeview.py	Fri Jun 21 11:09:18 2019 +0200
+++ b/test/test_treeview.py	Fri Jun 21 11:15:30 2019 +0200
@@ -23,5 +23,5 @@
     '''
 
 if __name__ == '__main__':
-    from logilab.common.testlib import unittest_main
-    unittest_main()
+    import unittest
+    unittest.main()
--- a/tox.ini	Fri Jun 21 11:09:18 2019 +0200
+++ b/tox.ini	Fri Jun 21 11:15:30 2019 +0200
@@ -1,33 +1,20 @@
 [tox]
-envlist = py27,flake8
-
-[tox:jenkins]
-envlist = py27,flake8-jenkins
+envlist = py27,py3,flake8
 
 [testenv]
-sitepackages = true
 deps =
   pytest
 commands =
   {envpython} -m pytest {posargs:test}
 
 [testenv:flake8]
+basepython = python3
 skip_install = true
-whitelist_externals =
-  flake8
 deps =
   flake8
 commands = flake8
-[testenv:flake8-jenkins]
-skip_install = true
-whitelist_externals =
-  flake8
-deps =
-  flake8
-commands = flake8 --exit-zero --show-source --output-file=code_quality.log {toxinidir}
 
 [flake8]
-format = pylint
 max-line-length = 100
 ignore = E731,W503
-exclude = __pkginfo__.py,migration/*,test/data/*,setup.py,.tox/*
+exclude = cubicweb_treeview/migration/*,test/data/*,.tox/*
--- a/views/formwidgets.py	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""Set of tree-building widgets, some based on jQuery treeview
-plugin.
-"""
-
-__docformat__ = "restructuredtext en"
-_ = unicode
-
-from logilab.mtconverter import xml_escape
-
-from cubicweb import tags
-from cubicweb.web import formwidgets as fwdgs
-
-class TreeViewWidget(fwdgs.FieldWidget):
-    """form widget to link to keywords of a given classification"""
-
-    subvid = 'oneline_edit'
-
-    needs_js = ('cubicweb.ajax.js', 'cubicweb.widgets.js',
-                'jquery.treeview.js', 'jquery.ui.js', 'cubes.treeview.js')
-    needs_css = ('jquery.treeview.css', 'jquery.ui.css', 'cubes.treeview.css')
-
-    html = (u'''<a href="javascript:$.noop()" '''
-            u'''onclick="$('#%(tree_uid)s').treewidget(%(required)s, %(multiple)s, false, {'cancelButton': '%(cancel)s', 'okButton': '%(ok)s'}) ;return false;">'''
-            u'''%(open_link)s&nbsp;%(remove_link)s</a>'''
-            u'''<div id="sel_%(tree_uid)s">%(selected)s</div>'''
-            u'''<div id="%(tree_uid)s" style="display: none;">'''
-            u'''<div class="error"></div><div id="holder_%(tree_uid)s">%(form)s</div></div>''') #'
-
-    remove_link_html = u'''<a href="javascript:$.noop()" cubicweb:link="%s" class="remove_link"
-    onclick="$('#sel_%s').empty()">[%s]</a>'''
-
-    def __init__(self, leavesonly=False,
-                 multiple=None, level=None, **kwargs):
-        """
-        :param leavesonly: True if only leaves can be selected
-        :param multiple: True if more than one value can be selected. If this parameter is set,
-                         the rtype's cardinality is ignored
-        :param level: only select values on the given tree level
-        """
-        super(TreeViewWidget, self).__init__(**kwargs)
-        self.leavesonly = int(leavesonly)
-        self.multiple = multiple
-        self.level = level
-
-    def _render(self, form, field, renderer):
-        _ = form._cw._
-        treerset = self._filter_rset(field, form)
-        if not treerset:
-            return _(u"no available values")
-        self.required = int(field.required)
-        self.guess_multiple(field, form)
-        tree_uid = field.input_name(form, self.suffix).replace(':', '--')
-        related = self.compute_related(form, field)
-        treeform = self.render_treeform(form, treerset, tree_uid, related)
-        remove_link = self.remove_link_html % (field.name, tree_uid, _('remove'))
-        return self.html % {
-            'required': self.required,
-            'multiple': self.multiple,
-            'selected': u'\n'.join(self.render_selected(field.input_name(form, self.suffix), related)),
-            'tree_uid': tree_uid, 'form': treeform,
-            'open_link': xml_escape(_('select').capitalize()),
-            'remove_link': remove_link,
-            'cancel': _('button_cancel'),
-            'ok': _('button_ok'),
-            }
-
-    def guess_multiple(self, field, form):
-        if self.multiple is None:
-            eschema = form._cw.vreg.schema.eschema(form.edited_entity.__regid__)
-            rschema = eschema.schema.rschema(field.name)
-            rdef = eschema.rdef(rschema, field.role)
-            card = rdef.role_cardinality(field.role)
-            self.multiple = card in '*+'
-        self.multiple = int(self.multiple)
-
-    def _filter_rset(self, field, form):
-        """filter the rset to only get the root entities"""
-        vocab = field.vocabulary(form)
-        if vocab:
-            entities = [form._cw.entity_from_eid(i[1]) for i in vocab]
-            eids = ', '.join(str(e.eid) for e in entities
-                             if e.cw_adapt_to('ITree') and e.cw_adapt_to('ITree').is_root())
-            return form._cw.execute('Any X WHERE X eid IN (%(e)s)' % {'e':eids})
-        return None
-
-    def render_treeform(self, form, treerset, tree_uid, related):
-        return form._cw.view('treeview_edit',  treerset, subvid="oneline_edit",
-                             tree_uid=tree_uid,
-                             related=[k.eid for k in related],
-                             leavesonly=self.leavesonly,
-                             required=self.required,
-                             multiple=self.multiple,
-                             level=self.level)
-
-    def compute_related(self, form, field):
-        if not hasattr(form, 'edited_entity'):
-            return ()
-        # set initial values if exist
-        initial_values = self.values(form, field)
-        if initial_values:
-            related = form._cw.execute('Any K WHERE K eid IN (%(eid)s)' %
-                                       {'eid':','.join([str(v) for v in initial_values])})
-        else:
-            related = form.edited_entity.related(field.name, field.role)
-        if related:
-            return list(related.entities())
-        return ()
-
-    def render_selected(self, name, related):
-        if not related:
-            yield tags.input(id=name, name=name, value='', type='hidden')
-        for keyword in related:
-            input = tags.input(id=name, name=name, value=keyword.eid, type='hidden')
-            yield tags.div(u'<a href="javascript:$.noop()" onclick="$(this).parent().remove()">[x]</a>'
-                           u'%(input)s %(title)s' % {'input':input,
-                                                     'title': xml_escape(keyword.dc_title())})
--- a/views/treeview.py	Fri Jun 21 11:09:18 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,219 +0,0 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""Set of tree
-"""
-
-__docformat__ = "restructuredtext en"
-_ = unicode
-
-import json
-
-from logilab.mtconverter import xml_escape
-
-from cubicweb.predicates import is_instance, match_kwargs, adaptable
-from cubicweb.web.views import baseviews, treeview
-from cubicweb.uilib import cut
-
-class TVTreeViewItemView(treeview.TreeViewItemView):
-
-    def _is_leaf(self, itree):
-        return itree is None or itree.is_leaf()
-
-    def _children(self, itree):
-        return itree.children(entities=False)
-
-    def cell_call(self, row, col, treeid, vid='oneline',
-                  parentvid='treeview',
-                  is_last=False, **morekwargs):
-        w = self.w
-        entity = self.cw_rset.get_entity(row, col)
-        itree = entity.cw_adapt_to('ITree')
-        # XXX treeview customization : add css class
-        liclasses = [u'cw-%s' % entity.__regid__.lower()]
-        # XXX
-        is_open = self.open_state(entity.eid, treeid)
-        is_leaf = self._is_leaf(itree)
-        if is_leaf:
-            if is_last:
-                liclasses.append('last')
-            w(u'<li class="%s">' % u' '.join(liclasses))
-        else:
-            rql = itree.children_rql() % {'x': entity.eid}
-            url = xml_escape(self._cw.build_url('json', rql=rql, vid=parentvid,
-                                                pageid=self._cw.pageid,
-                                                treeid=treeid,
-                                                fname='view',
-                                                treesubvid=vid,
-                                                morekwargs=json.dumps(morekwargs)))
-            divclasses = ['hitarea']
-            if is_open:
-                liclasses.append('collapsable')
-                divclasses.append('collapsable-hitarea')
-            else:
-                liclasses.append('expandable')
-                divclasses.append('expandable-hitarea')
-            if is_last:
-                if is_open:
-                    liclasses.append('lastCollapsable')
-                    divclasses.append('lastCollapsable-hitarea')
-                else:
-                    liclasses.append('lastExpandable')
-                    divclasses.append('lastExpandable-hitarea')
-            if is_open:
-                w(u'<li class="%s">' % u' '.join(liclasses))
-            else:
-                w(u'<li cubicweb:loadurl="%s" class="%s">' % (url, u' '.join(liclasses)))
-            if treeid.startswith('throw_away'):
-                divtail = ''
-            else:
-                divtail = """ onclick="asyncRemoteExec('node_clicked', '%s', '%s')" """ % (
-                    treeid, entity.eid)
-            w(u'<div class="%s"%s></div>' % (u' '.join(divclasses), divtail))
-
-            # add empty <ul> because jquery's treeview plugin checks for
-            # sublists presence
-            if not is_open:
-                w(u'<ul class="placeholder"><li>place holder</li></ul>')
-        # the local node info
-        self.wview(vid, self.cw_rset, row=row, col=col, **morekwargs)
-        if is_open and not is_leaf: #  => rql is defined
-            self.wview(parentvid, self._children(itree), subvid=vid,
-                       treeid=treeid, initial_load=False, **morekwargs)
-        w(u'</li>')
-
-class TVDefaultTreeViewItemView(treeview.DefaultTreeViewItemView):
-
-    def cell_call(self, row, col, vid='oneline', treeid=None, **morekwargs):
-        assert treeid is not None
-        entity =  self.cw_rset.get_entity(row, col)
-        itemview = entity.view(vid, **morekwargs)
-        # treeview customization : add css classe
-        liclasses = [u'cw-%s' % entity.__regid__.lower()]
-        if morekwargs['is_last']:
-            liclasses.append('last')
-        self.w(u'<li class="%s">%s</li>' % ( u' '.join(liclasses), itemview))
-
-class TVTreeViewEditItemView(TVTreeViewItemView):
-    """keeps track of which branches to open according to the X rtype
-    Y value given to the TreeView
-    """
-    __regid__ = 'itemvid_edit'
-    __select__ = (treeview.TreeView.__select__ &
-                  (match_kwargs('related', 'required', 'multiple', 'leavesonly',
-                                'tree_uid', 'level')))
-    _open_branch_memo = None
-
-    def open_state(self, eeid, treeid):
-        return eeid in self._open_branch_memo
-
-    def cell_call(self, row, col, treeid, vid='oneline_edit', parentvid='treeview_edit',
-                  is_last=False, **morekwargs):
-        entity = self.cw_rset.get_entity(row, col)
-        self._open_branch_memo = set(entity.cw_adapt_to('ITree').path())
-        return super(TVTreeViewEditItemView, self).cell_call(row, col, treeid, vid=vid, parentvid=parentvid,
-                  is_last=is_last, **morekwargs)
-
-    def _is_leaf(self, itree):
-        return itree is None or itree.is_editable_leaf()
-
-    def _children(self, itree):
-        return itree.editable_children(entities=False)
-
-class TVTreeEditView(treeview.TreeView):
-    __regid__ = 'treeview_edit'
-    subvid = 'oneline_edit'
-    itemvid = 'itemvid_edit'
-    __select__ = (treeview.TreeView.__select__ &
-                  (match_kwargs('related', 'required', 'multiple', 'leavesonly',
-                                'tree_uid', 'level')) & adaptable('ITree'))
-
-    def _init_params(self, subvid, treeid, initial_load, initial_thru_ajax, morekwargs):
-        form = self._cw.form
-        initial_fname = form.get('fname', None)
-        if initial_fname == 'reledit_form':
-            form.pop('fname')
-        return super(TVTreeEditView, self)._init_params(subvid, treeid, initial_load, initial_thru_ajax, morekwargs)
-
-class TVNotTreeEditView(treeview.DefaultTreeViewItemView):
-    __regid__ = 'treeview_edit'
-    __select__ = ~adaptable('ITree')
-    itemvid = 'itemvid_edit'
-
-    def cell_call(self, row, col, vid='oneline', treeid=None, **morekwargs):
-        return u''
-
-class TVNotTreeviewOneLineEditView(baseviews.InContextView):
-    __regid__ = 'oneline_edit'
-    __select__ = ~adaptable('ITree')
-
-    def cell_call(self, row, col, tree_uid, multiple,
-                  leavesonly, related, required, level):
-        return u''
-
-class TVTreeviewOneLineEditView(baseviews.InContextView):
-    __regid__ = 'oneline_edit'
-    __select__ = adaptable('ITree')
-
-    def cell_call(self, row, col, tree_uid, multiple,
-                  leavesonly, related, required, level):
-        entity = self.cw_rset.get_entity(row,col)
-        entity_name =  xml_escape(entity.dc_title())
-        itree = entity.cw_adapt_to('ITree')
-        is_leaf = itree.is_editable_leaf()
-        entity_level = self.entity_level(itree)
-        if multiple:
-            if level and entity_level != level:
-                self.w(u'<span>%s</span>' % entity_name)
-            elif not leavesonly or is_leaf:
-                self.w(u'<input type="checkbox" name="selitems" value="%(eid)s" '
-                       u'%(sel)s id="treeitem_%(eid)s"/>&nbsp;' \
-                           % {'eid':entity.eid,'sel':entity.eid
-                              in related and u'checked="checked"' or u''})
-                self.w(u'<span class="hidden">%s</span>' % entity_name)
-                self.w(u'<a href="javascript:$.noop()" onclick="$(\'#treeitem_%s\').click()" class="selectable">'
-                       u'%s</a>' % (entity.eid, entity_name))
-            else:
-                self.w(u'<span>%s</span>' % (entity_name))
-        else:
-            cssclass = u"selected " if entity.eid in related else u""
-            if level and entity_level.level != level:
-                self.w(u'<span class="%s">%s</span>' % (cssclass, entity_name))
-            elif not leavesonly or is_leaf:
-                cssclass += u' selectable"'
-                onclick = u"cw.treewidget.validateRelated(this, %s, \'%s\', %s)" % (
-                    required, tree_uid, [[str(entity.eid)], []])
-                self.w(u'<a href="javascript:$.noop()" onclick="%s" class="%s" '
-                       % (onclick, cssclass))
-                description = entity.dc_description()
-                if description:
-                    description = cut(description, 50)
-                    self.w(u' title="%s"' % xml_escape(description))
-                self.w(u'>%s</a>' % entity_name)
-            else:
-                self.w(u'<span class="%s">%s</span>' % (cssclass, entity_name))
-
-    def entity_level(self, itree):
-        if hasattr(itree, 'level'):
-            return itree.level
-        return None
-
-def registration_callback(vreg):
-    vreg.register_all(globals().values(), __name__, (
-        TVTreeViewItemView,
-        TVDefaultTreeViewItemView,
-        ))
-    vreg.register_and_replace(TVTreeViewItemView, treeview.TreeViewItemView)
-    vreg.register_and_replace(TVDefaultTreeViewItemView, treeview.DefaultTreeViewItemView)