change_workflow fixes
This commit is contained in:
parent
b9e2b60849
commit
eb8863136e
|
@ -2,8 +2,8 @@ from wcs.formdef import FormDef
|
|||
from wcs.qommon.storage import NotEqual
|
||||
from wcs.workflows import Workflow
|
||||
|
||||
FORM_SLUG = 'contact'
|
||||
TARGET_WF_ID = 19
|
||||
FORM_SLUG = 'Prime-eco-logis-91'
|
||||
TARGET_WF_ID = 21
|
||||
|
||||
formdef = FormDef.get_by_urlname(FORM_SLUG)
|
||||
print('Form:', formdef.name)
|
||||
|
@ -21,11 +21,15 @@ print('')
|
|||
status_mapping = {}
|
||||
status_mapping_display = {}
|
||||
for status in current_workflow.possible_status:
|
||||
# we only care about unmatched status ids
|
||||
if status.id not in [x.id for x in target_workflow.possible_status]:
|
||||
new_status = [x for x in target_workflow.possible_status if x.id == status.id]
|
||||
if not new_status:
|
||||
status_index = input('Map status %s to: ' % status.name)
|
||||
status_mapping[status.id] = target_workflow.possible_status[int(status_index)].id
|
||||
status_mapping_display[status.name] = target_workflow.possible_status[int(status_index)].name
|
||||
new_status = target_workflow.possible_status[int(status_index)]
|
||||
else:
|
||||
assert len(new_status) == 1
|
||||
new_status = new_status[0]
|
||||
status_mapping['wf-%s' % status.id] = 'wf-%s' % new_status.id
|
||||
status_mapping_display[status.name] = new_status.name
|
||||
|
||||
for status, target_status in status_mapping_display.items():
|
||||
print('Will remap status %s to %s' % (status, target_status))
|
||||
|
@ -34,19 +38,18 @@ if not input('Proceed? [y/N] ') == 'y':
|
|||
print('Aborted.')
|
||||
exit()
|
||||
|
||||
for x in status_mapping.items():
|
||||
###
|
||||
### workflow_status_remapping_submit code from wcs
|
||||
###
|
||||
# status_mapping.update({'draft': 'draft'})
|
||||
for item in formdef.data_class().select([NotEqual('status', 'draft')]):
|
||||
item.status = status_mapping.get(item.status)
|
||||
if item.evolution:
|
||||
for evo in item.evolution:
|
||||
evo.status = status_mapping.get(evo.status)
|
||||
item.store()
|
||||
###
|
||||
### workflow_status_remapping_submit code from wcs
|
||||
###
|
||||
for item in formdef.data_class().select([NotEqual('status', 'draft')]):
|
||||
item.status = status_mapping.get(item.status)
|
||||
if item.evolution:
|
||||
for evo in item.evolution:
|
||||
evo.status = status_mapping.get(evo.status)
|
||||
item.store()
|
||||
|
||||
formdef.workflow = Workflow.get(TARGET_WF_ID)
|
||||
formdef.store(comment='Changement de workflow (manuel)')
|
||||
# instruct formdef to update its security rules
|
||||
formdef.data_class().rebuild_security()
|
||||
formdef.update_storage()
|
||||
|
|
Loading…
Reference in New Issue