wcs: force an (empty) value for custom schema (#63935)

This commit is contained in:
Frédéric Péters 2022-04-14 16:26:14 +02:00 committed by Thomas NOEL
parent 518bf6ca4e
commit a3f5786473
2 changed files with 28 additions and 0 deletions

View File

@ -95,6 +95,13 @@ class WcsCardInfoCellForm(forms.ModelForm):
instance = kwargs['instance']
initial = kwargs.pop('initial', {})
initial['with_user'] = not instance.without_user
if kwargs.get('data'):
kwargs['data'] = kwargs['data'].copy() # QueryDict -> dict
# make sure there's a value for custom_schema as postgres.forms.jsonb
# would crash on None.
custom_schema_name = '%s-custom_schema' % kwargs.get('prefix')
if custom_schema_name not in kwargs['data']:
kwargs['data'][custom_schema_name] = '{}'
super().__init__(initial=initial, *args, **kwargs)
card_models = get_wcs_options('/api/cards/@list', include_custom_views=True)
self.fields['carddef_reference'].widget = forms.Select(choices=card_models)

View File

@ -1950,7 +1950,28 @@ def test_card_cell_setup(mock_send, app, admin_user):
]
}
WcsCardInfosCell.objects.all().delete()
# check adding a cell from the UI
app = login(app)
resp = app.get('/manage/pages/%s/' % page.pk)
cell_add_url = [x for x in resp.html.find_all('option') if x.text == 'Card Information Cell'][0].get(
'data-add-url'
)
resp = app.get(cell_add_url).follow()
cell = WcsCardInfosCell.objects.all().first()
manager_submit_cell(resp.forms[0]) # will save card model
cell.refresh_from_db()
# check getting back to uncustomized display reset the schema
cell.customize_display = True
cell.custom_schema = {
'cells': [
{'varname': 'foo', 'field_content': 'value', 'display_mode': 'text', 'empty_value': '@empty@'}
]
}
cell.save()
resp = app.get('/manage/pages/%s/' % page.pk)
assert resp.forms[0]['c%s-customize_display' % cell.get_reference()].value == 'on'
resp.forms[0]['c%s-customize_display' % cell.get_reference()].value = False