convert xxxlist to fill in separate function
This commit is contained in:
parent
6af2b3d1f3
commit
c90324187b
1 changed files with 63 additions and 51 deletions
|
@ -49,7 +49,7 @@ class ConditionAnnotator:
|
||||||
return
|
return
|
||||||
self.convert_condition_target()
|
self.convert_condition_target()
|
||||||
self.check_condition_fallback()
|
self.check_condition_fallback()
|
||||||
self.convert_xxxlist_to_variable()
|
self.convert_xxxlist()
|
||||||
self.convert_condition_source()
|
self.convert_condition_source()
|
||||||
self.check_choice_option_condition()
|
self.check_choice_option_condition()
|
||||||
self.remove_condition_with_empty_target()
|
self.remove_condition_with_empty_target()
|
||||||
|
@ -203,7 +203,7 @@ class ConditionAnnotator:
|
||||||
return variable, list(variable.variable.values())
|
return variable, list(variable.variable.values())
|
||||||
return variable, []
|
return variable, []
|
||||||
|
|
||||||
def convert_xxxlist_to_variable(self):
|
def convert_xxxlist(self):
|
||||||
"""transform *list to variable or family
|
"""transform *list to variable or family
|
||||||
"""
|
"""
|
||||||
fills = {}
|
fills = {}
|
||||||
|
@ -211,62 +211,74 @@ class ConditionAnnotator:
|
||||||
remove_targets = []
|
remove_targets = []
|
||||||
for target_idx, target in enumerate(condition.target):
|
for target_idx, target in enumerate(condition.target):
|
||||||
if target.type.endswith('list'):
|
if target.type.endswith('list'):
|
||||||
listname = target.type
|
listvars = self.objectspace.list_conditions.get(target.type,
|
||||||
listvars = self.objectspace.list_conditions.get(listname,
|
|
||||||
{}).get(target.name)
|
{}).get(target.name)
|
||||||
if listvars:
|
if listvars:
|
||||||
for listvar in listvars:
|
self._convert_xxxlist_to_fill(condition,
|
||||||
if target.name in self.force_service_value:
|
target,
|
||||||
listvar.default = self.force_service_value[target.name]
|
listvars,
|
||||||
continue
|
fills,
|
||||||
value = condition.name != 'disabled_if_in'
|
)
|
||||||
if listvar.path in fills:
|
|
||||||
fill = fills[listvar.path]
|
|
||||||
or_needed = True
|
|
||||||
for param in fill.param:
|
|
||||||
if hasattr(param, 'name') and param.name == 'condition_operator':
|
|
||||||
or_needed = False
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
fill = self.objectspace.fill(target.xmlfiles)
|
|
||||||
fill.target = listvar.path
|
|
||||||
fill.name = 'calc_value'
|
|
||||||
fill.namespace = 'services'
|
|
||||||
fill.index = -1
|
|
||||||
if not hasattr(self.objectspace.space.constraints, 'fill'):
|
|
||||||
self.objectspace.space.constraints.fill = []
|
|
||||||
self.objectspace.space.constraints.fill.append(fill)
|
|
||||||
fills[listvar.path] = fill
|
|
||||||
param1 = self.objectspace.param(target.xmlfiles)
|
|
||||||
param1.text = value
|
|
||||||
param1.type = 'boolean'
|
|
||||||
param2 = self.objectspace.param(target.xmlfiles)
|
|
||||||
param2.name = 'default'
|
|
||||||
param2.text = not value
|
|
||||||
param2.type = 'boolean'
|
|
||||||
fill.param = [param1, param2]
|
|
||||||
or_needed = len(condition.param) != 1
|
|
||||||
for param in condition.param:
|
|
||||||
fill.index += 1
|
|
||||||
param3 = self.objectspace.param(target.xmlfiles)
|
|
||||||
param3.name = f'condition_{fill.index}'
|
|
||||||
param3.type = 'variable'
|
|
||||||
param3.text = condition.source
|
|
||||||
fill.param.append(param3)
|
|
||||||
param4 = self.objectspace.param(target.xmlfiles)
|
|
||||||
param4.name = f'expected_{fill.index}'
|
|
||||||
param4.text = getattr(param, 'text', None)
|
|
||||||
fill.param.append(param4)
|
|
||||||
if or_needed:
|
|
||||||
param5 = self.objectspace.param(target.xmlfiles)
|
|
||||||
param5.name = 'condition_operator'
|
|
||||||
param5.text = 'OR'
|
|
||||||
fill.param.append(param5)
|
|
||||||
remove_targets.append(target_idx)
|
remove_targets.append(target_idx)
|
||||||
remove_targets.sort(reverse=True)
|
remove_targets.sort(reverse=True)
|
||||||
for target_idx in remove_targets:
|
for target_idx in remove_targets:
|
||||||
condition.target.pop(target_idx)
|
condition.target.pop(target_idx)
|
||||||
|
|
||||||
|
def _convert_xxxlist_to_fill(self,
|
||||||
|
condition: 'self.objectspace.condition',
|
||||||
|
target: 'self.objectspace.target',
|
||||||
|
listvars: list,
|
||||||
|
fills: dict,
|
||||||
|
):
|
||||||
|
for listvar in listvars:
|
||||||
|
if target.name in self.force_service_value:
|
||||||
|
listvar.default = self.force_service_value[target.name]
|
||||||
|
continue
|
||||||
|
value = condition.name != 'disabled_if_in'
|
||||||
|
if listvar.path in fills:
|
||||||
|
fill = fills[listvar.path]
|
||||||
|
or_needed = True
|
||||||
|
for param in fill.param:
|
||||||
|
if hasattr(param, 'name') and \
|
||||||
|
param.name == 'condition_operator':
|
||||||
|
or_needed = False
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
fill = self.objectspace.fill(target.xmlfiles)
|
||||||
|
fill.target = listvar.path
|
||||||
|
fill.name = 'calc_value'
|
||||||
|
fill.namespace = 'services'
|
||||||
|
fill.index = -1
|
||||||
|
if not hasattr(self.objectspace.space.constraints, 'fill'):
|
||||||
|
self.objectspace.space.constraints.fill = []
|
||||||
|
self.objectspace.space.constraints.fill.append(fill)
|
||||||
|
fills[listvar.path] = fill
|
||||||
|
param1 = self.objectspace.param(target.xmlfiles)
|
||||||
|
param1.text = value
|
||||||
|
param1.type = 'boolean'
|
||||||
|
param2 = self.objectspace.param(target.xmlfiles)
|
||||||
|
param2.name = 'default'
|
||||||
|
param2.text = not value
|
||||||
|
param2.type = 'boolean'
|
||||||
|
fill.param = [param1, param2]
|
||||||
|
or_needed = len(condition.param) != 1
|
||||||
|
for param in condition.param:
|
||||||
|
fill.index += 1
|
||||||
|
param3 = self.objectspace.param(target.xmlfiles)
|
||||||
|
param3.name = f'condition_{fill.index}'
|
||||||
|
param3.type = 'variable'
|
||||||
|
param3.text = condition.source
|
||||||
|
fill.param.append(param3)
|
||||||
|
param4 = self.objectspace.param(target.xmlfiles)
|
||||||
|
param4.name = f'expected_{fill.index}'
|
||||||
|
param4.text = getattr(param, 'text', None)
|
||||||
|
fill.param.append(param4)
|
||||||
|
if or_needed:
|
||||||
|
param5 = self.objectspace.param(target.xmlfiles)
|
||||||
|
param5.name = 'condition_operator'
|
||||||
|
param5.text = 'OR'
|
||||||
|
fill.param.append(param5)
|
||||||
|
|
||||||
def convert_condition_source(self):
|
def convert_condition_source(self):
|
||||||
"""remove condition for ChoiceOption that don't have param
|
"""remove condition for ChoiceOption that don't have param
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue