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
1 changed files with 63 additions and 51 deletions

View File

@ -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,10 +211,25 @@ 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:
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: for listvar in listvars:
if target.name in self.force_service_value: if target.name in self.force_service_value:
listvar.default = self.force_service_value[target.name] listvar.default = self.force_service_value[target.name]
@ -224,7 +239,8 @@ class ConditionAnnotator:
fill = fills[listvar.path] fill = fills[listvar.path]
or_needed = True or_needed = True
for param in fill.param: 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 or_needed = False
break break
else: else:
@ -262,10 +278,6 @@ class ConditionAnnotator:
param5.name = 'condition_operator' param5.name = 'condition_operator'
param5.text = 'OR' param5.text = 'OR'
fill.param.append(param5) 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): def convert_condition_source(self):
"""remove condition for ChoiceOption that don't have param """remove condition for ChoiceOption that don't have param