[schema] default_workflow_of more naturally expressed as default_workflow 3.5
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 21 Aug 2009 08:42:17 +0200
branch3.5
changeset 2943 77622caef9bd
parent 2942 77ebdbe93cf8
child 2944 3bd49b70f7f9
[schema] default_workflow_of more naturally expressed as default_workflow
entities/wfobjs.py
schemas/workflow.py
server/migractions.py
server/test/unittest_migractions.py
test/unittest_schema.py
--- a/entities/wfobjs.py	Fri Aug 21 08:31:25 2009 +0200
+++ b/entities/wfobjs.py	Fri Aug 21 08:42:17 2009 +0200
@@ -29,7 +29,8 @@
         """return True if this workflow is the default workflow for the given
         entity type
         """
-        return any(et for et in self.default_workflow_of if et.name == etype)
+        return any(et for et in self.reverse_default_workflow
+                   if et.name == etype)
 
     def after_deletion_path(self):
         """return (path, parameters) which should be used as redirect
--- a/schemas/workflow.py	Fri Aug 21 08:31:25 2009 +0200
+++ b/schemas/workflow.py	Fri Aug 21 08:42:17 2009 +0200
@@ -26,16 +26,22 @@
                                   description=_('entity types which may use this workflow'),
                                   constraints=[RQLConstraint('O final FALSE')])
 
-    default_workflow_of = SubjectRelation('CWEType', cardinality='*?',
-                                          description=_('which entity types use this workflow by default'),
-                                          constraints=[RQLConstraint('O final FALSE')])
-
     initial_state = SubjectRelation('State', cardinality='?*',
                                    # S initial_state O, O state_of S
                                    constraints=[RQLConstraint('O state_of S')],
                                    description=_('initial state for this workflow'))
 
 
+class default_workflow(RelationType):
+    """default workflow for this entity types"""
+    permissions = META_RTYPE_PERMS
+
+    subject = 'CWEType'
+    object = 'Workflow'
+    cardinality = '?*'
+    constraints = [RQLConstraint('S final FALSE, O workflow_of S')]
+
+
 class State(EntityType):
     """used to associate simple states to an entity type and/or to define
     workflows
--- a/server/migractions.py	Fri Aug 21 08:31:25 2009 +0200
+++ b/server/migractions.py	Fri Aug 21 08:42:17 2009 +0200
@@ -923,7 +923,7 @@
                                 {'x': wf.eid, 'et': etype}, 'x')
             assert rset, 'unexistant entity type %s' % etype
             if default:
-                rset = self.rqlexec('SET X default_workflow_of ET '
+                rset = self.rqlexec('SET ET default_workflow X '
                                     'WHERE X eid %(x)s, ET name %(et)s',
                                     {'x': wf.eid, 'et': etype}, 'x')
         if commit:
--- a/server/test/unittest_migractions.py	Fri Aug 21 08:31:25 2009 +0200
+++ b/server/test/unittest_migractions.py	Fri Aug 21 08:42:17 2009 +0200
@@ -111,7 +111,7 @@
             s1 = self.mh.rqlexec('Any N WHERE WF workflow_of ET, ET name "%s", WF name N' %
                                  etype)[0][0]
             self.assertEquals(s1, "foo")
-            s1 = self.mh.rqlexec('Any N WHERE WF default_workflow_of ET, ET name "%s", WF name N' %
+            s1 = self.mh.rqlexec('Any N WHERE ET default_workflow WF, ET name "%s", WF name N' %
                                  etype)[0][0]
             self.assertEquals(s1, "foo")
 
--- a/test/unittest_schema.py	Fri Aug 21 08:31:25 2009 +0200
+++ b/test/unittest_schema.py	Fri Aug 21 08:42:17 2009 +0200
@@ -166,7 +166,7 @@
                               'composite', 'condition', 'connait', 'constrained_by', 'content',
                               'content_format', 'created_by', 'creation_date', 'cstrtype', 'custom_workflow', 'cwuri',
 
-                              'data', 'data_encoding', 'data_format', 'default_workflow_of', 'defaultval', 'delete_permission',
+                              'data', 'data_encoding', 'data_format', 'default_workflow', 'defaultval', 'delete_permission',
                               'description', 'description_format', 'destination_state',
 
                               'ecrit_par', 'eid', 'evaluee', 'expression', 'exprtype',