[widget] truncate long descriptions as they break the tree.
authorKatia Saurfelt <katia.saurfelt@logilab.fr>
Fri, 07 Nov 2014 14:18:04 +0100
changeset 24 23292468ea66
parent 19 ed3158c7417d
child 25 01b1035fe314
[widget] truncate long descriptions as they break the tree. Use `dc_descripion`. closes #4616294
views/treeview.py
--- a/views/treeview.py	Wed Apr 16 10:52:33 2014 +0200
+++ b/views/treeview.py	Fri Nov 07 14:18:04 2014 +0100
@@ -23,6 +23,7 @@
 
 from cubicweb.predicates import is_instance, match_kwargs, adaptable
 from cubicweb.web.views import baseviews, treeview
+from cubicweb.uilib import cut
 
 import simplejson as json
 
@@ -192,13 +193,14 @@
                 self.w(u'<span class="%s">%s</span>' % (cssclass, entity_name))
             elif not leavesonly or is_leaf:
                 cssclass += u' selectable"'
-                description = getattr(entity, 'description', None)
                 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:
-                    self.w(u' title="%s"' % 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))