This commit is contained in:
Emmanuel Garette 2020-10-05 21:16:41 +02:00
parent a269cbcc93
commit e1fef11465

View file

@ -76,17 +76,18 @@ class ChoiceOption(Option):
if isinstance(self._choice_values, Calculation): if isinstance(self._choice_values, Calculation):
return return
values = self._choice_values values = self._choice_values
if values is not undefined and value not in values: self.validate_values(value, values)
if len(values) == 1:
raise ValueError(_('only "{0}" is allowed'
'').format(values[0]))
raise ValueError(_('only {0} are allowed'
'').format(display_list(values, add_quote=True)))
async def validate_with_option(self, async def validate_with_option(self,
value: Any, value: Any,
option_bag: OptionBag) -> None: option_bag: OptionBag) -> None:
values = await self.impl_get_values(option_bag) values = await self.impl_get_values(option_bag)
self.validate_values(value, values)
def validate_values(self,
value,
values,
) -> None:
if values is not undefined and value not in values: if values is not undefined and value not in values:
if len(values) == 1: if len(values) == 1:
raise ValueError(_('only "{0}" is allowed' raise ValueError(_('only "{0}" is allowed'