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 = {}
|
d = {}
|
||||||
|
|
||||||
for attr, sub in attrs.items():
|
for attr, sub in attrs.items():
|
||||||
|
no_attr = False
|
||||||
|
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
value = obj.get(attr, None)
|
value = obj.get(attr, None)
|
||||||
else:
|
else:
|
||||||
value = getattr(obj, attr, None)
|
try:
|
||||||
|
value = getattr(obj, attr)
|
||||||
|
except AttributeError:
|
||||||
|
no_attr = True
|
||||||
|
value = None
|
||||||
|
|
||||||
if callable(value):
|
if callable(value):
|
||||||
value = value()
|
value = value()
|
||||||
|
@ -1194,7 +1200,10 @@ def get_attrs_to_dict(obj, attrs):
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
value = [sub(o) for o in value]
|
value = [sub(o) for o in value]
|
||||||
else:
|
else:
|
||||||
value = sub(value)
|
if no_attr:
|
||||||
|
value = sub(obj)
|
||||||
|
else:
|
||||||
|
value = sub(value)
|
||||||
|
|
||||||
d[attr] = value
|
d[attr] = value
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue