Skip to content

Commit

Permalink
Proposed option for netbox-community#13795, adding module option to h…
Browse files Browse the repository at this point in the history
…ide scripts from user display
  • Loading branch information
Ryan Rawdon committed Sep 18, 2023
1 parent 2dfbd72 commit df71b02
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/customization/custom-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,6 +54,7 @@ class AnotherCustomScript(Script):
...

script_order = (MyCustomScript, AnotherCustomScript)
script_hide = (MyHiddenScript,)
```

## Module Attributes
Expand Down
3 changes: 2 additions & 1 deletion netbox/extras/models/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ def _get_name(cls):

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
Expand Down

0 comments on commit df71b02

Please sign in to comment.