python3: use class methods for child/family columns (#38094)
This commit is contained in:
parent
e87e088381
commit
a0828e21f1
|
@ -15,9 +15,14 @@ class DominoVariables(object):
|
|||
VARIABLE_TEMPLATE = 'domino_var_%s'
|
||||
CHILD_VARIABLE_TEMPLATE = 'domino_var_%s_enfant%s'
|
||||
|
||||
CHILD_COLUMNS = abelium_domino_ws.Child.COLUMNS
|
||||
FAMILY_COLUMNS = abelium_domino_ws.Family.COLUMNS \
|
||||
+ abelium_domino_ws.Family.MORE_COLUMNS
|
||||
@classmethod
|
||||
def CHILD_COLUMNS(cls):
|
||||
return abelium_domino_ws.Child.COLUMNS
|
||||
|
||||
@classmethod
|
||||
def FAMILY_COLUMNS(cls):
|
||||
return abelium_domino_ws.Family.COLUMNS + abelium_domino_ws.Family.MORE_COLUMNS
|
||||
|
||||
def __init__(self, publisher=None, request=None):
|
||||
self.publisher = publisher
|
||||
self.request = request
|
||||
|
@ -39,7 +44,7 @@ class DominoVariables(object):
|
|||
if family:
|
||||
family.complete()
|
||||
for i, child in enumerate(family.children):
|
||||
for remote_name, name, converter, desc in self.CHILD_COLUMNS:
|
||||
for remote_name, name, converter, desc in self.CHILD_COLUMNS():
|
||||
v = getattr(child, name, None)
|
||||
if v is None:
|
||||
continue
|
||||
|
@ -47,7 +52,7 @@ class DominoVariables(object):
|
|||
v = v.encode(charset)
|
||||
vars[self.CHILD_VARIABLE_TEMPLATE % (name, i+1)] = v
|
||||
vars[self.VARIABLE_TEMPLATE % 'nombre_enfants'] = len(family.children)
|
||||
for remote_name, name, converted, desc in self.FAMILY_COLUMNS:
|
||||
for remote_name, name, converted, desc in self.FAMILY_COLUMNS():
|
||||
if hasattr(family, name):
|
||||
v = getattr(family, name)
|
||||
if v is None:
|
||||
|
@ -70,9 +75,9 @@ class DominoVariables(object):
|
|||
if not is_activated():
|
||||
return ()
|
||||
vars = []
|
||||
for remote_name, name, converted, desc in cls.FAMILY_COLUMNS:
|
||||
for remote_name, name, converted, desc in cls.FAMILY_COLUMNS():
|
||||
vars.append((_('Domino'), cls.VARIABLE_TEMPLATE % name, desc))
|
||||
for remote_name, name, converted, desc in cls.CHILD_COLUMNS:
|
||||
for remote_name, name, converted, desc in cls.CHILD_COLUMNS():
|
||||
vars.append((_('Domino'), cls.CHILD_VARIABLE_TEMPLATE % (name, '{0,1,2,..}'), desc))
|
||||
return vars
|
||||
get_substitution_variables_list = classmethod(get_substitution_variables_list)
|
||||
|
|
Reference in New Issue