web/views/treeview.py
changeset 4436 294e084f1263
parent 4252 6c4f109c2b03
parent 4411 d0bde029f625
child 4459 f628abfb3a6c
equal deleted inserted replaced
4434:101344a6ff9b 4436:294e084f1263
    57         ulid = ' '
    57         ulid = ' '
    58         if toplevel:
    58         if toplevel:
    59             self._init_headers(treeid, toplevel_thru_ajax)
    59             self._init_headers(treeid, toplevel_thru_ajax)
    60             ulid = ' id="tree-%s"' % treeid
    60             ulid = ' id="tree-%s"' % treeid
    61         self.w(u'<ul%s class="%s">' % (ulid, self.css_classes))
    61         self.w(u'<ul%s class="%s">' % (ulid, self.css_classes))
    62         for rowidx in xrange(len(self.cw_rset)):
    62         for i, entity in enumerate(sorted(self.cw_rset.entities(),
    63             self.wview(self.itemvid, self.cw_rset, row=rowidx, col=0,
    63                                           key=lambda x: x.dc_title())):
    64                        vid=subvid, parentvid=self.__regid__, treeid=treeid, **morekwargs)
    64             if i+1 < len(self.cw_rset):
       
    65                 morekwargs['is_last'] = False
       
    66             else:
       
    67                 morekwargs['is_last'] = True
       
    68             entity.view(self.itemvid, vid=subvid, parentvid=self.__regid__,
       
    69                         treeid=treeid, w=self.w, **morekwargs)
    65         self.w(u'</ul>')
    70         self.w(u'</ul>')
    66 
    71 
    67     def cell_call(self, *args, **allargs):
    72     def cell_call(self, *args, **allargs):
    68         """ does not makes much sense until you have to invoke
    73         """ does not makes much sense until you have to invoke
    69         somentity.view('treeview') """
    74         somentity.view('treeview') """
    70         allargs.pop('row')
    75         allargs.pop('row')
    71         allargs.pop('col')
    76         allargs.pop('col')
    72         self.call(*args, **allargs)
    77         self.call(*args, **allargs)
       
    78 
    73 
    79 
    74 class FileTreeView(TreeView):
    80 class FileTreeView(TreeView):
    75     """specific version of the treeview to display file trees
    81     """specific version of the treeview to display file trees
    76     """
    82     """
    77     __regid__ = 'filetree'
    83     __regid__ = 'filetree'
   101 
   107 
   102 class DefaultTreeViewItemView(EntityView):
   108 class DefaultTreeViewItemView(EntityView):
   103     """default treeitem view for entities which don't implement ITree"""
   109     """default treeitem view for entities which don't implement ITree"""
   104     __regid__ = 'treeitemview'
   110     __regid__ = 'treeitemview'
   105 
   111 
   106     def cell_call(self, row, col, vid='oneline', parentvid='treeview', treeid=None):
   112     def cell_call(self, row, col, vid='oneline', treeid=None, **morekwargs):
   107         assert treeid is not None
   113         assert treeid is not None
   108         entity = self.cw_rset.get_entity(row, col)
   114         entity = self.cw_rset.get_entity(row, col)
   109         itemview = self._cw.view(vid, self.cw_rset, row=row, col=col)
   115         itemview = self._cw.view(vid, self.cw_rset, row=row, col=col)
   110         if row == len(self.cw_rset) - 1:
   116         if row == len(self.cw_rset) - 1:
   111             self.w(u'<li class="last">%s</li>' % itemview)
   117             self.w(u'<li class="last">%s</li>' % itemview)
   127         treestate = cookies.get(treecookiename(treeid))
   133         treestate = cookies.get(treecookiename(treeid))
   128         if treestate:
   134         if treestate:
   129             return str(eeid) in treestate.value.split(';')
   135             return str(eeid) in treestate.value.split(';')
   130         return self.default_branch_state_is_open
   136         return self.default_branch_state_is_open
   131 
   137 
   132     def cell_call(self, row, col, treeid, vid='oneline', parentvid='treeview', **morekwargs):
   138     def cell_call(self, row, col, treeid, vid='oneline', parentvid='treeview',
       
   139                   is_last=False, **morekwargs):
   133         w = self.w
   140         w = self.w
   134         entity = self.cw_rset.get_entity(row, col)
   141         entity = self.cw_rset.get_entity(row, col)
   135         liclasses = []
   142         liclasses = []
   136         is_last = row == len(self.cw_rset) - 1
       
   137         is_open = self.open_state(entity.eid, treeid)
   143         is_open = self.open_state(entity.eid, treeid)
   138         is_leaf = not hasattr(entity, 'is_leaf') or entity.is_leaf()
   144         is_leaf = not hasattr(entity, 'is_leaf') or entity.is_leaf()
   139         if is_leaf:
   145         if is_leaf:
   140             if is_last:
   146             if is_last:
   141                 liclasses.append('last')
   147                 liclasses.append('last')