admin: don't update formdatas on workflow switch with no changes (#38578)

This commit is contained in:
Frédéric Péters 2019-12-17 10:56:12 +01:00
parent b81a758804
commit 9fa4b1263e
2 changed files with 31 additions and 8 deletions

View File

@ -589,13 +589,33 @@ def test_form_workflow_remapping(pub):
for status in Workflow.get_default_workflow().possible_status:
assert resp.forms[0]['mapping-%s' % status.id]
# there's only one possible new status
assert len(resp.forms[0]['mapping-just_submitted'].options) == 1
assert len(resp.forms[0]['mapping-%s' % status.id].options) == 1
assert data_class.get(formdata1.id).status == 'wf-new'
assert data_class.get(formdata2.id).status == 'draft'
resp = resp.forms[0].submit()
assert data_class.get(formdata1.id).status == 'wf-finished'
assert data_class.get(formdata2.id).status == 'draft'
# change to another workflow, with no mapping change
workflow2 = workflow
workflow = Workflow(name='Workflow Three')
workflow.possible_status = Workflow.get_default_workflow().possible_status[-2:][:]
workflow.store()
resp = app.get('/backoffice/forms/1/')
resp = resp.click(href='workflow', index=1)
resp.forms[0]['workflow_id'] = workflow.id
resp = resp.forms[0].submit('submit')
assert resp.location == 'http://example.net/backoffice/forms/1/workflow-status-remapping?new=3'
resp = resp.follow()
for status in workflow2.possible_status:
assert resp.forms[0]['mapping-%s' % status.id]
# there are two status
assert len(resp.forms[0]['mapping-%s' % status.id].options) == 2
resp = resp.forms[0].submit()
assert data_class.get(formdata1.id).status == 'wf-finished'
assert data_class.get(formdata2.id).status == 'draft'
def test_form_submitter_roles(pub):
create_superuser(pub)
role = create_role()

View File

@ -866,16 +866,19 @@ class FormDefPage(Directory):
return redirect('.')
def workflow_status_remapping_submit(self, form):
status_mapping = {'wf-draft': 'draft', 'draft': 'draft'}
status_mapping = {}
for status in self.formdef.workflow.possible_status:
status_mapping['wf-%s' % status.id] = 'wf-%s' % \
form.get_widget('mapping-%s' % status.id).parse()
for item in self.formdef.data_class().select():
item.status = status_mapping.get(item.status)
if item.evolution:
for evo in item.evolution:
evo.status = status_mapping.get(evo.status)
item.store()
if any([x[0] != x[1] for x in status_mapping.items()]):
# if there are status changes, update all formdatas
status_mapping.update({'wf-draft': 'draft', 'draft': 'draft'})
for item in self.formdef.data_class().select():
item.status = status_mapping.get(item.status)
if item.evolution:
for evo in item.evolution:
evo.status = status_mapping.get(evo.status)
item.store()
def get_preview(self):
form = Form(action='#', use_tokens=False)