0001-fields-add-access-to-raw-structured-values-40203.patch
tests/test_formdata.py | ||
---|---|---|
1780 | 1780 |
assert tmpl.render(context) == 'bar' |
1781 | 1781 |
tmpl = Template('{{ form_var_plop_1_url }}') |
1782 | 1782 |
assert tmpl.render(context) == 'yyy' |
1783 |
tmpl = Template('{% for x in form_var_plop_structured_raw %}{{x.more}}{% endfor %}') |
|
1784 |
assert tmpl.render(context) == 'foobar' |
|
1783 | 1785 | |
1784 | 1786 |
assert 'form_var_plop_0_url' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys() |
1785 | 1787 |
assert 'form_var_plop_1_more' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys() |
1788 |
assert 'form_var_plop_structured_raw' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys() |
|
1786 | 1789 | |
1787 | 1790 | |
1788 | 1791 |
def test_formdata_user_field(pub, variable_test_data): |
wcs/formdata.py | ||
---|---|---|
93 | 93 |
if k in ('id', 'text'): |
94 | 94 |
continue |
95 | 95 |
new_data['var_%s_%s_%s' % (field.varname, i, k)] = v |
96 |
new_data['var_%s_structured_raw' % field.varname] = structured_value |
|
96 | 97 |
return new_data |
97 | 98 | |
98 | 99 |
wcs/variables.py | ||
---|---|---|
610 | 610 |
if not structured_value: |
611 | 611 |
return [] |
612 | 612 | |
613 |
keys = ['raw'] |
|
613 |
keys = ['raw', 'structured_raw']
|
|
614 | 614 | |
615 | 615 |
def walk(base, value): |
616 | 616 |
if isinstance(value, dict): |
... | ... | |
627 | 627 | |
628 | 628 |
return keys |
629 | 629 | |
630 |
@property |
|
631 |
def structured_raw(self): |
|
632 |
return self._field.get_structured_value(self._data) |
|
633 | ||
630 | 634 |
def __getitem__(self, key): |
631 | 635 |
try: |
632 | 636 |
return super(LazyFieldVarStructured, self).__getitem__(key) |
633 |
- |