mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Fix weird definition for boolean's humanize/normalize
This commit is contained in:
parent
8ea160b9fe
commit
78ad3b5da3
1 changed files with 31 additions and 28 deletions
|
@ -740,25 +740,21 @@ class BooleanQuestion(Question):
|
||||||
|
|
||||||
yes = option.get("yes", 1)
|
yes = option.get("yes", 1)
|
||||||
no = option.get("no", 0)
|
no = option.get("no", 0)
|
||||||
value = str(value).lower()
|
|
||||||
if value == str(yes).lower():
|
|
||||||
return "yes"
|
|
||||||
if value == str(no).lower():
|
|
||||||
return "no"
|
|
||||||
if value in BooleanQuestion.yes_answers:
|
|
||||||
return "yes"
|
|
||||||
if value in BooleanQuestion.no_answers:
|
|
||||||
return "no"
|
|
||||||
|
|
||||||
if value in ["none", ""]:
|
value = BooleanQuestion.normalize(value, option)
|
||||||
|
|
||||||
|
if value == yes:
|
||||||
|
return "yes"
|
||||||
|
if value == no:
|
||||||
|
return "no"
|
||||||
|
if value is None:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
raise YunohostValidationError(
|
raise YunohostValidationError(
|
||||||
"app_argument_choice_invalid",
|
"app_argument_choice_invalid",
|
||||||
name=getattr(option, "name", None) or option.get("name"),
|
name=getattr(option, "name", None) or option.get("name"),
|
||||||
value=value,
|
value=value,
|
||||||
# FIXME : this doesn't match yes_answers / no_answers...
|
choices="yes/no",
|
||||||
choices="yes, no, y, n, 1, 0",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -769,31 +765,38 @@ class BooleanQuestion(Question):
|
||||||
yes = option.get("yes", 1)
|
yes = option.get("yes", 1)
|
||||||
no = option.get("no", 0)
|
no = option.get("no", 0)
|
||||||
|
|
||||||
#
|
strvalue = str(value).lower()
|
||||||
# FIXME: Shouldn't we also check that value == yes ?
|
|
||||||
# Otherwise is yes = "foobar", normalize is not idempotent
|
|
||||||
# i.e normalize("true") will return "foobar"
|
|
||||||
# but normalize(normalize("true")) will raise an exception ?
|
|
||||||
#
|
|
||||||
# FIXME: it's also a bit confusing to understand if the
|
|
||||||
# packager-provided 'yes' value is meant for humans (in which case
|
|
||||||
# shouldn't it be used as a return value for humanize?)
|
|
||||||
# or as an internal value for better interfacing with scripts/computers
|
|
||||||
#
|
|
||||||
# Also shouldnt we be using normalize() in humanize() ?
|
|
||||||
if str(value).lower() in BooleanQuestion.yes_answers:
|
|
||||||
return yes
|
|
||||||
|
|
||||||
if str(value).lower() in BooleanQuestion.no_answers:
|
#
|
||||||
|
# N.B.:
|
||||||
|
# we check first if the value is equal to yes
|
||||||
|
# then if equal to no
|
||||||
|
# then if in yes_answers
|
||||||
|
# then if in no_answers
|
||||||
|
#
|
||||||
|
# This is to hopefully cover the weird edgecase
|
||||||
|
# where the value for yes/no could be reversed
|
||||||
|
# such as yes=false or yes=0
|
||||||
|
# no=true no=1
|
||||||
|
#
|
||||||
|
|
||||||
|
if strvalue == str(yes).lower():
|
||||||
|
return yes
|
||||||
|
if strvalue == str(no).lower():
|
||||||
|
return no
|
||||||
|
if strvalue in BooleanQuestion.yes_answers:
|
||||||
|
return yes
|
||||||
|
if strvalue in BooleanQuestion.no_answers:
|
||||||
return no
|
return no
|
||||||
|
|
||||||
if value in [None, ""]:
|
if value in [None, ""]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
raise YunohostValidationError(
|
raise YunohostValidationError(
|
||||||
"app_argument_choice_invalid",
|
"app_argument_choice_invalid",
|
||||||
name=getattr(option, "name", None) or option.get("name"),
|
name=getattr(option, "name", None) or option.get("name"),
|
||||||
value=value,
|
value=value,
|
||||||
choices="yes, no, y, n, 1, 0",
|
choices="yes/no",
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, question, user_answers):
|
def __init__(self, question, user_answers):
|
||||||
|
|
Loading…
Add table
Reference in a new issue