web/views/tableview.py
changeset 3451 6b46d73823f5
parent 3377 dd9d292b6a6d
child 3457 0924d0d08d60
--- a/web/views/tableview.py	Wed Sep 23 19:26:38 2009 +0200
+++ b/web/views/tableview.py	Wed Sep 23 19:40:19 2009 +0200
@@ -28,14 +28,14 @@
 
     def form_filter(self, divid, displaycols, displayactions, displayfilter,
                     hidden=True):
-        rqlst = self.rset.syntax_tree()
+        rqlst = self.cw_rset.syntax_tree()
         # union not yet supported
         if len(rqlst.children) != 1:
             return ()
         rqlst.save_state()
-        mainvar, baserql = prepare_facets_rqlst(rqlst, self.rset.args)
-        wdgs = [facet.get_widget() for facet in self.vreg['facets'].poss_visible_objects(
-            self.req, rset=self.rset, context='tablefilter',
+        mainvar, baserql = prepare_facets_rqlst(rqlst, self.cw_rset.args)
+        wdgs = [facet.get_widget() for facet in self._cw.vreg['facets'].poss_visible_objects(
+            self._cw, rset=self.cw_rset, context='tablefilter',
             filtered_variable=mainvar)]
         wdgs = [wdg for wdg in wdgs if wdg is not None]
         rqlst.recover()
@@ -51,8 +51,8 @@
         """display a form to filter table's content. This should only
         occurs when a context eid is given
         """
-        self.req.add_css('cubicweb.facets.css')
-        self.req.add_js( ('cubicweb.ajax.js', 'cubicweb.facets.js'))
+        self._cw.add_css('cubicweb.facets.css')
+        self._cw.add_js( ('cubicweb.ajax.js', 'cubicweb.facets.js'))
         # drop False / None values from vidargs
         vidargs = dict((k, v) for k, v in vidargs.iteritems() if v)
         self.w(u'<form method="post" cubicweb:facetargs="%s" action="">' %
@@ -77,8 +77,8 @@
         """returns the index of the first non-attribute variable among the RQL
         selected variables
         """
-        eschema = self.vreg.schema.eschema
-        for i, etype in enumerate(self.rset.description[0]):
+        eschema = self._cw.vreg.schema.eschema
+        for i, etype in enumerate(self.cw_rset.description[0]):
             try:
                 if not eschema(etype).is_final():
                     return i
@@ -88,10 +88,10 @@
 
     def displaycols(self, displaycols):
         if displaycols is None:
-            if 'displaycols' in self.req.form:
-                displaycols = [int(idx) for idx in self.req.form['displaycols']]
+            if 'displaycols' in self._cw.form:
+                displaycols = [int(idx) for idx in self._cw.form['displaycols']]
             else:
-                displaycols = range(len(self.rset.syntax_tree().children[0].selection))
+                displaycols = range(len(self.cw_rset.syntax_tree().children[0].selection))
         return displaycols
 
     def call(self, title=None, subvid=None, displayfilter=None, headers=None,
@@ -104,7 +104,7 @@
         :param displayfilter: filter that selects rows to display
         :param headers: columns' titles
         """
-        req = self.req
+        req = self._cw
         req.add_js('jquery.tablesorter.js')
         req.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css'))
         # compute label first  since the filter form may remove some necessary
@@ -115,7 +115,7 @@
         hidden = True
         if not subvid and 'subvid' in req.form:
             subvid = req.form.pop('subvid')
-        divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.rset))
+        divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.cw_rset))
         actions = list(actions)
         if mainindex is None:
             displayfilter, displayactions = False, False
@@ -144,7 +144,7 @@
             actions += self.show_hide_actions(divid, True)
         self.w(u'<div id="%s"' % divid)
         if displayactions:
-            actionsbycat = self.vreg['actions'].possible_actions(req, self.rset)
+            actionsbycat = self._cw.vreg['actions'].possible_actions(req, self.cw_rset)
             for action in actionsbycat.get('mainactions', ()):
                 for action in action.actual_actions():
                     actions.append( (action.url(), req._(action.title),
@@ -170,8 +170,8 @@
         showhide = u';'.join(toggle_action('%s%s' % (divid, what))[11:]
                              for what in ('Form', 'Show', 'Hide', 'Actions'))
         showhide = 'javascript:' + showhide
-        showlabel = self.req._('show filter form')
-        hidelabel = self.req._('hide filter form')
+        showlabel = self._cw._('show filter form')
+        hidelabel = self._cw._('hide filter form')
         if currentlydisplayed:
             return [(showhide, showlabel, 'hidden', '%sShow' % divid),
                     (showhide, hidelabel, None, '%sHide' % divid)]
@@ -181,8 +181,8 @@
     def render_actions(self, divid, actions):
         box = MenuWidget('', 'tableActionsBox', _class='', islist=False)
         label = '<img src="%s" alt="%s"/>' % (
-            self.req.datadir_url + 'liveclipboard-icon.png',
-            xml_escape(self.req._('action(s) on this selection')))
+            self._cw.datadir_url + 'liveclipboard-icon.png',
+            xml_escape(self._cw._('action(s) on this selection')))
         menu = PopupBoxMenu(label, isitem=False, link_class='actionsBox',
                             ident='%sActions' % divid)
         box.append(menu)
@@ -201,14 +201,14 @@
             if headers is not None:
                 label = headers[displaycols.index(colindex)]
             if colindex == mainindex:
-                label += ' (%s)' % self.rset.rowcount
+                label += ' (%s)' % self.cw_rset.rowcount
             column = TableColumn(label, colindex)
-            coltype = self.rset.description[0][colindex]
+            coltype = self.cw_rset.description[0][colindex]
             # compute column cell view (if coltype is None, it's a left outer
             # join, use the default non final subvid)
             if cellvids and colindex in cellvids:
                 column.append_renderer(cellvids[colindex], colindex)
-            elif coltype is not None and self.schema.eschema(coltype).is_final():
+            elif coltype is not None and self._cw.schema.eschema(coltype).is_final():
                 column.append_renderer(self.finalview, colindex)
             else:
                 column.append_renderer(subvid or 'incontext', colindex)
@@ -221,10 +221,10 @@
 
 
     def render_cell(self, cellvid, row, col, w):
-        self.view('cell', self.rset, row=row, col=col, cellvid=cellvid, w=w)
+        self._cw.view('cell', self.cw_rset, row=row, col=col, cellvid=cellvid, w=w)
 
     def get_rows(self):
-        return self.rset
+        return self.cw_rset
 
     @htmlescape
     @jsonize
@@ -233,16 +233,16 @@
         # XXX it might be interesting to try to limit value's
         #     length as much as possible (e.g. by returning the 10
         #     first characters of a string)
-        val = self.rset[row][col]
+        val = self.cw_rset[row][col]
         if val is None:
             return u''
-        etype = self.rset.description[row][col]
-        if self.schema.eschema(etype).is_final():
-            entity, rtype = self.rset.related_entity(row, col)
+        etype = self.cw_rset.description[row][col]
+        if self._cw.schema.eschema(etype).is_final():
+            entity, rtype = self.cw_rset.related_entity(row, col)
             if entity is None:
                 return val # remove_html_tags() ?
             return entity.sortvalue(rtype)
-        entity = self.rset.get_entity(row, col)
+        entity = self.cw_rset.get_entity(row, col)
         return entity.sortvalue()
 
 
@@ -261,17 +261,17 @@
         :param row, col: indexes locating the cell value in view's result set
         :param cellvid: cell view (defaults to 'outofcontext')
         """
-        etype, val = self.rset.description[row][col], self.rset[row][col]
-        if val is not None and not self.schema.eschema(etype).is_final():
-            e = self.rset.get_entity(row, col)
+        etype, val = self.cw_rset.description[row][col], self.cw_rset[row][col]
+        if val is not None and not self._cw.schema.eschema(etype).is_final():
+            e = self.cw_rset.get_entity(row, col)
             e.view(cellvid or 'outofcontext', w=self.w)
         elif val is None:
             # This is usually caused by a left outer join and in that case,
             # regular views will most certainly fail if they don't have
             # a real eid
-            self.wview('final', self.rset, row=row, col=col)
+            self.wview('final', self.cw_rset, row=row, col=col)
         else:
-            self.wview(cellvid or 'final', self.rset, 'null', row=row, col=col)
+            self.wview(cellvid or 'final', self.cw_rset, 'null', row=row, col=col)
 
 
 class InitialTableView(TableView):
@@ -295,17 +295,17 @@
     def call(self, title=None, subvid=None, headers=None, divid=None,
              displaycols=None, displayactions=None, mainindex=None):
         """Dumps a table displaying a composite query"""
-        actrql = self.req.form['actualrql']
-        self.req.ensure_ro_rql(actrql)
+        actrql = self._cw.form['actualrql']
+        self._cw.ensure_ro_rql(actrql)
         displaycols = self.displaycols(displaycols)
-        if displayactions is None and 'displayactions' in self.req.form:
+        if displayactions is None and 'displayactions' in self._cw.form:
             displayactions = True
-        if divid is None and 'divid' in self.req.form:
-            divid = self.req.form['divid']
+        if divid is None and 'divid' in self._cw.form:
+            divid = self._cw.form['divid']
         self.w(u'<div class="section">')
-        if not title and 'title' in self.req.form:
+        if not title and 'title' in self._cw.form:
             # pop title so it's not displayed by the table view as well
-            title = self.req.form.pop('title')
+            title = self._cw.form.pop('title')
         if title:
             self.w(u'<h2>%s</h2>\n' % title)
         if mainindex is None:
@@ -314,12 +314,12 @@
             actions = self.form_filter(divid, displaycols, displayactions, True)
         else:
             actions = ()
-        if not subvid and 'subvid' in self.req.form:
-            subvid = self.req.form.pop('subvid')
-        self.view('table', self.req.execute(actrql),
-                  'noresult', w=self.w, displayfilter=False, subvid=subvid,
-                  displayactions=displayactions, displaycols=displaycols,
-                  actions=actions, headers=headers, divid=divid)
+        if not subvid and 'subvid' in self._cw.form:
+            subvid = self._cw.form.pop('subvid')
+        self._cw.view('table', self._cw.execute(actrql),
+                      'noresult', w=self.w, displayfilter=False, subvid=subvid,
+                      displayactions=displayactions, displaycols=displaycols,
+                      actions=actions, headers=headers, divid=divid)
         self.w(u'</div>\n')