fields: add access to raw structured values (#40203)
This commit is contained in:
parent
bfe446c444
commit
db0a045e3e
|
@ -4317,7 +4317,10 @@ def test_backoffice_workflow_display_form(pub):
|
||||||
resp = resp.form.submit('submit')
|
resp = resp.form.submit('submit')
|
||||||
assert formdef.data_class().get(formdata.id).status == 'wf-accepted'
|
assert formdef.data_class().get(formdata.id).status == 'wf-accepted'
|
||||||
assert formdef.data_class().get(formdata.id).workflow_data == {
|
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):
|
def test_backoffice_workflow_form_with_conditions(pub):
|
||||||
|
|
|
@ -1757,9 +1757,12 @@ def test_lazy_structured_items(pub, variable_test_data):
|
||||||
assert tmpl.render(context) == 'bar'
|
assert tmpl.render(context) == 'bar'
|
||||||
tmpl = Template('{{ form_var_plop_1_url }}')
|
tmpl = Template('{{ form_var_plop_1_url }}')
|
||||||
assert tmpl.render(context) == 'yyy'
|
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_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_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):
|
def test_formdata_user_field(pub, variable_test_data):
|
||||||
|
|
|
@ -93,6 +93,8 @@ def get_dict_with_varnames(fields, data, formdata=None, varnames_only=False):
|
||||||
if k in ('id', 'text'):
|
if k in ('id', 'text'):
|
||||||
continue
|
continue
|
||||||
new_data['var_%s_%s_%s' % (field.varname, i, k)] = v
|
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
|
return new_data
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -602,7 +602,7 @@ class LazyFieldVarStructured(LazyFieldVar):
|
||||||
if not structured_value:
|
if not structured_value:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
keys = ['raw']
|
keys = ['raw', 'structured_raw']
|
||||||
|
|
||||||
def walk(base, value):
|
def walk(base, value):
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
|
@ -619,6 +619,10 @@ class LazyFieldVarStructured(LazyFieldVar):
|
||||||
|
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
|
@property
|
||||||
|
def structured_raw(self):
|
||||||
|
return self._field.get_structured_value(self._data)
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
try:
|
try:
|
||||||
return super(LazyFieldVarStructured, self).__getitem__(key)
|
return super(LazyFieldVarStructured, self).__getitem__(key)
|
||||||
|
|
Loading…
Reference in New Issue