fields: store _structured on ItemsField for every data source (#44123)
This commit is contained in:
parent
b18e62d050
commit
149c73db4f
|
@ -2813,10 +2813,18 @@ def test_form_items_data_source_field_submit(pub):
|
|||
'type': 'formula',
|
||||
'value': repr([('1', 'un'), ('2', 'deux'), ('3', 'trois')]),
|
||||
}
|
||||
assert submit_items_data_source_field(ds) == {'0': ['1', '3'], '0_display': 'un, trois'}
|
||||
assert submit_items_data_source_field(ds) == {
|
||||
'0': ['1', '3'],
|
||||
'0_display': 'un, trois',
|
||||
'0_structured': [{'id': '1', 'text': 'un'}, {'id': '3', 'text': 'trois'}],
|
||||
}
|
||||
|
||||
ds['value'] = repr([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}, {'id': '3', 'text': 'trois'}])
|
||||
assert submit_items_data_source_field(ds) == {'0': ['1', '3'], '0_display': 'un, trois'}
|
||||
assert submit_items_data_source_field(ds) == {
|
||||
'0': ['1', '3'],
|
||||
'0_display': 'un, trois',
|
||||
'0_structured': [{'id': '1', 'text': 'un'}, {'id': '3', 'text': 'trois'}],
|
||||
}
|
||||
|
||||
ds['value'] = repr(
|
||||
[
|
||||
|
@ -4320,7 +4328,11 @@ def test_form_items_datasource(pub):
|
|||
resp = resp.form.submit('submit')
|
||||
resp = resp.follow()
|
||||
|
||||
assert data_class.select()[0].data == {'1': ['un', 'deux'], '1_display': 'un, deux'}
|
||||
assert data_class.select()[0].data == {
|
||||
'1': ['un', 'deux'],
|
||||
'1_display': 'un, deux',
|
||||
'1_structured': [{'id': 'un', 'text': 'un'}, {'id': 'deux', 'text': 'deux'}],
|
||||
}
|
||||
|
||||
data_source.data_source = {
|
||||
'type': 'formula',
|
||||
|
@ -4339,7 +4351,11 @@ def test_form_items_datasource(pub):
|
|||
resp = resp.form.submit('submit')
|
||||
resp = resp.follow()
|
||||
|
||||
assert data_class.select()[0].data == {'1': ['1', '2'], '1_display': 'un, deux'}
|
||||
assert data_class.select()[0].data == {
|
||||
'1': ['1', '2'],
|
||||
'1_display': 'un, deux',
|
||||
'1_structured': [{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}],
|
||||
}
|
||||
|
||||
data_source.data_source = {
|
||||
'type': 'formula',
|
||||
|
|
|
@ -2609,10 +2609,7 @@ def test_lazy_structured_items(pub, variable_test_data):
|
|||
|
||||
assert 'form_var_plop2' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
|
||||
assert 'form_var_plop2_raw' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
|
||||
assert (
|
||||
'form_var_plop2_structured'
|
||||
not in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
|
||||
)
|
||||
assert 'form_var_plop2_structured' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
|
||||
|
||||
|
||||
def test_formdata_user_field(pub, variable_test_data):
|
||||
|
|
|
@ -2297,8 +2297,6 @@ class ItemsField(WidgetField, ItemFieldMixin):
|
|||
structured_options = data_sources.get_structured_items(self.data_source)
|
||||
if not structured_options:
|
||||
return
|
||||
if not set(structured_options[0].keys()) != set(['id', 'text']):
|
||||
return
|
||||
structured_value = []
|
||||
for structured_option in structured_options:
|
||||
for choice in data.get(field_id) or []:
|
||||
|
|
Loading…
Reference in New Issue