misc: use _structured suffix for structured field data (#41855)

This commit is contained in:
Frédéric Péters 2020-04-18 16:51:12 +02:00
parent c3ddaa2e6c
commit d8da078c73
4 changed files with 11 additions and 2 deletions

View File

@ -4542,6 +4542,7 @@ def test_backoffice_workflow_display_form(pub):
'blah_var_str': 'blah',
'blah_var_radio': 'c',
'blah_var_radio_raw': 'c',
'blah_var_radio_structured': None,
'blah_var_radio_structured_raw': None}

View File

@ -1785,10 +1785,12 @@ def test_lazy_structured_items(pub, variable_test_data):
assert tmpl.render(context) == 'yyy'
tmpl = Template('{% for x in form_var_plop_structured_raw %}{{x.more}}{% endfor %}')
assert tmpl.render(context) == 'foobar'
tmpl = Template('{% for x in form_var_plop_structured %}{{x.more}}{% endfor %}')
assert tmpl.render(context) == 'foobar'
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_raw' 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()
def test_formdata_user_field(pub, variable_test_data):

View File

@ -95,6 +95,7 @@ def get_dict_with_varnames(fields, data, formdata=None, varnames_only=False):
new_data['var_%s_%s_%s' % (field.varname, i, k)] = v
if field.store_structured_value:
new_data['var_%s_structured_raw' % field.varname] = structured_value
new_data['var_%s_structured' % field.varname] = structured_value
return new_data

View File

@ -641,7 +641,7 @@ class LazyFieldVarStructured(LazyFieldVar):
if not structured_value:
return []
keys = ['raw', 'structured_raw']
keys = ['raw', 'structured']
def walk(base, value):
if isinstance(value, dict):
@ -660,6 +660,11 @@ class LazyFieldVarStructured(LazyFieldVar):
@property
def structured_raw(self):
# backward compatibility, _structured should be use.
return self._field.get_structured_value(self._data)
@property
def structured(self):
return self._field.get_structured_value(self._data)
def __getitem__(self, key):