From f2b95e5fbeabec1f4a99e81c6a93aac0b876223d Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Sun, 30 Jan 2022 20:45:06 +0000 Subject: [PATCH 1/2] configpanel: filter as a simple_js_expression --- share/config_domain.toml | 2 +- src/utils/config.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/share/config_domain.toml b/share/config_domain.toml index b0131f1c1..65e755365 100644 --- a/share/config_domain.toml +++ b/share/config_domain.toml @@ -14,7 +14,7 @@ i18n = "domain_config" [feature.app] [feature.app.default_app] type = "app" - filters = ["is_webapp"] + filter = "is_webapp" default = "_none" [feature.mail] diff --git a/src/utils/config.py b/src/utils/config.py index ab18a19b0..1e4f4cd1e 100644 --- a/src/utils/config.py +++ b/src/utils/config.py @@ -440,7 +440,7 @@ class ConfigPanel: "step", "accept", "redact", - "filters", + "filter", ], "defaults": {}, }, @@ -706,7 +706,7 @@ class Question: self.ask = question.get("ask", {"en": self.name}) self.help = question.get("help") self.redact = question.get("redact", False) - self.filters = question.get("filters", []) + self.filter = question.get("filter", []) # .current_value is the currently stored value self.current_value = question.get("current_value") # .value is the "proposed" value which we got from the user @@ -1142,12 +1142,12 @@ class AppQuestion(Question): super().__init__(question, context, hooks) apps = app_list(full=True)["apps"] - for _filter in self.filters: - apps = [app for app in apps if _filter in app and app[_filter]] + + apps = [app for app in apps if evaluate_simple_js_expression(self.filter, context=app)] def _app_display(app): - domain_path = f" ({app['domain_path']})" if "domain_path" in app else "" - return app["label"] + domain_path + domain_path_or_id = f" ({app.get('domain_path', app['id'])})" + return app["label"] + domain_path_or_id self.choices = {"_none": "---"} self.choices.update({app["id"]: _app_display(app) for app in apps}) From 3de3205648cdfaf530148defc51b58460e03ea10 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Sun, 30 Jan 2022 22:39:26 +0000 Subject: [PATCH 2/2] set default filter to always return true --- src/utils/config.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/config.py b/src/utils/config.py index 1e4f4cd1e..0b2aca414 100644 --- a/src/utils/config.py +++ b/src/utils/config.py @@ -706,7 +706,7 @@ class Question: self.ask = question.get("ask", {"en": self.name}) self.help = question.get("help") self.redact = question.get("redact", False) - self.filter = question.get("filter", []) + self.filter = question.get("filter", "true") # .current_value is the currently stored value self.current_value = question.get("current_value") # .value is the "proposed" value which we got from the user @@ -1142,8 +1142,9 @@ class AppQuestion(Question): super().__init__(question, context, hooks) apps = app_list(full=True)["apps"] - - apps = [app for app in apps if evaluate_simple_js_expression(self.filter, context=app)] + + if self.filter: + apps = [app for app in apps if evaluate_simple_js_expression(self.filter, context=app)] def _app_display(app): domain_path_or_id = f" ({app.get('domain_path', app['id'])})"