Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change cache options when loading Widget resource #164

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/spaceone/dashboard/manager/data_table_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def load_from_widget(
column_sum: bool = False,
) -> dict:
query_data = self._prepare_query_data(
data_table_id, granularity, start, end, group_by, sort
data_table_id, granularity, start, end, group_by, sort, vars
)

cache_hash_key = utils.dict_to_hash(query_data)
Expand Down Expand Up @@ -323,15 +323,18 @@ def change_global_variables(self, expression: str, vars: dict):
return expression, gv_type_map

@staticmethod
def remove_jinja_braces(expression: str) -> Union[str, float, list]:
jinja_pattern = re.compile(r"\{\{\s*(.*?)\s*\}\}")

modified_expression = re.sub(
jinja_pattern,
lambda m: "{{" + m.group(1).replace(" ", "_") + "}}",
expression,
)
expression = modified_expression
def remove_jinja_braces(
expression: str,
gv_type_map: dict = None,
) -> Union[str, float, list]:
if not gv_type_map:
jinja_pattern = re.compile(r"\{\{\s*(.*?)\s*\}\}")
modified_expression = re.sub(
jinja_pattern,
lambda m: "{{" + m.group(1).replace(" ", "_") + "}}",
expression,
)
expression = modified_expression

while "{{" in expression and "}}" in expression:
if re.match(r"{{\s*(\w+)\s*}}", expression):
Expand Down Expand Up @@ -384,6 +387,7 @@ def _prepare_query_data(
end: str,
group_by: list,
sort: list,
vars: dict,
) -> dict:
user_id = self.transaction.get_meta(
"authorization.user_id"
Expand All @@ -399,6 +403,7 @@ def _prepare_query_data(
"data_table_id": data_table_id,
"widget_id": self.widget_id,
"domain_id": self.domain_id,
"vars": vars,
}

if role_type == "WORKSPACE_MEMBER":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def _make_query(
query_value, gv_type_map = self.change_global_variables(
query_value, vars
)
query_value = self.remove_jinja_braces(query_value)
query_value = self.remove_jinja_braces(query_value, gv_type_map)
if (
isinstance(query_value, str)
or isinstance(query_value, int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def query_data_table(
for condition in conditions:
if self.is_jinja_expression(condition):
condition, gv_type_map = self.change_global_variables(condition, vars)
condition = self.remove_jinja_braces(condition)
condition = self.remove_jinja_braces(condition, gv_type_map)
condition = self.change_expression_data_type(condition, gv_type_map)
condition = self.change_space_variable(condition)

Expand Down Expand Up @@ -295,15 +295,17 @@ def evaluate_data_table(
condition, gv_type_map = self.change_global_variables(
condition, vars
)
condition = self.remove_jinja_braces(condition)
condition = self.remove_jinja_braces(condition, gv_type_map)
condition = self.change_expression_data_type(condition, gv_type_map)
condition = self.change_space_variable(condition)

if self.is_jinja_expression(value_expression):
value_expression, gv_type_map = self.change_global_variables(
value_expression, vars
)
value_expression = self.remove_jinja_braces(value_expression)
value_expression = self.remove_jinja_braces(
value_expression, gv_type_map
)
value_expression = self.change_expression_data_type(
value_expression, gv_type_map
)
Expand Down Expand Up @@ -897,7 +899,7 @@ def filter_data(self, df: pd.DataFrame, vars: dict) -> pd.DataFrame:

if self.is_jinja_expression(condition):
condition, gv_type_map = self.change_global_variables(condition, vars)
condition = self.remove_jinja_braces(condition)
condition = self.remove_jinja_braces(condition, gv_type_map)
condition = self.change_expression_data_type(condition, gv_type_map)
condition = self.change_space_variable(condition)

Expand Down
Loading