selectors.py
branchtls-sprint
changeset 1503 5cc3afa14e4b
parent 1492 53d28ac02868
child 1694 d7990e3478b2
--- 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