1206 self.cmd_add_relation_definition(etype, 'in_state', 'State') |
1206 self.cmd_add_relation_definition(etype, 'in_state', 'State') |
1207 self.cmd_add_relation_definition(etype, 'custom_workflow', 'Workflow') |
1207 self.cmd_add_relation_definition(etype, 'custom_workflow', 'Workflow') |
1208 self.cmd_add_relation_definition('TrInfo', 'wf_info_for', etype) |
1208 self.cmd_add_relation_definition('TrInfo', 'wf_info_for', etype) |
1209 |
1209 |
1210 def cmd_add_workflow(self, name, wfof, default=True, commit=False, |
1210 def cmd_add_workflow(self, name, wfof, default=True, commit=False, |
1211 **kwargs): |
1211 ensure_workflowable=True, **kwargs): |
1212 """ |
1212 """ |
1213 create a new workflow and links it to entity types |
1213 create a new workflow and links it to entity types |
1214 :type name: unicode |
1214 :type name: unicode |
1215 :param name: name of the workflow |
1215 :param name: name of the workflow |
1216 |
1216 |
1230 wfof = (wfof,) |
1230 wfof = (wfof,) |
1231 def _missing_wf_rel(etype): |
1231 def _missing_wf_rel(etype): |
1232 return 'missing workflow relations, see make_workflowable(%s)' % etype |
1232 return 'missing workflow relations, see make_workflowable(%s)' % etype |
1233 for etype in wfof: |
1233 for etype in wfof: |
1234 eschema = self.repo.schema[etype] |
1234 eschema = self.repo.schema[etype] |
1235 assert 'in_state' in eschema.subjrels, _missing_wf_rel(etype) |
1235 if ensure_workflowable: |
1236 assert 'custom_workflow' in eschema.subjrels, _missing_wf_rel(etype) |
1236 assert 'in_state' in eschema.subjrels, _missing_wf_rel(etype) |
1237 assert 'wf_info_for' in eschema.objrels, _missing_wf_rel(etype) |
1237 assert 'custom_workflow' in eschema.subjrels, _missing_wf_rel(etype) |
|
1238 assert 'wf_info_for' in eschema.objrels, _missing_wf_rel(etype) |
1238 rset = self.rqlexec( |
1239 rset = self.rqlexec( |
1239 'SET X workflow_of ET WHERE X eid %(x)s, ET name %(et)s', |
1240 'SET X workflow_of ET WHERE X eid %(x)s, ET name %(et)s', |
1240 {'x': wf.eid, 'et': etype}, ask_confirm=False) |
1241 {'x': wf.eid, 'et': etype}, ask_confirm=False) |
1241 assert rset, 'unexistant entity type %s' % etype |
1242 assert rset, 'unexistant entity type %s' % etype |
1242 if default: |
1243 if default: |