From 837194f0bb57f1498702fcbdf96b1bc2384c7fb3 Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Wed, 27 Jan 2016 16:44:38 +0100 Subject: [PATCH] don't staticly replace [var_xxx] in jsonp url --- wcs/qommon/form.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wcs/qommon/form.py b/wcs/qommon/form.py index 5fc3adb..f26783b 100644 --- a/wcs/qommon/form.py +++ b/wcs/qommon/form.py @@ -1705,7 +1705,10 @@ $("#form_%(id)s").select2({ 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) + # skip variables that can be dynamic (name start with "var_") + no_dynamic_vars = dict((x, y) for x, y in vars.items() if not x.startswith('var_')) + url = misc.get_variadic_url(self.url, no_dynamic_vars, encode_query=False) + dynamic_vars = dict((x, y) for x, y in vars.items() if x.startswith('var_')) else: url = self.url @@ -1745,9 +1748,12 @@ $("#form_%(id)s").data('select2').opts.wcs_base_url = '%(url)s'; function url_replace_%(id)s() { var url = $("#form_%(id)s").data('select2').opts.wcs_base_url;""" % {'id': self.name}) for variable in variables: + default_value = dynamic_vars.get(variable + '_raw') or dynamic_vars.get(variable) or '' r += htmltext(""" selector = '#' + $('#%(variable)s').data('valuecontainerid'); - url = url.replace('[%(variable)s]', $(selector).val());""" % {'variable': variable}) + value = $(selector).val() || %(default_value)s; + url = url.replace('[%(variable)s]', value);""" % {'default_value': json.dumps(default_value), + 'variable': variable}) r += htmltext(""" $("#form_%(id)s").data('select2').opts.ajax.url = url; $("#form_%(id)s").data('select2').clear(); -- 2.7.0.rc3