new match_transition selector tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 28 Apr 2009 15:36:37 +0200
branchtls-sprint
changeset 1503 5cc3afa14e4b
parent 1502 e25be3c82947
child 1504 c6051f141807
new match_transition selector
selectors.py
--- a/selectors.py	Tue Apr 28 15:36:04 2009 +0200
+++ b/selectors.py	Tue Apr 28 15:36:37 2009 +0200
@@ -51,7 +51,8 @@
 
 from yams import BASE_TYPES
 
-from cubicweb import Unauthorized, NoSelectableObject, NotAnEntity, role
+from cubicweb import (Unauthorized, NoSelectableObject, NotAnEntity,
+                      role, typed_eid)
 from cubicweb.vregistry import (NoSelectableObject, Selector,
                                 chainall, objectify_selector)
 from cubicweb.cwconfig import CubicWebConfiguration
@@ -529,6 +530,20 @@
         return score
 
 
+class match_transition(match_search_state):
+    @lltrace
+    def __call__(self, cls, req, rset=None, row=None, col=0, **kwargs):
+        try:
+            trname = req.execute('Any XN WHERE X is Transition, X eid %(x)s, X name XN',
+                                 {'x': typed_eid(req.form['treid'])})[0][0]
+        except (KeyError, IndexError):
+            return 0
+        # XXX check this is a transition that apply to the object?
+        if not trname in self.expected:
+            return 0
+        return 1
+
+
 class match_view(match_search_state):
     """accept if the current view is in one of the expected vid given to the
     initializer