diff --git a/src/utils/form.py b/src/utils/form.py index 4c0f15710..df70b1695 100644 --- a/src/utils/form.py +++ b/src/utils/form.py @@ -40,6 +40,13 @@ from yunohost.log import OperationLogger logger = getActionLogger("yunohost.form") +# ╭───────────────────────────────────────────────────────╮ +# │ ┌─╴╷ ╷╭─┐╷ │ +# │ ├─╴│╭╯├─┤│ │ +# │ ╰─╴╰╯ ╵ ╵╰─╴ │ +# ╰───────────────────────────────────────────────────────╯ + + # Those js-like evaluate functions are used to eval safely visible attributes # The goal is to evaluate in the same way than js simple-evaluate # https://github.com/shepherdwind/simple-evaluate @@ -183,6 +190,13 @@ def evaluate_simple_js_expression(expr, context={}): return evaluate_simple_ast(node, context) +# ╭───────────────────────────────────────────────────────╮ +# │ ╭─╮┌─╮╶┬╴╶┬╴╭─╮╭╮╷╭─╴ │ +# │ │ │├─╯ │ │ │ ││││╰─╮ │ +# │ ╰─╯╵ ╵ ╶┴╴╰─╯╵╰╯╶─╯ │ +# ╰───────────────────────────────────────────────────────╯ + + class BaseOption: hide_user_input_in_prompt = False pattern: Optional[Dict] = None @@ -377,6 +391,11 @@ class BaseOption: return self.value +# ╭───────────────────────────────────────────────────────╮ +# │ DISPLAY OPTIONS │ +# ╰───────────────────────────────────────────────────────╯ + + class DisplayTextOption(BaseOption): argument_type = "display_text" @@ -418,6 +437,14 @@ class ButtonOption(BaseOption): self.enabled = question.get("enabled", None) +# ╭───────────────────────────────────────────────────────╮ +# │ INPUT OPTIONS │ +# ╰───────────────────────────────────────────────────────╯ + + +# ─ STRINGS ─────────────────────────────────────────────── + + class StringOption(BaseOption): argument_type = "string" default_value = "" @@ -461,6 +488,9 @@ class ColorOption(StringOption): } +# ─ NUMERIC ─────────────────────────────────────────────── + + class NumberOption(BaseOption): argument_type = "number" default_value = None @@ -514,6 +544,9 @@ class NumberOption(BaseOption): ) +# ─ BOOLEAN ─────────────────────────────────────────────── + + class BooleanOption(BaseOption): argument_type = "boolean" default_value = 0 @@ -604,6 +637,9 @@ class BooleanOption(BaseOption): return text_for_user_input_in_cli +# ─ TIME ────────────────────────────────────────────────── + + class DateOption(StringOption): pattern = { "regexp": r"^\d{4}-\d\d-\d\d$", @@ -629,6 +665,9 @@ class TimeOption(StringOption): } +# ─ LOCATIONS ───────────────────────────────────────────── + + class EmailOption(StringOption): pattern = { "regexp": r"^.+@.+", @@ -674,6 +713,9 @@ class URLOption(StringOption): } +# ─ FILE ────────────────────────────────────────────────── + + class FileOption(BaseOption): argument_type = "file" upload_dirs: List[str] = [] @@ -739,6 +781,9 @@ class FileOption(BaseOption): return self.value +# ─ CHOICES ─────────────────────────────────────────────── + + class TagsOption(BaseOption): argument_type = "tags" default_value = "" @@ -933,6 +978,13 @@ OPTIONS = { } +# ╭───────────────────────────────────────────────────────╮ +# │ ╷ ╷╶┬╴╶┬╴╷ ╭─╴ │ +# │ │ │ │ │ │ ╰─╮ │ +# │ ╰─╯ ╵ ╶┴╴╰─╴╶─╯ │ +# ╰───────────────────────────────────────────────────────╯ + + def ask_questions_and_parse_answers( raw_questions: Dict, prefilled_answers: Union[str, Mapping[str, Any]] = {},