workflows: clean context after workflow form action (#39030)
This commit is contained in:
parent
cd9cb97266
commit
3d9fd7f2bc
|
@ -5532,3 +5532,79 @@ def test_studio_card_item_link(pub, studio):
|
|||
resp = app.get('/backoffice/data/bar/1/')
|
||||
with pytest.raises(IndexError):
|
||||
resp.click('card plop')
|
||||
|
||||
|
||||
def test_lazy_eval_with_conditional_workflow_form(pub):
|
||||
role = Role(name='foobar')
|
||||
role.store()
|
||||
user = create_user(pub)
|
||||
|
||||
app = login(get_app(pub))
|
||||
|
||||
FormDef.wipe()
|
||||
|
||||
wf = Workflow(name='lazy backoffice form')
|
||||
wf.backoffice_fields_formdef = WorkflowBackofficeFieldsFormDef(wf)
|
||||
wf.backoffice_fields_formdef.fields = [
|
||||
fields.StringField(id='bo1', label='Foo Bar', varname='foo_bar'),
|
||||
]
|
||||
st1 = wf.add_status('New', 'new')
|
||||
st2 = wf.add_status('Choose', 'choice')
|
||||
st3 = wf.add_status('Done', 'done')
|
||||
|
||||
# first status with a workflow form, with a live conditional field.
|
||||
display_form = FormWorkflowStatusItem()
|
||||
display_form.id = '_display_form'
|
||||
display_form.by = [user.roles[0]]
|
||||
display_form.varname = 'local'
|
||||
display_form.formdef = WorkflowFormFieldsFormDef(item=display_form)
|
||||
display_form.formdef.fields = [
|
||||
fields.StringField(id='1', label='Test', varname='str', type='string', required=True),
|
||||
fields.StringField(id='2', label='Test 2', varname='str2', type='string',
|
||||
condition={'type': 'django', 'value': 'local_var_str'})
|
||||
]
|
||||
display_form.parent = st1
|
||||
|
||||
submit_choice = JumpOnSubmitWorkflowStatusItem()
|
||||
submit_choice.parent = st1
|
||||
submit_choice.status = st2.id
|
||||
st1.items.append(display_form)
|
||||
st1.items.append(submit_choice)
|
||||
|
||||
# jump to a second status, that set's a backoffice field data
|
||||
setbo = SetBackofficeFieldsWorkflowStatusItem()
|
||||
setbo.parent = st2
|
||||
setbo.fields = [{'field_id': 'bo1', 'value': 'go'}]
|
||||
|
||||
# and jump to the third status if the evoluation succeeds
|
||||
jump = JumpWorkflowStatusItem()
|
||||
jump.condition = {'type': 'django', 'value': "form_var_foo_bar == 'go'"}
|
||||
jump.status = st3.id
|
||||
jump.parent = st2
|
||||
st2.items.append(setbo)
|
||||
st2.items.append(jump)
|
||||
wf.store()
|
||||
|
||||
formdef = FormDef()
|
||||
formdef.name = 'test'
|
||||
formdef.fields = [
|
||||
fields.StringField(id='0', label='Foo', varname='foo')
|
||||
]
|
||||
formdef.workflow_roles = {'_receiver': role.id}
|
||||
formdef.workflow_id = wf.id
|
||||
formdef.store()
|
||||
formdata = formdef.data_class()()
|
||||
formdata.just_created()
|
||||
formdata.data = {
|
||||
'0': 'test'
|
||||
}
|
||||
formdata.store()
|
||||
|
||||
resp = app.get(formdata.get_url(backoffice=True))
|
||||
resp.forms[0]['f1'] = 'a'
|
||||
resp.forms[0]['f2'] = 'b'
|
||||
resp = resp.forms[0].submit()
|
||||
assert formdata.select()[0].status == 'wf-done'
|
||||
|
||||
context = pub.substitutions.get_context_variables(mode='lazy')
|
||||
assert context['form_var_foo_bar'] == 'go'
|
||||
|
|
|
@ -216,6 +216,7 @@ class FormWorkflowStatusItem(WorkflowStatusItem):
|
|||
if form.get_submit() == 'submit' and not form.has_errors():
|
||||
self.evaluate_live_form(form, formdata, user)
|
||||
formdata.store()
|
||||
get_publisher().substitutions.unfeed(lambda x: x.__class__.__name__ == 'ConditionVars')
|
||||
|
||||
def get_parameters_view(self):
|
||||
r = TemplateIO(html=True)
|
||||
|
|
Loading…
Reference in New Issue