forms: restore edited data early on (#48493)
This commit is contained in:
parent
d7e0232354
commit
1c0b30004d
|
@ -3654,6 +3654,63 @@ def test_backoffice_wfedit_and_data_source_with_user_info(pub):
|
|||
resp = resp.follow()
|
||||
|
||||
|
||||
def test_backoffice_wfedit_and_data_source_with_field_info(pub):
|
||||
user = create_user(pub)
|
||||
create_environment(pub)
|
||||
formdef = FormDef.get_by_urlname('form-title')
|
||||
|
||||
formdef.fields[0].varname = 'bar'
|
||||
formdef.fields[2].data_source = {'type': 'json',
|
||||
'value': 'https://www.example.invalid/?xxx={{ form_var_bar }}'
|
||||
}
|
||||
formdef.store()
|
||||
|
||||
form_class = formdef.data_class()
|
||||
|
||||
number31 = [x for x in form_class.select() if x.data['1'] == 'FOO BAR 30'][0]
|
||||
|
||||
# attach a custom workflow
|
||||
workflow = Workflow(name='wfedit')
|
||||
st1 = workflow.add_status('Status1', number31.status.split('-')[1])
|
||||
|
||||
wfedit = EditableWorkflowStatusItem()
|
||||
wfedit.id = '_wfedit'
|
||||
wfedit.by = [user.roles[0]]
|
||||
st1.items.append(wfedit)
|
||||
wfedit.parent = st1
|
||||
workflow.store()
|
||||
|
||||
formdef.workflow_id = workflow.id
|
||||
formdef.store()
|
||||
|
||||
number31 = form_class().get(number31.id)
|
||||
number31.data['3'] = 'EE'
|
||||
number31.data['3_display'] = 'EE'
|
||||
number31.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
|
||||
with mock.patch('wcs.qommon.misc.urlopen') as urlopen:
|
||||
data = {'data': [{'id': 'DD', 'text': 'DD'}, {'id': 'EE', 'text': 'EE'}]}
|
||||
|
||||
def side_effect(url, *args):
|
||||
assert '?xxx=FOO BAR 30' in url
|
||||
return StringIO(json.dumps(data))
|
||||
|
||||
urlopen.side_effect = side_effect
|
||||
|
||||
resp = app.get('/backoffice/management/form-title/%s/' % number31.id)
|
||||
resp = resp.form.submit('button_wfedit')
|
||||
resp = resp.follow()
|
||||
assert urlopen.call_count == 1
|
||||
assert 'invalid value' not in resp
|
||||
assert resp.form['f3'].value == 'EE'
|
||||
resp.form['f3'].value = 'DD'
|
||||
resp = resp.form.submit('submit')
|
||||
assert urlopen.call_count == 2
|
||||
resp = resp.follow()
|
||||
|
||||
|
||||
def test_global_listing(pub):
|
||||
if not pub.is_using_postgresql():
|
||||
pytest.skip('this requires SQL')
|
||||
|
|
|
@ -611,6 +611,10 @@ class FormPage(Directory, FormTemplateMixin):
|
|||
formdata.prefilling_data = formdata.data.get('prefilling_data', {})
|
||||
|
||||
if self.edit_mode:
|
||||
if magictoken is None:
|
||||
# restore edited data early on as it may be required to
|
||||
# create lists with appropriate values on first page.
|
||||
formdata.data = self.edited_data.data
|
||||
# keep associated user as it may be required as a parameter in
|
||||
# data source URLs.
|
||||
formdata.user = self.edited_data.user
|
||||
|
|
Loading…
Reference in New Issue