[17] fix conditionals

This commit is contained in:
meisnate12 2022-07-11 02:23:46 -04:00
parent c57497ba15
commit 397621df3a
2 changed files with 25 additions and 24 deletions

View file

@ -1 +1 @@
1.17.1-develop16
1.17.1-develop17

View file

@ -156,7 +156,6 @@ class DataFile:
for key, value in variables.copy().items():
variables[f"{key}_encoded"] = requests.utils.quote(str(value))
conditional = {}
default = {}
def add_default(d_key, d_value):
for v_key, v_value in variables.items():
@ -165,6 +164,15 @@ class DataFile:
default[d_key] = d_value
default[f"{d_key}_encoded"] = requests.utils.quote(str(d_value))
def small_var_check(var_check):
for var_k, var_v in variables.items():
if f"<<{var_k}>>" in str(var_check):
var_check = str(var_check).replace(f"<<{var_k}>>", str(var_v))
for var_k, var_v in default.items():
if f"<<{var_k}>>" in str(var_check):
var_check = str(var_check).replace(f"<<{var_k}>>", str(var_v))
return var_check
if "default" in template:
if not template["default"]:
raise Failed(f"{self.data_type} Error: template sub-attribute default is blank")
@ -177,13 +185,6 @@ class DataFile:
final_key = final_key.replace(f"<<{k}>>", str(v))
if final_key not in optional:
final_value = template["default"][dv]
if isinstance(final_value, dict):
if "variable" not in final_value:
raise Failed(f"{self.data_type} Error: variable sub-attribute required when the default variable is a dictionary")
if "values" not in final_value:
raise Failed(f"{self.data_type} Error: values sub-attribute required when the default variable is a dictionary")
conditional[final_key] = final_value
else:
add_default(final_key, final_value)
if "optional" in template:
@ -208,9 +209,7 @@ class DataFile:
for con_key, con_value in template["conditionals"].items():
if not isinstance(con_value, dict):
raise Failed(f"{self.data_type} Error: template sub-attribute conditionals is not a dictionary")
for k, v in variables.items():
if f"<<{k}>>" in con_key:
con_key = con_key.replace(f"<<{k}>>", str(v))
con_key = small_var_check(con_key)
if con_key in variables:
continue
if "conditions" not in con_value:
@ -227,17 +226,19 @@ class DataFile:
if "value" not in condition:
raise Failed(f"{self.data_type} Error: each condition must have a result value")
condition_passed = True
for var_key, var_value in condition:
for var_key, var_value in condition.items():
if var_key == "value":
continue
for k, v in variables.items():
if f"<<{k}>>" in var_key:
var_key = var_key.replace(f"<<{k}>>", str(v))
if f"<<{k}>>" in str(var_value):
var_value = str(var_value).replace(f"<<{k}>>", str(v))
if var_key not in variables or \
(not isinstance(var_value, list) and variables[var_key] != var_value) or \
(isinstance(var_value, list) and variables[var_key] not in var_value):
var_key = small_var_check(var_key)
var_value = small_var_check(var_value)
if var_key in variables:
if (isinstance(var_value, list) and variables[var_key] not in var_value) or \
(not isinstance(var_value, list) and variables[var_key] != var_value):
condition_passed = False
break
elif var_key in default:
if (isinstance(var_value, list) and default[var_key] not in var_value) or \
(not isinstance(var_value, list) and default[var_key] != var_value):
condition_passed = False
break
if condition_passed: