[workflow ui] fix state/transition edition form on existing entity. Closes #2423531
It should not return unrelated entities only in case where the entity
exists.
Also fix a deprecation warning, vocabulary values should be an
unicode string.
--- a/web/views/workflow.py Fri Jul 20 11:42:59 2012 +0200
+++ b/web/views/workflow.py Thu Jul 19 09:01:54 2012 +0200
@@ -315,7 +315,7 @@
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)
+ return sorted((e.view('combobox'), unicode(e.eid))
for e in getattr(wf, 'reverse_%s' % wfrelation)
if rschema.has_perm(req, 'add', **{param: e.eid}))
@@ -330,12 +330,14 @@
def transition_states_vocabulary(form, field):
entity = form.edited_entity
- if not entity.has_eid():
+ if entity.has_eid():
+ wfeid = entity.transition_of[0].eid
+ else:
eids = form.linked_to.get(('transition_of', 'subject'))
if not eids:
return []
- return _wf_items_for_relation(form._cw, eids[0], 'state_of', field)
- return field.relvoc_unrelated(form)
+ wfeid = eids[0]
+ return _wf_items_for_relation(form._cw, wfeid, 'state_of', field)
_afs.tag_subject_of(('*', 'destination_state', '*'), 'main', 'attributes')
_affk.tag_subject_of(('*', 'destination_state', '*'),
@@ -348,12 +350,14 @@
def state_transitions_vocabulary(form, field):
entity = form.edited_entity
- if not entity.has_eid():
+ if entity.has_eid():
+ wfeid = entity.state_of[0].eid
+ else :
eids = form.linked_to.get(('state_of', 'subject'))
- if eids:
- return _wf_items_for_relation(form._cw, eids[0], 'transition_of', field)
- return []
- return field.relvoc_unrelated(form)
+ if not eids:
+ return []
+ wfeid = eids[0]
+ return _wf_items_for_relation(form._cw, wfeid, 'transition_of', field)
_afs.tag_subject_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
_affk.tag_subject_of(('State', 'allowed_transition', '*'),