hidden are now recursive + schema without root
This commit is contained in:
parent
e1f62e8044
commit
a91f32401a
|
@ -237,9 +237,9 @@ class _Option:
|
|||
for path, schema in self.schema['properties'].items():
|
||||
if type == 'all' or schema['type'] not in ['object', 'array']:
|
||||
hidden = self.temp.get(path, {}).get('hidden', None)
|
||||
if self.temp.get(path, {}).get('hidden', False) is not True and \
|
||||
not self.model.get(path, {}).get('hidden', False) and \
|
||||
self.model.get(path, {}).get('display', True):
|
||||
model_hidden = not self.model.get(path, {}).get('hidden', False) and \
|
||||
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']:
|
||||
yield TiramisuOptionDescription(self.config,
|
||||
schema,
|
||||
|
@ -285,10 +285,10 @@ class TiramisuOptionDescription(_Option):
|
|||
raise APIError(_('please specify a valid sub function ({})').format(subfunc))
|
||||
|
||||
def group_type(self):
|
||||
hidden = self.temp.get(self.path, {}).get('hidden', None)
|
||||
if hidden is False or (hidden is None and \
|
||||
not self.model.get(self.path, {}).get('hidden', False) and \
|
||||
self.model.get(self.path, {}).get('display', True)):
|
||||
hidden = self.temp.get(key, {}).get('hidden', None)
|
||||
model_hidden = not self.model.get(key, {}).get('hidden', False) and \
|
||||
self.model.get(key, {}).get('display', True)
|
||||
if hidden is False or (hidden is None and model_hidden):
|
||||
# FIXME
|
||||
return 'default'
|
||||
raise PropertiesOptionError(None, None, None, opt_type='optiondescription')
|
||||
|
@ -365,8 +365,16 @@ class ContextOption(_Option):
|
|||
def __call__(self,
|
||||
path: str,
|
||||
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,
|
||||
self.config.get_schema(path),
|
||||
schema,
|
||||
self.model,
|
||||
self.form,
|
||||
self.temp,
|
||||
|
@ -492,19 +500,18 @@ class Config:
|
|||
def get_schema(self,
|
||||
path):
|
||||
root_path = self.root
|
||||
schema = {'properties': self.schema}
|
||||
if root_path:
|
||||
schema = {'properties': self.schema}
|
||||
root = self.root.split('.')
|
||||
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:
|
||||
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
|
||||
|
||||
|
||||
|
@ -577,7 +584,7 @@ class Config:
|
|||
else:
|
||||
self.temp.setdefault(path, {})['owner'] = 'tmp'
|
||||
self.temp[path]['value'] = value
|
||||
self.set_dependencies(path, action, value)
|
||||
self.set_dependencies(path, value)
|
||||
self.set_not_equal(path, value)
|
||||
self.do_copy(path, value)
|
||||
|
||||
|
@ -604,8 +611,8 @@ class Config:
|
|||
|
||||
def set_dependencies(self,
|
||||
path: str,
|
||||
action: str,
|
||||
value: Any) -> None:
|
||||
value: Any,
|
||||
force_hide: bool=False) -> None:
|
||||
dependencies = self.form.get(path, {}).get('dependencies', {})
|
||||
if dependencies:
|
||||
if value in dependencies['expected']:
|
||||
|
@ -615,8 +622,17 @@ class Config:
|
|||
for action in ['hide', 'show']:
|
||||
expected_actions = expected.get(action)
|
||||
if expected_actions:
|
||||
if force_hide:
|
||||
hidden = True
|
||||
else:
|
||||
hidden = action == 'hide'
|
||||
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,
|
||||
path: str,
|
||||
|
|
Loading…
Reference in New Issue