mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
form: add fancy separators
This commit is contained in:
parent
e4a0ad35ce
commit
dc99febe4c
1 changed files with 52 additions and 0 deletions
|
@ -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]] = {},
|
||||
|
|
Loading…
Add table
Reference in a new issue