From 655bebd0a820ca584af9426f5bba76920f12d69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 4 Feb 2016 18:15:49 +0100 Subject: [PATCH] misc: don't feed var_-prefixed variables into the substitution system (#9786) They are only created for backward-compatibility when evaluating conditions and interfere with variadic URLs that may be used for dynamic jsonp-based fields. --- tests/test_form_pages.py | 12 +++++++++--- wcs/fields.py | 23 +++++++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py index 5d98d3d..af812b3 100644 --- a/tests/test_form_pages.py +++ b/tests/test_form_pages.py @@ -1997,20 +1997,26 @@ def test_form_middle_session_change(pub): def test_form_autocomplete_variadic_url(pub): formdef = create_formdef() formdef.fields = [fields.PageField(id='0', label='1st page', type='page'), + fields.PageField(id='3', label='2nd page', type='page', condition="True"), fields.ItemField(id='1', label='string', type='item', varname='foo', items=['Foo', 'Bar']), - fields.StringField(id='2', label='string2', + fields.StringField(id='2', label='string2', required=True, data_source={'type': 'jsonp', 'value': '[var_foo]'}), - fields.PageField(id='3', label='2nd page', type='page', - condition='foo == "Foo"'), + fields.PageField(id='4', label='3rd page', type='page', condition="True") ] formdef.store() formdef.data_class().wipe() resp = get_app(pub).get('/test/') + resp = resp.form.submit('submit') # next # test javascript will be used to compute the full URL assert 'options.wcs_base_url' in resp.body + # test going forward (will error out), check it's still a variadic URL (#9786) + resp.form['f1'] = 'Foo' + resp = resp.form.submit('submit') + assert 'options.wcs_base_url' in resp.body + def test_form_page_formula_prefill_user_name(pub): user = create_user(pub) formdef = create_formdef() diff --git a/wcs/fields.py b/wcs/fields.py index 53446f4..e76dd5f 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -1341,27 +1341,30 @@ class PageField(Field): def add_to_view_form(self, *args): pass - def evaluate_condition(self, dict, formdef, condition): + def evaluate_condition(self, dict_vars, formdef, condition): if not condition: return True # create variables with values currently being evaluated, not yet - # available in the formdata, keep them as var_xxx for compatibility, - # and add them as form_var_xxx. + # available in the formdata. from formdata import get_dict_with_varnames - live_data = get_dict_with_varnames(formdef.fields, dict) - for k, v in live_data.items(): - live_data['form_' + k] = v + live_data = get_dict_with_varnames(formdef.fields, dict_vars) + form_live_data = dict(('form_' + x, y) for x, y in live_data.items()) - # and feed those new variables in the global substitution system, they - # will shadow formdata context variables with their new "live" value, - # this may be useful when evaluating data sources. + # 1) feed the form_var_* variables in the global substitution system, + # they # will shadow formdata context variables with their new "live" + # value, this may be useful when evaluating data sources. class ConditionVars(object): def get_substitution_variables(self): - return live_data + return form_live_data get_publisher().substitutions.feed(ConditionVars()) data = get_publisher().substitutions.get_context_variables() + # 2) add live data as var_ variables for local evaluation only, for + # backward compatibility. They are not added globally as they would + # interfere with the var_ prefixed variables used in dynamic jsonp + # fields. (#9786) + data.update(live_data) try: if eval(condition, get_publisher().get_global_eval_dict(), data): -- 2.7.0