Skip to content

Commit

Permalink
feat: modify remove_jinja_braces method in DataTable Manager
Browse files Browse the repository at this point in the history
Signed-off-by: seolmin <[email protected]>
  • Loading branch information
stat-kwon committed Nov 5, 2024
1 parent 0c9c1c5 commit a6ee520
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/spaceone/dashboard/manager/data_table_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,26 +361,26 @@ def change_global_variables(self, expression: str, vars: dict):

@staticmethod
def remove_jinja_braces(expression: str) -> Union[str, float, list]:
if re.match(r"{{\s*(\w+)\s*}}", expression):
return re.sub(r"{{\s*(\w+)\s*}}", r"\1", expression)
elif re.match(r"{{\s*(\d+(\.\d+)?)\s*}}", expression):
result = re.sub(r"{{\s*(\d+(\.\d+)?)\s*}}", r"\1", expression)
try:
return float(result)
except ValueError:
return eval(result)
else:
expression = expression.replace("{{", "").replace("}}", "").strip()

pattern = r"\[\d+\]$"
if re.search(pattern, expression):
dict_expression, _ = re.subn(pattern, "", expression)
index_str = expression.replace(dict_expression, "").strip()
index_str = index_str.replace("[", "").replace("]", "")
index = int(index_str)
return ast.literal_eval(dict_expression)[index]

return ast.literal_eval(expression)
while "{{" in expression and "}}" in expression:
if re.match(r"{{\s*(\w+)\s*}}", expression):
expression = re.sub(r"{{\s*(\w+)\s*}}", r"\1", expression)
elif re.match(r"{{\s*(\d+(\.\d+)?)\s*}}", expression):
result = re.sub(r"{{\s*(\d+(\.\d+)?)\s*}}", r"\1", expression)
try:
expression = float(result)
except ValueError:
expression = eval(result)
else:
expression = expression.replace("{{", "").replace("}}", "").strip()

pattern = r"\[\d+\]$"
if re.search(pattern, expression):
dict_expression, _ = re.subn(pattern, "", expression)
index_str = expression.replace(dict_expression, "").strip()
index_str = index_str.replace("[", "").replace("]", "")
index = int(index_str)
expression = ast.literal_eval(dict_expression)[index]
return expression

@staticmethod
def change_expression_data_type(expression: str, gv_type_map: dict) -> str:
Expand Down

0 comments on commit a6ee520

Please sign in to comment.