diff --git a/brian_dashboard_manager/templating/helpers.py b/brian_dashboard_manager/templating/helpers.py index aad2a3120719e380530f3330cf31f0825849098b..00b5946f383e680b75bb05826eea1bdd19de7427 100644 --- a/brian_dashboard_manager/templating/helpers.py +++ b/brian_dashboard_manager/templating/helpers.py @@ -490,7 +490,7 @@ def get_interface_data(interfaces): return result -def get_aggregate_interface_data(interfaces, agg_name, group_field): +def get_aggregate_interface_data(interfaces, group_field): """ Helper for grouping interface data to be used for generating aggregate dashboards. @@ -509,7 +509,7 @@ def get_aggregate_interface_data(interfaces, agg_name, group_field): :return: dictionary of aggregate dashboards and their interface data """ - result = [] + targets = [] def get_reduce_func_for_field(field): def reduce_func(prev, curr): @@ -532,15 +532,19 @@ def get_aggregate_interface_data(interfaces, agg_name, group_field): for info in interface['dashboards_info']: remote = info['name'] location = host.split('.')[1].upper() - result.append({ - 'type': agg_name, + targets.append({ 'interface': interface_name, 'hostname': host, 'remote': remote, 'location': location, 'alias': f"{router} - {remote} - {interface_name}", }) - return reduce(get_reduce_func_for_field(group_field), result, {}) + targets = sorted(targets, key=lambda x: x[group_field]) + result = reduce(get_reduce_func_for_field(group_field), targets, {}) + + for key in result: + result[key] = sorted(result[key], key=lambda x: x[group_field]) + return result def get_aggregate_targets(targets):