validation value when set value
This commit is contained in:
parent
de0d40efbb
commit
814c8ca96b
|
@ -8,6 +8,11 @@ from .setting import undefined
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TYPE = {'boolean': bool,
|
||||||
|
'number': int,
|
||||||
|
'string': str}
|
||||||
|
|
||||||
class Option:
|
class Option:
|
||||||
# fake Option (IntOption, StrOption, ...)
|
# fake Option (IntOption, StrOption, ...)
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
|
@ -237,6 +242,11 @@ class TiramisuOptionValue(_Value):
|
||||||
return self.schema['enum']
|
return self.schema['enum']
|
||||||
|
|
||||||
def set(self, value):
|
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.config.modify_value(self.path,
|
||||||
self.index,
|
self.index,
|
||||||
value,
|
value,
|
||||||
|
|
Loading…
Reference in New Issue