diff --git a/tests/test_backoffice_pages.py b/tests/test_backoffice_pages.py index 733aa5983..7c70a0e62 100644 --- a/tests/test_backoffice_pages.py +++ b/tests/test_backoffice_pages.py @@ -4317,7 +4317,10 @@ def test_backoffice_workflow_display_form(pub): resp = resp.form.submit('submit') assert formdef.data_class().get(formdata.id).status == 'wf-accepted' assert formdef.data_class().get(formdata.id).workflow_data == { - 'blah_var_str': 'blah', 'blah_var_radio': 'c', 'blah_var_radio_raw': 'c'} + 'blah_var_str': 'blah', + 'blah_var_radio': 'c', + 'blah_var_radio_raw': 'c', + 'blah_var_radio_structured_raw': None} def test_backoffice_workflow_form_with_conditions(pub): diff --git a/tests/test_formdata.py b/tests/test_formdata.py index bc2ec3182..07416225b 100644 --- a/tests/test_formdata.py +++ b/tests/test_formdata.py @@ -1757,9 +1757,12 @@ def test_lazy_structured_items(pub, variable_test_data): assert tmpl.render(context) == 'bar' tmpl = Template('{{ form_var_plop_1_url }}') assert tmpl.render(context) == 'yyy' + tmpl = Template('{% for x in form_var_plop_structured_raw %}{{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() def test_formdata_user_field(pub, variable_test_data): diff --git a/wcs/formdata.py b/wcs/formdata.py index ef5aebe42..0f585422c 100644 --- a/wcs/formdata.py +++ b/wcs/formdata.py @@ -93,6 +93,8 @@ def get_dict_with_varnames(fields, data, formdata=None, varnames_only=False): if k in ('id', 'text'): continue 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 return new_data diff --git a/wcs/variables.py b/wcs/variables.py index f9039daec..8305455e4 100644 --- a/wcs/variables.py +++ b/wcs/variables.py @@ -602,7 +602,7 @@ class LazyFieldVarStructured(LazyFieldVar): if not structured_value: return [] - keys = ['raw'] + keys = ['raw', 'structured_raw'] def walk(base, value): if isinstance(value, dict): @@ -619,6 +619,10 @@ class LazyFieldVarStructured(LazyFieldVar): return keys + @property + def structured_raw(self): + return self._field.get_structured_value(self._data) + def __getitem__(self, key): try: return super(LazyFieldVarStructured, self).__getitem__(key)