mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
form: add "mode" to BaseOption to distinguish "bash" and "python" serialization
This commit is contained in:
parent
566f5d29a7
commit
64e2c3177c
1 changed files with 11 additions and 1 deletions
|
@ -296,6 +296,7 @@ Context = dict[str, Any]
|
|||
Translation = Union[dict[str, str], str]
|
||||
JSExpression = str
|
||||
Values = dict[str, Any]
|
||||
Mode = Literal["python", "bash"]
|
||||
|
||||
|
||||
class Pattern(BaseModel):
|
||||
|
@ -359,6 +360,7 @@ class BaseOption(BaseModel):
|
|||
|
||||
type: OptionType
|
||||
id: str
|
||||
mode: Mode = "bash" # TODO use "python" as default mode with AppConfigPanel setuping it to "bash"
|
||||
ask: Union[Translation, None]
|
||||
readonly: bool = False
|
||||
visible: Union[JSExpression, bool] = True
|
||||
|
@ -627,6 +629,13 @@ class BaseInputOption(BaseOption):
|
|||
"""
|
||||
return self._annotation
|
||||
|
||||
@property
|
||||
def _validators(self) -> dict[str, Callable]:
|
||||
return {
|
||||
"pre": self._value_pre_validator,
|
||||
"post": self._value_post_validator,
|
||||
}
|
||||
|
||||
def _get_field_attrs(self) -> dict[str, Any]:
|
||||
"""
|
||||
Returns attributes to build a `pydantic.Field`.
|
||||
|
@ -1886,11 +1895,12 @@ def build_form(
|
|||
continue # filter out non input options
|
||||
|
||||
options_as_fields[option.id] = option._as_dynamic_model_field()
|
||||
option_validators = option._validators
|
||||
|
||||
for step in ("pre", "post"):
|
||||
validators[f"{option.id}_{step}_validator"] = validator(
|
||||
option.id, allow_reuse=True, pre=step == "pre"
|
||||
)(getattr(option, f"_value_{step}_validator"))
|
||||
)(option_validators[step])
|
||||
|
||||
return cast(
|
||||
Type[FormModel],
|
||||
|
|
Loading…
Add table
Reference in a new issue