Do not count template variables as prompted

This commit is contained in:
AlanCoding
2018-11-13 10:04:44 -05:00
committed by Jake McDermott
parent 89a0be64af
commit c105885c7b
2 changed files with 58 additions and 2 deletions

View File

@@ -301,6 +301,13 @@ class SurveyJobTemplateMixin(models.Model):
accepted.update(extra_vars)
extra_vars = {}
if extra_vars:
# Prune the prompted variables for those identical to template
tmp_extra_vars = self.extra_vars_dict
for key in (set(tmp_extra_vars.keys()) & set(extra_vars.keys())):
if tmp_extra_vars[key] == extra_vars[key]:
extra_vars.pop(key)
if extra_vars:
# Leftover extra_vars, keys provided that are not allowed
rejected.update(extra_vars)
@@ -308,7 +315,7 @@ class SurveyJobTemplateMixin(models.Model):
if 'prompts' not in _exclude_errors:
errors['extra_vars'] = [_('Variables {list_of_keys} are not allowed on launch. Check the Prompt on Launch setting '+
'on the Job Template to include Extra Variables.').format(
list_of_keys=', '.join(extra_vars.keys()))]
list_of_keys=six.text_type(', ').join([six.text_type(key) for key in extra_vars.keys()]))]
return (accepted, rejected, errors)