From 535169823073b70dbd56e406140a329044755277 Mon Sep 17 00:00:00 2001 From: axolotle Date: Fri, 7 Apr 2023 17:03:03 +0200 Subject: [PATCH] form: rename ARGUMENTS_TYPE_PARSERS to OPTIONS --- src/tests/test_questions.py | 4 ++-- src/utils/configpanel.py | 10 ++++------ src/utils/form.py | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/tests/test_questions.py b/src/tests/test_questions.py index 7579355bd..190eb0cba 100644 --- a/src/tests/test_questions.py +++ b/src/tests/test_questions.py @@ -15,7 +15,7 @@ from _pytest.mark.structures import ParameterSet from moulinette import Moulinette from yunohost import app, domain, user from yunohost.utils.form import ( - ARGUMENTS_TYPE_PARSERS, + OPTIONS, ask_questions_and_parse_answers, DisplayTextOption, PasswordOption, @@ -440,7 +440,7 @@ class BaseTest: is_special_readonly_option = isinstance(option, DisplayTextOption) - assert isinstance(option, ARGUMENTS_TYPE_PARSERS[raw_option["type"]]) + assert isinstance(option, OPTIONS[raw_option["type"]]) assert option.type == raw_option["type"] assert option.name == id_ assert option.ask == {"en": id_} diff --git a/src/utils/configpanel.py b/src/utils/configpanel.py index c75311a56..c4edd5259 100644 --- a/src/utils/configpanel.py +++ b/src/utils/configpanel.py @@ -36,7 +36,7 @@ from moulinette.utils.filesystem import ( from yunohost.utils.i18n import _value_for_locale from yunohost.utils.error import YunohostError, YunohostValidationError from yunohost.utils.form import ( - ARGUMENTS_TYPE_PARSERS, + OPTIONS, FileOption, BaseOption, ask_questions_and_parse_answers, @@ -127,7 +127,7 @@ class ConfigPanel: option_type = None for _, _, option_ in self._iterate(): if option_["id"] == option: - option_type = ARGUMENTS_TYPE_PARSERS[option_["type"]] + option_type = OPTIONS[option_["type"]] break return option_type.normalize(value) if option_type else value @@ -152,7 +152,7 @@ class ConfigPanel: if mode == "full": option["ask"] = ask - question_class = ARGUMENTS_TYPE_PARSERS[option.get("type", "string")] + question_class = OPTIONS[option.get("type", "string")] # FIXME : maybe other properties should be taken from the question, not just choices ?. option["choices"] = question_class(option).choices option["default"] = question_class(option).default @@ -160,9 +160,7 @@ class ConfigPanel: else: result[key] = {"ask": ask} if "current_value" in option: - question_class = ARGUMENTS_TYPE_PARSERS[ - option.get("type", "string") - ] + question_class = OPTIONS[option.get("type", "string")] result[key]["value"] = question_class.humanize( option["current_value"], option ) diff --git a/src/utils/form.py b/src/utils/form.py index 1a1b8d47e..82cb23afb 100644 --- a/src/utils/form.py +++ b/src/utils/form.py @@ -906,7 +906,7 @@ class ButtonOption(BaseOption): self.enabled = question.get("enabled", None) -ARGUMENTS_TYPE_PARSERS = { +OPTIONS = { "string": StringOption, "text": StringOption, "select": StringOption, @@ -969,7 +969,7 @@ def ask_questions_and_parse_answers( for name, raw_question in raw_questions.items(): raw_question["name"] = name - question_class = ARGUMENTS_TYPE_PARSERS[raw_question.get("type", "string")] + question_class = OPTIONS[raw_question.get("type", "string")] raw_question["value"] = answers.get(name) question = question_class(raw_question, context=context, hooks=hooks) if question.type == "button": @@ -996,7 +996,7 @@ def hydrate_questions_with_choices(raw_questions: List) -> List: out = [] for raw_question in raw_questions: - question = ARGUMENTS_TYPE_PARSERS[raw_question.get("type", "string")]( + question = OPTIONS[raw_question.get("type", "string")]( raw_question ) if question.choices: