form: rename ARGUMENTS_TYPE_PARSERS to OPTIONS

This commit is contained in:
axolotle 2023-04-07 17:03:03 +02:00
parent f9fd379997
commit 5351698230
3 changed files with 9 additions and 11 deletions

View file

@ -15,7 +15,7 @@ from _pytest.mark.structures import ParameterSet
from moulinette import Moulinette from moulinette import Moulinette
from yunohost import app, domain, user from yunohost import app, domain, user
from yunohost.utils.form import ( from yunohost.utils.form import (
ARGUMENTS_TYPE_PARSERS, OPTIONS,
ask_questions_and_parse_answers, ask_questions_and_parse_answers,
DisplayTextOption, DisplayTextOption,
PasswordOption, PasswordOption,
@ -440,7 +440,7 @@ class BaseTest:
is_special_readonly_option = isinstance(option, DisplayTextOption) 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.type == raw_option["type"]
assert option.name == id_ assert option.name == id_
assert option.ask == {"en": id_} assert option.ask == {"en": id_}

View file

@ -36,7 +36,7 @@ from moulinette.utils.filesystem import (
from yunohost.utils.i18n import _value_for_locale from yunohost.utils.i18n import _value_for_locale
from yunohost.utils.error import YunohostError, YunohostValidationError from yunohost.utils.error import YunohostError, YunohostValidationError
from yunohost.utils.form import ( from yunohost.utils.form import (
ARGUMENTS_TYPE_PARSERS, OPTIONS,
FileOption, FileOption,
BaseOption, BaseOption,
ask_questions_and_parse_answers, ask_questions_and_parse_answers,
@ -127,7 +127,7 @@ class ConfigPanel:
option_type = None option_type = None
for _, _, option_ in self._iterate(): for _, _, option_ in self._iterate():
if option_["id"] == option: if option_["id"] == option:
option_type = ARGUMENTS_TYPE_PARSERS[option_["type"]] option_type = OPTIONS[option_["type"]]
break break
return option_type.normalize(value) if option_type else value return option_type.normalize(value) if option_type else value
@ -152,7 +152,7 @@ class ConfigPanel:
if mode == "full": if mode == "full":
option["ask"] = ask 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 ?. # FIXME : maybe other properties should be taken from the question, not just choices ?.
option["choices"] = question_class(option).choices option["choices"] = question_class(option).choices
option["default"] = question_class(option).default option["default"] = question_class(option).default
@ -160,9 +160,7 @@ class ConfigPanel:
else: else:
result[key] = {"ask": ask} result[key] = {"ask": ask}
if "current_value" in option: if "current_value" in option:
question_class = ARGUMENTS_TYPE_PARSERS[ question_class = OPTIONS[option.get("type", "string")]
option.get("type", "string")
]
result[key]["value"] = question_class.humanize( result[key]["value"] = question_class.humanize(
option["current_value"], option option["current_value"], option
) )

View file

@ -906,7 +906,7 @@ class ButtonOption(BaseOption):
self.enabled = question.get("enabled", None) self.enabled = question.get("enabled", None)
ARGUMENTS_TYPE_PARSERS = { OPTIONS = {
"string": StringOption, "string": StringOption,
"text": StringOption, "text": StringOption,
"select": StringOption, "select": StringOption,
@ -969,7 +969,7 @@ def ask_questions_and_parse_answers(
for name, raw_question in raw_questions.items(): for name, raw_question in raw_questions.items():
raw_question["name"] = name 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) raw_question["value"] = answers.get(name)
question = question_class(raw_question, context=context, hooks=hooks) question = question_class(raw_question, context=context, hooks=hooks)
if question.type == "button": if question.type == "button":
@ -996,7 +996,7 @@ def hydrate_questions_with_choices(raw_questions: List) -> List:
out = [] out = []
for raw_question in raw_questions: for raw_question in raw_questions:
question = ARGUMENTS_TYPE_PARSERS[raw_question.get("type", "string")]( question = OPTIONS[raw_question.get("type", "string")](
raw_question raw_question
) )
if question.choices: if question.choices: