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 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_}

View file

@ -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
)

View file

@ -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: