some improvments
This commit is contained in:
parent
140fa03592
commit
5c49a4018a
|
@ -11,10 +11,14 @@ from .i18n import _
|
||||||
|
|
||||||
TYPE = {'boolean': bool,
|
TYPE = {'boolean': bool,
|
||||||
'number': int,
|
'number': int,
|
||||||
'string': str}
|
'string': str,
|
||||||
|
'password': str,
|
||||||
|
'domain': str}
|
||||||
|
|
||||||
|
|
||||||
class Option:
|
class Option:
|
||||||
# fake Option (IntOption, StrOption, ...)
|
# fake Option (IntOption, StrOption, ...)
|
||||||
|
# only usefull for warnings
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
name,
|
name,
|
||||||
path):
|
path):
|
||||||
|
@ -24,9 +28,6 @@ class Option:
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def impl_get_display_name(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def impl_getpath(self):
|
def impl_getpath(self):
|
||||||
return self.path
|
return self.path
|
||||||
|
|
||||||
|
@ -252,17 +253,29 @@ class TiramisuOptionValue(_Value):
|
||||||
def list(self):
|
def list(self):
|
||||||
return self.schema['enum']
|
return self.schema['enum']
|
||||||
|
|
||||||
def set(self, value):
|
def _validate(self, type_, value):
|
||||||
if self.schema['type'] == 'choice':
|
if value in [None, undefined]:
|
||||||
|
return
|
||||||
|
if type_ == 'choice':
|
||||||
if value not in self.schema['enum']:
|
if value not in self.schema['enum']:
|
||||||
raise Exception('value {} is not in {}'.format(value, self.schema['enum']))
|
raise Exception('value {} is not in {}'.format(value, self.schema['enum']))
|
||||||
elif not isinstance(value, TYPE[self.schema['type']]):
|
elif not isinstance(value, TYPE[type_]):
|
||||||
raise Exception('value {} is not a valid {} '.format(value, self.schema['type']))
|
raise Exception('value {} is not a valid {} '.format(value, type_))
|
||||||
|
|
||||||
|
def set(self, value):
|
||||||
|
type_ = self.schema['type']
|
||||||
|
if self.schema.get('isMulti', False):
|
||||||
|
if not isinstance(value, list):
|
||||||
|
raise Exception('value must be a list')
|
||||||
|
for val in value:
|
||||||
|
self._validate(type_, val)
|
||||||
|
else:
|
||||||
|
self._validate(type_, value)
|
||||||
self.config.modify_value(self.path,
|
self.config.modify_value(self.path,
|
||||||
self.index,
|
self.index,
|
||||||
value,
|
value,
|
||||||
self.form.get(self.path, {}).get('remote', False))
|
self.form.get(self.path, {}).get('remote', False))
|
||||||
self._display_warnings(self.path, value, self.schema['type'], self.schema['name'])
|
self._display_warnings(self.path, value, type_, self.schema['name'])
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.config.delete_value(self.path,
|
self.config.delete_value(self.path,
|
||||||
|
@ -326,12 +339,20 @@ class TiramisuOptionDescription(_Option):
|
||||||
self.form)
|
self.form)
|
||||||
if subfunc == 'property':
|
if subfunc == 'property':
|
||||||
return TiramisuOptionProperty(self.model.get(self.path, {}))
|
return TiramisuOptionProperty(self.model.get(self.path, {}))
|
||||||
|
if subfunc == 'value':
|
||||||
|
return TiramisuOptionValue(self.config,
|
||||||
|
self.schema,
|
||||||
|
self.model,
|
||||||
|
self.form,
|
||||||
|
self.temp,
|
||||||
|
self.path,
|
||||||
|
self.index)
|
||||||
raise APIError(_('please specify a valid sub function ({})').format(subfunc))
|
raise APIError(_('please specify a valid sub function ({})').format(subfunc))
|
||||||
|
|
||||||
def group_type(self):
|
def group_type(self):
|
||||||
hidden = self.temp.get(key, {}).get('hidden', None)
|
hidden = self.temp.get(self.path, {}).get('hidden', None)
|
||||||
model_hidden = not self.model.get(key, {}).get('hidden', False) and \
|
model_hidden = not self.model.get(self.path, {}).get('hidden', False) and \
|
||||||
self.model.get(key, {}).get('display', True)
|
self.model.get(self.path, {}).get('display', True)
|
||||||
if hidden is False or (hidden is None and model_hidden):
|
if hidden is False or (hidden is None and model_hidden):
|
||||||
# FIXME
|
# FIXME
|
||||||
return 'default'
|
return 'default'
|
||||||
|
@ -560,7 +581,8 @@ class Config:
|
||||||
def get_schema(self,
|
def get_schema(self,
|
||||||
path):
|
path):
|
||||||
root_path = self.root
|
root_path = self.root
|
||||||
schema = {'properties': self.schema}
|
schema = {'properties': self.schema,
|
||||||
|
'type': 'object'}
|
||||||
if root_path:
|
if root_path:
|
||||||
root = self.root.split('.')
|
root = self.root.split('.')
|
||||||
subpaths = path.split('.')[len(root):]
|
subpaths = path.split('.')[len(root):]
|
||||||
|
|
Loading…
Reference in New Issue