add script to change formdef workflow
This commit is contained in:
parent
d496f9005a
commit
b9e2b60849
|
@ -0,0 +1,52 @@
|
|||
from wcs.formdef import FormDef
|
||||
from wcs.qommon.storage import NotEqual
|
||||
from wcs.workflows import Workflow
|
||||
|
||||
FORM_SLUG = 'contact'
|
||||
TARGET_WF_ID = 19
|
||||
|
||||
formdef = FormDef.get_by_urlname(FORM_SLUG)
|
||||
print('Form:', formdef.name)
|
||||
current_workflow = formdef.workflow
|
||||
print('Current workflow:', current_workflow.name)
|
||||
target_workflow = Workflow.get(TARGET_WF_ID)
|
||||
print('Target workflow:', target_workflow.name, end='\n\n')
|
||||
|
||||
# remap statuses
|
||||
print('Available statuses:')
|
||||
for i, status in enumerate(target_workflow.possible_status):
|
||||
print('[%s] %s' % (i, status.name))
|
||||
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]:
|
||||
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
|
||||
|
||||
for status, target_status in status_mapping_display.items():
|
||||
print('Will remap status %s to %s' % (status, target_status))
|
||||
|
||||
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()
|
||||
|
||||
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()
|
Loading…
Reference in New Issue