New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibility to order reports #6973
Comments
It might be a bit cleaner to allow the declaration of an ordered list within the module, akin to Django's reports = ('report_a', 'report_b', 'report_z') |
You are totally right about that. I would propose to have a variable named Exemple with a class MySuperReportZ(Report):
[...]
class MySuperReportA(Report):
[...]
class MySuperReportC(Report):
[...]
report_order = (MySuperReportA, MySuperReportC, MySuperReportZ) I would then modify the original
def get_reports():
""" """
module_list = []
# Iterate through all modules within the reports path. These are the user-created files in which reports are
# defined.
for importer, module_name, _ in pkgutil.iter_modules([settings.REPORTS_ROOT]):
module = importer.find_module(module_name).load_module(module_name)
ordered_reports = set([report for report in getattr(module, "report_order", ()) if is_report(report)])
available_reports = set([cls for _, cls in inspect.getmembers(module, is_report)])
ordered_reports.update(available_reports - ordered_reports)
report_list = [cls() for _, cls in ordered_reports]
module_list.append((module_name, report_list))
return module_list If you agree with the implementation I can handle this feature with the code modification, test cases and documentation update. |
Sorry, this fell off the radar. Please have it if you're still available @maximumG! Also, you can likely simplify the above logic a bit:
|
Don't worry about the delay in your answer. We still need this feature internally so I will handle this and try to implement what you described above. |
@jeremystretch We also have the same needs to order Script within a module. Do you want me to create another FR dedicated to this ? |
@maximumG Yes, let's handle that in a separate FR. Thanks! |
NetBox version
v2.11.7
Feature type
Change to existing functionality
Proposed functionality
State of the art
As of Netbox 2.11.x, reports are automatically discovered and rendered in the UI (extras/reports/). The order of the reports is based on alphabetical order.
As an exemple, if you have a python module named DCIM-report.py with 3 Reports subclasses named report_a, report_b and report_z, the order in which reports are rendered in the report list depends upon their name.
The code handling this list can be found here:
netbox/netbox/extras/reports.py
Lines 46 to 65 in 10847e2
Proposal
Use case
We propose the possibility for the developer to order the report's listing inside a python module. This can possibly help Ops team to follow each report and correct corresponding errors one after another.
Implementation
The Report class should have a new attribute named
order
with a default value of -1. Developer would have the possibility to order their reports based on this attribute, the biggest number being the first report in the list.Netbox source code should also take into account this attribute in order to reorder the report list inside each python module.
Use case
Ordering reports on the WebUI would guide Ops team to check each report and correct the pinpoint errors one after another.
Database changes
N/A
External dependencies
N/A
The text was updated successfully, but these errors were encountered: