mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 16:06:43 -06:00
Proposed option for #13795, adding module option to hide scripts from user display
This commit is contained in:
parent
2dfbd72f10
commit
df71b02e88
@ -42,7 +42,7 @@ Defining script variables is optional: You may create a script with only a `run(
|
||||
|
||||
Any output generated by the script during its execution will be displayed under the "output" tab in the UI.
|
||||
|
||||
By default, scripts within a module are ordered alphabetically in the scripts list page. To return scripts in a specific order, you can define the `script_order` variable at the end of your module. The `script_order` variable is a tuple which contains each Script class in the desired order. Any scripts that are omitted from this list will be listed last.
|
||||
By default, scripts within a module are ordered alphabetically in the scripts list page. To return scripts in a specific order, you can define the `script_order` variable at the end of your module. The `script_order` variable is a tuple which contains each Script class in the desired order. Any scripts that are omitted from this list will be listed last. To omit scripts from display entirely, define the `script_hide` variable at the end of your module. Scripts listed in this tuple will be ommitted from the unordered script listing.
|
||||
|
||||
```python
|
||||
from extras.scripts import Script
|
||||
@ -54,6 +54,7 @@ class AnotherCustomScript(Script):
|
||||
...
|
||||
|
||||
script_order = (MyCustomScript, AnotherCustomScript)
|
||||
script_hide = (MyHiddenScript,)
|
||||
```
|
||||
|
||||
## Module Attributes
|
||||
|
@ -67,11 +67,12 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
|
||||
|
||||
scripts = {}
|
||||
ordered = getattr(module, 'script_order', [])
|
||||
hide = getattr(module, 'script_hide', [])
|
||||
|
||||
for cls in ordered:
|
||||
scripts[_get_name(cls)] = cls
|
||||
for name, cls in inspect.getmembers(module, is_script):
|
||||
if cls not in ordered:
|
||||
if cls not in ordered and cls not in hide:
|
||||
scripts[_get_name(cls)] = cls
|
||||
|
||||
return scripts
|
||||
|
Loading…
Reference in New Issue
Block a user