[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid treeview-tabs
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 03 Mar 2009 14:54:31 +0100
branchtreeview-tabs
changeset 998 9c6ce9d6384f
parent 997 ee71c2ba73e6
child 999 999198995a53
child 2026 74edd1b34c52
[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid
web/views/treeview.py
--- a/web/views/treeview.py	Tue Mar 03 12:57:25 2009 +0100
+++ b/web/views/treeview.py	Tue Mar 03 14:54:31 2009 +0100
@@ -5,6 +5,7 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 __docformat__ = "restructuredtext en"
+import uuid
 
 from logilab.mtconverter import html_escape
 from cubicweb.interfaces import ITree
@@ -22,13 +23,17 @@
     title = _('tree view')
 
     def call(self, subvid=None, treeid=None, initial_load=True):
-        if subvid is None and 'subvid' in self.req.form:
-            subvid = self.req.form.pop('subvid') # consume it
         if subvid is None:
-            subvid = 'oneline'
-        if treeid is None and 'treeid' in self.req.form:
-            treeid = self.req.form.pop('treeid')
-        assert treeid is not None
+            if 'subvid' in self.req.form:
+                subvid = self.req.form.pop('subvid') # consume it
+            else:
+                subvid = 'oneline'
+        if treeid is None:
+            if 'treeid' in self.req.form:
+                treeid = self.req.form.pop('treeid')
+            else:
+                treeid = uuid.uuid1().hex
+                self.warning('Tree state won\'t be properly restored after next reload')
         if initial_load:
             self.req.add_css('jquery.treeview.css')
             self.req.add_js(('cubicweb.ajax.js', 'jquery.treeview.js'))