backoffice: fix formdata history with block field bad value (#89069)
gitea/wcs/pipeline/head This commit looks good
Details
gitea/wcs/pipeline/head This commit looks good
Details
This commit is contained in:
parent
ca2fe34b14
commit
bf32ad0b56
|
@ -596,6 +596,26 @@ def test_backoffice_show_history(pub, user, formdef_class):
|
|||
}
|
||||
evo.add_part(part4)
|
||||
formdata.store()
|
||||
part5 = ContentSnapshotPart(formdata=formdata, old_data=copy.deepcopy(part4.new_data))
|
||||
part5.new_data = {
|
||||
'1': 'reset',
|
||||
'2': 'foo bar blah',
|
||||
'3': 'foo@bar.com',
|
||||
'4': True,
|
||||
'6': time.strptime('2022-11-06', '%Y-%m-%d'),
|
||||
'7': 'b',
|
||||
'7_display': 'b',
|
||||
'8': ['a', 'b'],
|
||||
'8_display': 'a, b',
|
||||
'9': '1.5;2.26',
|
||||
'10': {'cleartext': 'fooo'},
|
||||
'11': 'computed',
|
||||
# bad format, 12 is a block field
|
||||
'12': 'foobar',
|
||||
'bo1': 'foobar',
|
||||
}
|
||||
evo.add_part(part5)
|
||||
formdata.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get(formdata.get_backoffice_url())
|
||||
|
@ -741,6 +761,25 @@ def test_backoffice_show_history(pub, user, formdef_class):
|
|||
assert len(resp.pyquery('%s tr[data-field-id="12"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="bo1"]' % table4)) == 0
|
||||
|
||||
assert resp.pyquery(
|
||||
'#evolutions fieldset[data-datetime="%s"] legend' % part5.datetime.isoformat()
|
||||
).text() == 'changed at %s' % localtime(part5.datetime).strftime('%Y-%m-%d %H:%M')
|
||||
table4 = '#evolutions table[data-datetime="%s"]' % part5.datetime.isoformat()
|
||||
assert len(resp.pyquery('%s tr[data-field-id="1"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="2"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="3"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="4"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="5"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="6"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="7"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="8"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="9"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="10"]' % table4)) == 0
|
||||
assert len(resp.pyquery('%s tr[data-field-id="11"]' % table4)) == 0
|
||||
assert resp.pyquery('%s tr[data-field-id="12"] td' % table3).text() == 'Block'
|
||||
assert len(resp.pyquery('%s tr[data-block-id="12"]' % table3)) == 2
|
||||
assert len(resp.pyquery('%s tr[data-field-id="bo1"]' % table4)) == 0
|
||||
|
||||
# check user display
|
||||
part5 = ContentSnapshotPart(formdata=formdata, old_data=copy.deepcopy(part4.new_data))
|
||||
part5.new_data = copy.deepcopy(part4.new_data)
|
||||
|
|
|
@ -618,8 +618,14 @@ class ContentSnapshotPart(EvolutionPart):
|
|||
def diff_fields(fields, old_data, new_data, block_field=None, block_item_num=0):
|
||||
for field in fields:
|
||||
if field.key == 'block':
|
||||
block_old_data = (old_data.get(field.id) or {}).get('data') or []
|
||||
block_new_data = (new_data.get(field.id) or {}).get('data') or []
|
||||
try:
|
||||
block_old_data = (old_data.get(field.id) or {}).get('data') or []
|
||||
except AttributeError:
|
||||
block_old_data = []
|
||||
try:
|
||||
block_new_data = (new_data.get(field.id) or {}).get('data') or []
|
||||
except AttributeError:
|
||||
block_new_data = []
|
||||
len_old = len(block_old_data)
|
||||
len_new = len(block_new_data)
|
||||
block_diffs = []
|
||||
|
|
Loading…
Reference in New Issue