misc: include _raw in inspect page if it exists (#41857)

This commit is contained in:
Frédéric Péters 2020-04-19 08:44:13 +02:00
parent d8da078c73
commit 0f06fecbc1
2 changed files with 19 additions and 2 deletions

View File

@ -1757,18 +1757,28 @@ def test_lazy_structured_items(pub, variable_test_data):
{'id': '2', 'text': 'deux', 'more': 'bar', 'url': 'yyy'}]),
}
ds2 = {
'type': 'formula',
'value': repr([
{'id': '1', 'text': 'un'},
{'id': '2', 'text': 'deux'}]),
}
formdef = FormDef()
formdef.name = 'foobar'
formdef.url_name = 'foobar'
formdef.fields = [
fields.ItemsField(id='1', label='items', data_source=ds, varname='plop'),
fields.ItemsField(id='2', label='items', data_source=ds2, varname='plop2'),
]
formdef.store()
formdata = formdef.data_class()()
formdata.data = {'1': ['1', '2']}
formdata.data = {'1': ['1', '2'], '2': ['1', '2']}
formdata.data['1_display'] = formdef.fields[0].store_display_value(formdata.data, '1')
formdata.data['1_structured'] = formdef.fields[0].store_structured_value(formdata.data, '1')
formdata.data['2_display'] = formdef.fields[1].store_display_value(formdata.data, '2')
formdata.data['2_structured'] = formdef.fields[1].store_structured_value(formdata.data, '2')
formdata.store()
pub.substitutions.reset()
@ -1791,6 +1801,11 @@ def test_lazy_structured_items(pub, variable_test_data):
assert 'form_var_plop_0_url' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
assert 'form_var_plop_1_more' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
assert 'form_var_plop_structured' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
assert 'form_var_plop_raw' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
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()
def test_formdata_user_field(pub, variable_test_data):

View File

@ -639,7 +639,9 @@ class LazyFieldVarStructured(LazyFieldVar):
def inspect_keys(self):
structured_value = self._field.get_structured_value(self._data)
if not structured_value:
return []
if not self._data.get(self._field.id):
return []
return ['raw']
keys = ['raw', 'structured']