Allow an attribute lookup on a list to select from the list
This commit is contained in:
parent
2a4ba037c6
commit
cad20f42f1
@ -450,6 +450,15 @@ class Struct(object):
|
|||||||
elif isinstance(self.struct, HandleClass):
|
elif isinstance(self.struct, HandleClass):
|
||||||
struct = self.handle_join(self.struct)
|
struct = self.handle_join(self.struct)
|
||||||
return getattr(struct, attr)
|
return getattr(struct, attr)
|
||||||
|
elif isinstance(self.struct, (list, tuple)):
|
||||||
|
# then, let's make this select from the list
|
||||||
|
sublist = [getattr(Struct(item, self.db), attr) for item in self.struct]
|
||||||
|
if len(sublist) == 0:
|
||||||
|
return None
|
||||||
|
elif len(sublist) == 1:
|
||||||
|
return sublist[0]
|
||||||
|
else:
|
||||||
|
return Struct(sublist, self.db)
|
||||||
else:
|
else:
|
||||||
# better be a property of the list/tuple/dict/value:
|
# better be a property of the list/tuple/dict/value:
|
||||||
return getattr(self.struct, attr)
|
return getattr(self.struct, attr)
|
||||||
|
Loading…
Reference in New Issue
Block a user