--- a/web/views/workflow.py Wed Jun 29 13:03:04 2011 +0200
+++ b/web/views/workflow.py Fri Jul 01 12:20:24 2011 +0200
@@ -39,7 +39,7 @@
from cubicweb.web import uicfg, stdmsgs, action, component, form, action
from cubicweb.web import formfields as ff, formwidgets as fwdgs
from cubicweb.web.views import TmpFileViewMixin
-from cubicweb.web.views import forms, primary, autoform, ibreadcrumbs
+from cubicweb.web.views import forms, primary, ibreadcrumbs
from cubicweb.web.views.tabs import TabbedPrimaryView, PrimaryTab
from cubicweb.web.views.dotgraphview import DotGraphView, DotPropsHandler
@@ -72,11 +72,7 @@
_abaa.tag_object_of(('WorkflowTransition', 'transition_of', 'Workflow'), True)
_afs = uicfg.autoform_section
-_afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'main', 'hidden')
-_afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'main', 'hidden')
-_afs.tag_attribute(('TrInfo', 'tr_count'), 'main', 'hidden')
-_afs.tag_object_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
-
+_affk = uicfg.autoform_field_kwargs
# IWorkflowable views #########################################################
@@ -324,51 +320,56 @@
# workflow entity types edition ################################################
-_afs = uicfg.autoform_section
+def _wf_items_for_relation(req, wfeid, wfrelation, field):
+ wf = req.entity_from_eid(wfeid)
+ rschema = req.vreg.schema[field.name]
+ param = 'toeid' if field.role == 'subject' else 'fromeid'
+ return sorted((e.view('combobox'), e.eid)
+ for e in getattr(wf, 'reverse_%s' % wfrelation)
+ if rschema.has_perm(req, 'add', **{param: e.eid}))
+
+# TrInfo
_afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'main', 'hidden')
_afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'main', 'hidden')
-_afs.tag_object_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
-_afs.tag_subject_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
+_afs.tag_attribute(('TrInfo', 'tr_count'), 'main', 'hidden')
+
+# BaseTransition
+# XXX * allowed_transition BaseTransition
+# XXX BaseTransition destination_state *
+
+def transition_states_vocabulary(form, field):
+ entity = form.edited_entity
+ if not entity.has_eid():
+ eids = entity.linked_to('transition_of', 'subject')
+ if not eids:
+ return []
+ return _wf_items_for_relation(form._cw, eids[0], 'state_of', field)
+ return ff.relvoc_unrelated(entity, field.name, field.role)
-def workflow_items_for_relation(req, wfeid, wfrelation, targetrelation):
- wf = req.entity_from_eid(wfeid)
- rschema = req.vreg.schema[targetrelation]
- return sorted((e.view('combobox'), e.eid)
- for e in getattr(wf, 'reverse_%s' % wfrelation)
- if rschema.has_perm(req, 'add', toeid=e.eid))
+_afs.tag_subject_of(('*', 'destination_state', '*'), 'main', 'attributes')
+_affk.tag_subject_of(('*', 'destination_state', '*'),
+ {'choices': transition_states_vocabulary})
+_afs.tag_object_of(('*', 'allowed_transition', '*'), 'main', 'attributes')
+_affk.tag_object_of(('*', 'allowed_transition', '*'),
+ {'choices': transition_states_vocabulary})
+
+# State
+
+def state_transitions_vocabulary(form, field):
+ entity = form.edited_entity
+ if not entity.has_eid():
+ eids = entity.linked_to('state_of', 'subject')
+ if eids:
+ return _wf_items_for_relation(form._cw, eids[0], 'transition_of', field)
+ return []
+ return ff.relvoc_unrelated(entity, field.name, field.role)
+
+_afs.tag_subject_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
+_affk.tag_subject_of(('State', 'allowed_transition', '*'),
+ {'choices': state_transitions_vocabulary})
-class TransitionEditionForm(autoform.AutomaticEntityForm):
- __select__ = is_instance('Transition')
-
- def workflow_states_for_relation(self, targetrelation):
- eids = self.edited_entity.linked_to('transition_of', 'subject')
- if eids:
- return workflow_items_for_relation(self._cw, eids[0], 'state_of',
- targetrelation)
- return []
-
- def subject_destination_state_vocabulary(self, rtype, limit=None):
- if not self.edited_entity.has_eid():
- return self.workflow_states_for_relation('destination_state')
- return self.subject_relation_vocabulary(rtype, limit)
-
- def object_allowed_transition_vocabulary(self, rtype, limit=None):
- if not self.edited_entity.has_eid():
- return self.workflow_states_for_relation('allowed_transition')
- return self.object_relation_vocabulary(rtype, limit)
-
-
-class StateEditionForm(autoform.AutomaticEntityForm):
- __select__ = is_instance('State')
-
- def subject_allowed_transition_vocabulary(self, rtype, limit=None):
- if not self.edited_entity.has_eid():
- eids = self.edited_entity.linked_to('state_of', 'subject')
- if eids:
- return workflow_items_for_relation(self._cw, eids[0], 'transition_of',
- 'allowed_transition')
- return []
+# adaptaters ###################################################################
class WorkflowIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter):
__select__ = is_instance('Workflow')