form: skip over None variables when computing autocomplete variadic URL (#8631)

This commit is contained in:
Frédéric Péters 2015-10-15 16:38:57 +02:00
parent 39a88562d9
commit f3cfe17d58
2 changed files with 21 additions and 0 deletions

View File

@ -1343,3 +1343,20 @@ def test_form_middle_session_change(pub):
resp = resp.forms[0].submit('submit')
resp = resp.follow()
assert 'Sorry, your session have been lost.' in resp.body
def test_form_autocomplete_variadic_url(pub):
formdef = create_formdef()
formdef.fields = [fields.PageField(id='0', label='1st page', type='page'),
fields.ItemField(id='1', label='string', type='item',
varname='foo', items=['Foo', 'Bar']),
fields.StringField(id='2', label='string2',
data_source={'type': 'jsonp', 'value': '[var_foo]'}),
fields.PageField(id='3', label='2nd page', type='page',
condition='foo == "Foo"'),
]
formdef.store()
formdef.data_class().wipe()
resp = get_app(pub).get('/test/')
# test javascript will be used to compute the full URL
assert 'options.wcs_base_url' in resp.body

View File

@ -1671,6 +1671,8 @@ $("#form_%(id)s").select2({
if '[' in self.url:
vars = get_publisher().substitutions.get_context_variables()
# skip variables that were not set (None)
vars = dict((x, y) for x, y in vars.items() if y is not None)
url = misc.get_variadic_url(self.url, vars, encode_query=False)
else:
url = self.url
@ -1770,6 +1772,8 @@ class AutocompleteStringWidget(WcsExtraStringWidget):
if '[' in self.url:
vars = get_publisher().substitutions.get_context_variables()
# skip variables that were not set (None)
vars = dict((x, y) for x, y in vars.items() if y is not None)
url = misc.get_variadic_url(self.url, vars, encode_query=False)
else:
url = self.url