Skip to content

Commit 3e5452d

Browse files
Merge pull request #7369 from maximumG/6973-order-reports
Fixes #6973: order reports
2 parents 3ec0fe5 + 0214c38 commit 3e5452d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

docs/customization/reports.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ The recording of one or more failure messages will automatically flag a report a
9797

9898
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`.
9999

100+
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
101+
of your module. The `report_order` variable is a tuple which contains each Report class in a specific order.
102+
103+
```
104+
from extras.reports import Report
105+
106+
class DeviceConnectionsReport(Report)
107+
pass
108+
109+
class DeviceIPsReport(Report)
110+
pass
111+
112+
report_order = (DeviceIPsReport, DeviceConnectionsReport)
113+
```
114+
100115
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.
101116

102117
## Running Reports

netbox/extras/reports.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ def get_reports():
5959
# defined.
6060
for importer, module_name, _ in pkgutil.iter_modules([settings.REPORTS_ROOT]):
6161
module = importer.find_module(module_name).load_module(module_name)
62-
report_list = [cls() for _, cls in inspect.getmembers(module, is_report)]
63-
module_list.append((module_name, report_list))
62+
report_order = getattr(module, "report_order", ())
63+
ordered_reports = [cls() for cls in report_order if is_report(cls)]
64+
unordered_reports = [cls() for _, cls in inspect.getmembers(module, is_report) if cls not in report_order]
65+
module_list.append((module_name, [*ordered_reports, *unordered_reports]))
6466

6567
return module_list
6668

0 commit comments

Comments
 (0)