validation value when set value

This commit is contained in:
Emmanuel Garette 2019-01-16 16:38:32 +01:00
parent de0d40efbb
commit 814c8ca96b

View File

@ -8,6 +8,11 @@ from .setting import undefined
from .i18n import _
TYPE = {'boolean': bool,
'number': int,
'string': str}
class Option:
# fake Option (IntOption, StrOption, ...)
def __init__(self,
@ -237,6 +242,11 @@ class TiramisuOptionValue(_Value):
return self.schema['enum']
def set(self, value):
if self.schema['type'] == 'choice':
if value not in self.schema['enum']:
raise Exception('value {} is not in {}'.format(value, self.schema['enum']))
elif not isinstance(value, TYPE[self.schema['type']]):
raise Exception('value {} is not a valid {} '.format(value, self.schema['type']))
self.config.modify_value(self.path,
self.index,
value,