From a4936ad0dd091a639aefb7aa727d5a544ed94198 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 19 Aug 2019 14:40:08 -0400 Subject: [PATCH] Introduce BaseScript for extending Script without creating a new executable script --- netbox/extras/scripts.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index 91e387e9b..0bad2fe06 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -21,6 +21,7 @@ from .forms import ScriptForm __all__ = [ + 'BaseScript', 'BooleanVar', 'FileVar', 'IntegerVar', @@ -164,9 +165,10 @@ class IPNetworkVar(ScriptVariable): # Scripts # -class Script: +class BaseScript: """ - Custom scripts inherit this object. + Base model for custom scripts. User classes should inherit from this model if they want to extend Script + functionality for use in other subclasses. """ class Meta: pass @@ -250,6 +252,13 @@ class Script: return data +class Script(BaseScript): + """ + Classes which inherit this model will appear in the list of available scripts. + """ + pass + + # # Functions # @@ -258,7 +267,10 @@ def is_script(obj): """ Returns True if the object is a Script. """ - return obj in Script.__subclasses__() + try: + return issubclass(obj, Script) and obj != Script + except TypeError: + return False def is_variable(obj):