From e443d719d40a0cca2bb7e2a7a43214a8bcee9c5c Mon Sep 17 00:00:00 2001 From: maximumG Date: Mon, 27 Sep 2021 10:59:23 +0200 Subject: [PATCH 1/2] feat: reports within a module can now be ordered --- netbox/extras/reports.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netbox/extras/reports.py b/netbox/extras/reports.py index 64fbffb46..cc623b37c 100644 --- a/netbox/extras/reports.py +++ b/netbox/extras/reports.py @@ -59,8 +59,10 @@ def get_reports(): # defined. for importer, module_name, _ in pkgutil.iter_modules([settings.REPORTS_ROOT]): module = importer.find_module(module_name).load_module(module_name) - report_list = [cls() for _, cls in inspect.getmembers(module, is_report)] - module_list.append((module_name, report_list)) + report_order = getattr(module, "report_order", ()) + ordered_reports = [cls() for cls in report_order if is_report(cls)] + unordered_reports = [cls() for _, cls in inspect.getmembers(module, is_report) if cls not in report_order] + module_list.append((module_name, [*ordered_reports, *unordered_reports])) return module_list From 0214c388ae612d97120365366e2a16a37cfbc967 Mon Sep 17 00:00:00 2001 From: maximumG Date: Mon, 27 Sep 2021 11:00:23 +0200 Subject: [PATCH 2/2] add: document how to order reports --- docs/customization/reports.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/customization/reports.md b/docs/customization/reports.md index 2fead68ec..a227f3851 100644 --- a/docs/customization/reports.md +++ b/docs/customization/reports.md @@ -97,6 +97,21 @@ The recording of one or more failure messages will automatically flag a report a To perform additional tasks, such as sending an email or calling a webhook, after a report has been run, extend the `post_run()` method. The status of the report is available as `self.failed` and the results object is `self.result`. +By default, reports within a module are unordered and 'randomly' displayed in the reports list page. If you want to order reports, you can defined the `report_order` variable at the end +of your module. The `report_order` variable is a tuple which contains each Report class in a specific order. + +``` +from extras.reports import Report + +class DeviceConnectionsReport(Report) + pass + +class DeviceIPsReport(Report) + pass + +report_order = (DeviceIPsReport, DeviceConnectionsReport) +``` + Once you have created a report, it will appear in the reports list. Initially, reports will have no results associated with them. To generate results, run the report. ## Running Reports