6 Commits

2 changed files with 31 additions and 17 deletions

View File

@ -1,5 +1,5 @@
from .api import Config
__version__ = "0.2"
__version__ = "0.5"
__all__ = ('Config',)

View File

@ -26,7 +26,8 @@ TYPE = {'boolean': bool,
'broadcast_address': str,
'port': str,
'domainname': str,
'date': str}
'date': str,
'float': float}
class Option:
@ -225,13 +226,14 @@ class _Value:
withwarning: bool=False,
flatten: bool=False):
ret = {}
self._dict_walk(ret,
self.schema,
self.path,
fullpath,
withwarning,
flatten,
None)
if self.schema:
self._dict_walk(ret,
self.schema,
self.path,
fullpath,
withwarning,
flatten,
None)
return ret
@ -326,11 +328,11 @@ class TiramisuOptionValue(_Value):
def set(self, value):
type_ = self.schema['type']
leader_old_value = undefined
if self.config.is_hidden(self.path, self.index):
remote = self.config.form.get(self.path, {}).get('remote', False)
if not remote and self.config.is_hidden(self.path, self.index):
raise PropertiesOptionError(None, {'disabled'}, None, opt_type='option')
if self.config.isleader(self.path):
leader_old_value = self.config.get_value(self.path)
remote = self.config.form.get(self.path, {}).get('remote', False)
if self.index is None and self.schema.get('isMulti', False):
if not isinstance(value, list):
raise ValueError('value must be a list')
@ -574,7 +576,7 @@ class ContextOption(_Option):
schema: Dict) -> None:
self.config = config
self.schema = {'properties': schema}
self.index = None
self.index = None
def __call__(self,
path: str,
@ -597,7 +599,7 @@ class ContextOwner:
schema: Dict) -> None:
self.config = config
self.schema = {'properties': schema}
self.index = None
self.index = None
def get(self):
return self.config.global_model.get('owner', 'tmp')
@ -609,9 +611,12 @@ class ContextValue(_Value):
config: 'Config',
schema: Dict) -> None:
self.config = config
first = next(iter(schema.keys()))
self.path = first.rsplit('.', 1)[0]
self.schema = {'properties': schema}
if schema:
first = next(iter(schema.keys()))
self.path = first.rsplit('.', 1)[0]
self.schema = {'properties': schema}
else:
self.schema = {}
def __call__(self) -> TiramisuOptionValue:
return TiramisuOptionValue(self.config,
@ -644,6 +649,7 @@ class Config:
# config
def __init__(self,
dico):
self._unrestraint = False
if DEBUG:
from pprint import pprint
pprint(dico)
@ -668,6 +674,7 @@ class Config:
self.root = first_path.rsplit('.', 1)[0]
else:
self.root = ''
self.dico = dico
def __getattr__(self,
subfunc: str) -> Any:
@ -682,6 +689,11 @@ class Config:
if subfunc == 'owner':
return ContextOwner(self,
self.schema)
if subfunc == 'unrestraint':
ret = Config(self.dico)
ret._unrestraint = True
ret.temp = self.temp
return ret
raise APIError(_('please specify a valid sub function ({})').format(subfunc))
def add_value(self,
@ -847,6 +859,8 @@ class Config:
path: str,
index: Optional[int],
permissive: bool=False) -> bool:
if self._unrestraint:
return False
if permissive:
property_ = 'hidden'
needs = True
@ -1181,7 +1195,7 @@ class Config:
value: Any) -> bool:
if not path in self.form or not 'pattern' in self.form[path]:
return True
if value is None or value is '':
if value is None or value == '':
match = True
else:
if isinstance(value, int):