mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 14:10:52 -07:00
Add ability for custom calculated attributes for exporting
This commit is contained in:
parent
55100dfb7a
commit
d3704fcee6
1 changed files with 11 additions and 2 deletions
|
@ -1172,10 +1172,16 @@ def get_attrs_to_dict(obj, attrs):
|
|||
d = {}
|
||||
|
||||
for attr, sub in attrs.items():
|
||||
no_attr = False
|
||||
|
||||
if isinstance(obj, dict):
|
||||
value = obj.get(attr, None)
|
||||
else:
|
||||
value = getattr(obj, attr, None)
|
||||
try:
|
||||
value = getattr(obj, attr)
|
||||
except AttributeError:
|
||||
no_attr = True
|
||||
value = None
|
||||
|
||||
if callable(value):
|
||||
value = value()
|
||||
|
@ -1193,6 +1199,9 @@ def get_attrs_to_dict(obj, attrs):
|
|||
elif callable(sub):
|
||||
if isinstance(value, list):
|
||||
value = [sub(o) for o in value]
|
||||
else:
|
||||
if no_attr:
|
||||
value = sub(obj)
|
||||
else:
|
||||
value = sub(value)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue