misc: fix import of unnamed block field (#73729)
gitea-wip/wcs/pipeline/pr-main This commit looks good
Details
gitea-wip/wcs/pipeline/pr-main This commit looks good
Details
This commit is contained in:
parent
92dac5eb8c
commit
de815650e6
|
@ -1108,3 +1108,50 @@ def test_formdef_import_export_block(pub, admin_user):
|
||||||
|
|
||||||
new_formdata = formdef.data_class().select()[0]
|
new_formdata = formdef.data_class().select()[0]
|
||||||
assert new_formdata.data == formdata.data
|
assert new_formdata.data == formdata.data
|
||||||
|
|
||||||
|
|
||||||
|
def test_formdef_import_export_unnamed_block(pub, admin_user):
|
||||||
|
BlockDef.wipe()
|
||||||
|
block = BlockDef()
|
||||||
|
block.name = 'foobar'
|
||||||
|
block.fields = [
|
||||||
|
fields.StringField(id='1', label='Foo', varname='foo'),
|
||||||
|
]
|
||||||
|
block.store()
|
||||||
|
|
||||||
|
FormDef.wipe()
|
||||||
|
formdef = FormDef()
|
||||||
|
formdef.name = 'test'
|
||||||
|
formdef.fields = [
|
||||||
|
fields.BlockField(id='0', label='test', type='block:foobar', max_items=3),
|
||||||
|
]
|
||||||
|
formdef.store()
|
||||||
|
|
||||||
|
formdef.data_class().wipe()
|
||||||
|
formdata = formdef.data_class()()
|
||||||
|
formdata.data = {
|
||||||
|
'0': {
|
||||||
|
'data': [
|
||||||
|
{
|
||||||
|
'1': 'plop',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'1': 'hop',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'schema': {'1': 'string'},
|
||||||
|
},
|
||||||
|
'0_display': 'foobar, foobar',
|
||||||
|
}
|
||||||
|
formdata.just_created()
|
||||||
|
formdata.store()
|
||||||
|
|
||||||
|
formdata_export = formdata.get_json_export_dict(include_unnamed_fields=True, include_evolution=False)
|
||||||
|
del formdata_export['receipt_time']
|
||||||
|
del formdata_export['last_update_time']
|
||||||
|
formdef.data_class().wipe()
|
||||||
|
|
||||||
|
app = login(get_app(pub))
|
||||||
|
app.post_json('/api/formdefs/test/submit', formdata_export)
|
||||||
|
new_formdata = formdef.data_class().select()[0]
|
||||||
|
assert new_formdata.data == formdata.data
|
||||||
|
|
|
@ -74,7 +74,9 @@ def posted_json_data_to_formdata_data(formdef, data):
|
||||||
|
|
||||||
# merge unnamed fields if they exist
|
# merge unnamed fields if they exist
|
||||||
if '_unnamed' in data:
|
if '_unnamed' in data:
|
||||||
data.update(data.pop('_unnamed'))
|
unnamed_data = data.pop('_unnamed')
|
||||||
|
for k in unnamed_data.keys():
|
||||||
|
data[k] = unnamed_data.get('%s_raw' % k, unnamed_data.get(k)) # prefer raw value
|
||||||
|
|
||||||
# create a temporary formdata so datasources using previous fields in
|
# create a temporary formdata so datasources using previous fields in
|
||||||
# parameters can find their values.
|
# parameters can find their values.
|
||||||
|
|
Loading…
Reference in New Issue