mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 15:32:38 -07:00
Add attribute sort helper function
This commit is contained in:
parent
881f37f731
commit
3be9c84f2b
2 changed files with 9 additions and 2 deletions
|
@ -1643,8 +1643,7 @@ class Export(object):
|
||||||
|
|
||||||
if self.file_format == 'csv':
|
if self.file_format == 'csv':
|
||||||
csv_data = helpers.flatten_dict(result)
|
csv_data = helpers.flatten_dict(result)
|
||||||
csv_headers = [field.split('.') for field in set().union(*csv_data)]
|
csv_headers = sorted(set().union(*csv_data), key=helpers.sort_attrs)
|
||||||
csv_headers = ['.'.join(field) for field in sorted(csv_headers, key=lambda s: (len(s), s))]
|
|
||||||
with open(filepath, 'w', encoding='utf-8', newline='') as outfile:
|
with open(filepath, 'w', encoding='utf-8', newline='') as outfile:
|
||||||
writer = csv.DictWriter(outfile, csv_headers)
|
writer = csv.DictWriter(outfile, csv_headers)
|
||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
|
|
|
@ -1236,6 +1236,14 @@ def bool_true(value, return_none=False):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def sort_attrs(attr):
|
||||||
|
if isinstance(attr, (list, tuple)):
|
||||||
|
a = attr[0].split('.')
|
||||||
|
else:
|
||||||
|
a = attr.split('.')
|
||||||
|
return len(a), a
|
||||||
|
|
||||||
|
|
||||||
def get_attrs_to_dict(obj, attrs):
|
def get_attrs_to_dict(obj, attrs):
|
||||||
d = {}
|
d = {}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue