[treeview] ensure items are ordered according to their dc_title, we can't rely on an ordered rset stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 29 Jan 2010 16:53:52 +0100
branchstable
changeset 4407 e4f921a68703
parent 4406 b3f61c38526b
child 4408 899b426087ab
[treeview] ensure items are ordered according to their dc_title, we can't rely on an ordered rset * is_last has to be computed on the caller now, not possible in the callee * rely on b3f61c38526b to use entity.view() with vid in *view*'s arguments
web/views/treeview.py
--- a/web/views/treeview.py	Fri Jan 29 16:45:18 2010 +0100
+++ b/web/views/treeview.py	Fri Jan 29 16:53:52 2010 +0100
@@ -59,9 +59,13 @@
             self._init_headers(treeid, toplevel_thru_ajax)
             ulid = ' id="tree-%s"' % treeid
         self.w(u'<ul%s class="%s">' % (ulid, self.css_classes))
-        for rowidx in xrange(len(self.rset)):
-            self.wview(self.itemvid, self.rset, row=rowidx, col=0,
-                       vid=subvid, parentvid=self.id, treeid=treeid, **morekwargs)
+        for i, entity in enumerate(sorted(self.rset.entities(), key=lambda x: x.dc_title())):
+            if i+1 < len(self.rset):
+                morekwargs['is_last'] = False
+            else:
+                morekwargs['is_last'] = True
+            entity.view(self.itemvid, vid=subvid, parentvid=self.id,
+                        treeid=treeid, w=self.w, **morekwargs)
         self.w(u'</ul>')
 
     def cell_call(self, *args, **allargs):
@@ -71,6 +75,7 @@
         allargs.pop('col')
         self.call(*args, **allargs)
 
+
 class FileTreeView(TreeView):
     """specific version of the treeview to display file trees
     """
@@ -129,11 +134,11 @@
             return str(eeid) in treestate.value.split(';')
         return self.default_branch_state_is_open
 
-    def cell_call(self, row, col, treeid, vid='oneline', parentvid='treeview', **morekwargs):
+    def cell_call(self, row, col, treeid, vid='oneline', parentvid='treeview',
+                  is_last=False, **morekwargs):
         w = self.w
         entity = self.entity(row, col)
         liclasses = []
-        is_last = row == len(self.rset) - 1
         is_open = self.open_state(entity.eid, treeid)
         is_leaf = not hasattr(entity, 'is_leaf') or entity.is_leaf()
         if is_leaf: