Просмотр исходного кода

feat: scripts within a module can now be ordered

maximumG 4 лет назад
Родитель
Сommit
0fdd081869
1 измененных файлов с 6 добавлено и 4 удалено
  1. 6 4
      netbox/extras/scripts.py

+ 6 - 4
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