convert xxxlist to fill in separate function

This commit is contained in:
Emmanuel Garette 2021-01-30 15:36:02 +01:00
parent 6af2b3d1f3
commit c90324187b

View file

@ -49,7 +49,7 @@ class ConditionAnnotator:
return
self.convert_condition_target()
self.check_condition_fallback()
self.convert_xxxlist_to_variable()
self.convert_xxxlist()
self.convert_condition_source()
self.check_choice_option_condition()
self.remove_condition_with_empty_target()
@ -203,7 +203,7 @@ class ConditionAnnotator:
return variable, list(variable.variable.values())
return variable, []
def convert_xxxlist_to_variable(self):
def convert_xxxlist(self):
"""transform *list to variable or family
"""
fills = {}
@ -211,10 +211,25 @@ class ConditionAnnotator:
remove_targets = []
for target_idx, target in enumerate(condition.target):
if target.type.endswith('list'):
listname = target.type
listvars = self.objectspace.list_conditions.get(listname,
listvars = self.objectspace.list_conditions.get(target.type,
{}).get(target.name)
if listvars:
self._convert_xxxlist_to_fill(condition,
target,
listvars,
fills,
)
remove_targets.append(target_idx)
remove_targets.sort(reverse=True)
for target_idx in remove_targets:
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]
@ -224,7 +239,8 @@ class ConditionAnnotator:
fill = fills[listvar.path]
or_needed = True
for param in fill.param:
if hasattr(param, 'name') and param.name == 'condition_operator':
if hasattr(param, 'name') and \
param.name == 'condition_operator':
or_needed = False
break
else:
@ -262,10 +278,6 @@ class ConditionAnnotator:
param5.name = 'condition_operator'
param5.text = 'OR'
fill.param.append(param5)
remove_targets.append(target_idx)
remove_targets.sort(reverse=True)
for target_idx in remove_targets:
condition.target.pop(target_idx)
def convert_condition_source(self):
"""remove condition for ChoiceOption that don't have param