merge
authorKatia Saurfelt <katia.saurfelt@logilab.fr>
Thu, 16 Apr 2009 17:49:52 +0200
changeset 1384 c4f4f8bacb92
parent 1383 a793dc5bfd67 (current diff)
parent 1381 6042f1b342bb (diff)
child 1385 41fe68a4f94c
child 1394 ff1e912cbc39
merge
--- a/cwvreg.py	Thu Apr 16 17:37:59 2009 +0200
+++ b/cwvreg.py	Thu Apr 16 17:49:52 2009 +0200
@@ -179,9 +179,9 @@
         
     def possible_actions(self, req, rset, **kwargs):
         if rset is None:
-            actions = self.possible_vobjects('actions', req, rset)
+            actions = self.possible_vobjects('actions', req, rset, **kwargs)
         else:
-            actions = rset.possible_actions() # cached implementation
+            actions = rset.possible_actions(**kwargs) # cached implementation
         result = {}
         for action in actions:
             result.setdefault(action.category, []).append(action)
--- a/rset.py	Thu Apr 16 17:37:59 2009 +0200
+++ b/rset.py	Thu Apr 16 17:49:52 2009 +0200
@@ -51,7 +51,9 @@
         # set by the cursor which returned this resultset
         self.vreg = None
         self.req = None
-   
+        # actions cache
+        self._rsetactions = None
+        
     def __str__(self):
         if not self.rows:
             return '<empty resultset %s>' % self.rql
@@ -70,9 +72,19 @@
                                                  '\n'.join('%s (%s)' % (r, d)
                                                            for r, d in zip(rows, self.description)))
 
-    @cached
-    def possible_actions(self):
-        return self.vreg.possible_vobjects('actions', self.req, self)
+    def possible_actions(self, **kwargs):
+        if self._rsetactions is None:
+            self._rsetactions = {}
+        if kwargs:
+            key = tuple(sorted(kwargs.iteritems()))
+        else:
+            key = None
+        try:
+            return self._rsetactions[key]
+        except KeyError:
+            actions = self.vreg.possible_vobjects('actions', self.req, self, **kwargs)
+            self._rsetactions[key] = actions
+            return actions
     
     def __len__(self):
         """returns the result set's size"""
--- a/web/views/tabs.py	Thu Apr 16 17:37:59 2009 +0200
+++ b/web/views/tabs.py	Thu Apr 16 17:49:52 2009 +0200
@@ -96,19 +96,25 @@
         return selected_tabs
 
     def render_tabs(self, tabs, default, entity):
+        # tabbed views do no support concatenation
+        # hence we delegate to the default tab if there is more than on entity
+        # in the result set
+        if len(self.rset) > 1:
+            entity.view(default, w=self.w)
+            return
+        # XXX (syt) fix below add been introduced at some point to fix something
+        # (http://intranet.logilab.fr/jpl/ticket/32174 ?) but this is not a clean
+        # way. We must not consider form['rql'] here since it introduces some
+        # other failures on non rql queries (plain text, shortcuts,... handled by
+        # magicsearch) which has a single result whose primary view is using tabs
+        # (https://www.logilab.net/cwo/ticket/342789)
+        #rql = self.req.form.get('rql')
+        #if rql:
+        #    self.req.execute(rql).get_entity(0,0).view(default, w=self.w)
+        #    return
         self.req.add_css('ui.tabs.css')
         self.req.add_js(('ui.core.js', 'ui.tabs.js',
                          'cubicweb.ajax.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js'))
-        # tabbed views do no support concatenation
-        # hence we delegate to the default tab
-        form = self.req.form
-        if form.get('vid') == 'primary':
-            entity.view(default, w=self.w)
-            return
-        rql = form.get('rql')
-        if rql:
-            self.req.execute(rql).get_entity(0,0).view(default, w=self.w)
-            return
         # prune tabs : not all are to be shown
         tabs = self.prune_tabs(tabs)
         # select a tab