fix change_state to allow state as eid/state name/state entity/ stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 19 Jun 2009 08:23:23 +0200
branchstable
changeset 2117 b451bd56c9cd
parent 2116 344ca533ee9d
child 2118 0012d997b992
fix change_state to allow state as eid/state name/state entity/
common/mixins.py
--- a/common/mixins.py	Fri Jun 19 08:22:51 2009 +0200
+++ b/common/mixins.py	Fri Jun 19 08:23:23 2009 +0200
@@ -191,11 +191,18 @@
             return rset.get_entity(0, 0)
         return None
 
-    def change_state(self, stateeid, trcomment=None, trcommentformat=None):
+    def change_state(self, state, trcomment=None, trcommentformat=None):
         """change the entity's state according to a state defined in given
         parameters
         """
-        assert not isinstance(stateeid, basestring), 'change_state wants a state eid'
+        if isinstance(state, basestring):
+            state = self.wf_state(state)
+            assert state is not None, 'not a %s state: %s' % (self.id, state)
+        if hasattr(state, 'eid'):
+            stateeid = state.eid
+        else:
+            stateeid = state
+        stateeid = typed_eid(stateeid)
         if trcomment:
             self.req.set_shared_data('trcomment', trcomment)
         if trcommentformat: