hidden are now recursive + schema without root

This commit is contained in:
Emmanuel Garette 2019-01-12 17:33:26 +01:00
parent e1f62e8044
commit a91f32401a
1 changed files with 37 additions and 21 deletions

View File

@ -237,9 +237,9 @@ class _Option:
for path, schema in self.schema['properties'].items(): for path, schema in self.schema['properties'].items():
if type == 'all' or schema['type'] not in ['object', 'array']: if type == 'all' or schema['type'] not in ['object', 'array']:
hidden = self.temp.get(path, {}).get('hidden', None) hidden = self.temp.get(path, {}).get('hidden', None)
if self.temp.get(path, {}).get('hidden', False) is not True and \ model_hidden = not self.model.get(path, {}).get('hidden', False) and \
not self.model.get(path, {}).get('hidden', False) and \ self.model.get(path, {}).get('display', True)
self.model.get(path, {}).get('display', True): if hidden is False or (hidden is None and model_hidden is True):
if schema['type'] in ['object', 'array']: if schema['type'] in ['object', 'array']:
yield TiramisuOptionDescription(self.config, yield TiramisuOptionDescription(self.config,
schema, schema,
@ -285,10 +285,10 @@ class TiramisuOptionDescription(_Option):
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(self.path, {}).get('hidden', None) hidden = self.temp.get(key, {}).get('hidden', None)
if hidden is False or (hidden is None and \ model_hidden = not self.model.get(key, {}).get('hidden', False) and \
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):
# FIXME # FIXME
return 'default' return 'default'
raise PropertiesOptionError(None, None, None, opt_type='optiondescription') raise PropertiesOptionError(None, None, None, opt_type='optiondescription')
@ -365,8 +365,16 @@ class ContextOption(_Option):
def __call__(self, def __call__(self,
path: str, path: str,
index: Optional[int]=None) -> TiramisuOption: index: Optional[int]=None) -> TiramisuOption:
schema = self.config.get_schema(path)
if schema['type'] in ['object', 'array']:
return TiramisuOptionDescription(self.config,
schema,
self.model,
self.form,
self.temp,
path)
return TiramisuOption(self.config, return TiramisuOption(self.config,
self.config.get_schema(path), schema,
self.model, self.model,
self.form, self.form,
self.temp, self.temp,
@ -492,19 +500,18 @@ class Config:
def get_schema(self, def get_schema(self,
path): path):
root_path = self.root root_path = self.root
schema = {'properties': self.schema}
if root_path: if root_path:
schema = {'properties': self.schema}
root = self.root.split('.') root = self.root.split('.')
subpaths = path.split('.')[len(root):] subpaths = path.split('.')[len(root):]
for subpath in subpaths:
if root_path:
root_path += '.' + subpath
else:
root_path = subpath
schema = schema['properties'][root_path]
print(path, schema)
else: else:
schema = self.schema[path] subpaths = path.split('.')
for subpath in subpaths:
if root_path:
root_path += '.' + subpath
else:
root_path = subpath
schema = schema['properties'][root_path]
return schema return schema
@ -577,7 +584,7 @@ class Config:
else: else:
self.temp.setdefault(path, {})['owner'] = 'tmp' self.temp.setdefault(path, {})['owner'] = 'tmp'
self.temp[path]['value'] = value self.temp[path]['value'] = value
self.set_dependencies(path, action, value) self.set_dependencies(path, value)
self.set_not_equal(path, value) self.set_not_equal(path, value)
self.do_copy(path, value) self.do_copy(path, value)
@ -604,8 +611,8 @@ class Config:
def set_dependencies(self, def set_dependencies(self,
path: str, path: str,
action: str, value: Any,
value: Any) -> None: force_hide: bool=False) -> None:
dependencies = self.form.get(path, {}).get('dependencies', {}) dependencies = self.form.get(path, {}).get('dependencies', {})
if dependencies: if dependencies:
if value in dependencies['expected']: if value in dependencies['expected']:
@ -615,8 +622,17 @@ class Config:
for action in ['hide', 'show']: for action in ['hide', 'show']:
expected_actions = expected.get(action) expected_actions = expected.get(action)
if expected_actions: if expected_actions:
if force_hide:
hidden = True
else:
hidden = action == 'hide'
for expected_path in expected_actions: for expected_path in expected_actions:
self.temp[expected_path] = {'hidden': action == 'hide'} self.temp.setdefault(expected_path, {})['hidden'] = hidden
if 'value' in self.temp.get(expected_path, {}):
value = self.temp[expected_path]['value']
else:
value = self.model[expected_path].get('value')
self.set_dependencies(expected_path, value, hidden)
def set_not_equal(self, def set_not_equal(self,
path: str, path: str,