From 0fdd0818695e2673c1c81a0cd5911956b68f244a Mon Sep 17 00:00:00 2001 From: maximumG Date: Thu, 30 Sep 2021 09:17:33 +0200 Subject: [PATCH] feat: scripts within a module can now be ordered --- netbox/extras/scripts.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index 156b88065..6ccf7f48a 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -470,7 +470,6 @@ def get_scripts(use_names=False): defined name in place of the actual module name. """ scripts = OrderedDict() - # 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.SCRIPTS_ROOT]): @@ -478,11 +477,14 @@ def get_scripts(use_names=False): if use_names and hasattr(module, 'name'): module_name = module.name module_scripts = OrderedDict() - for name, cls in inspect.getmembers(module, is_script): - module_scripts[name] = cls + script_order = getattr(module, "script_order", ()) + ordered_scripts = [cls for cls in script_order if is_script(cls)] + unordered_scripts = [cls for _, cls in inspect.getmembers(module, is_script) if cls not in script_order] + for cls in [*ordered_scripts, *unordered_scripts]: + module_scripts[cls.__name__] = cls if module_scripts: scripts[module_name] = module_scripts - + return scripts