From 22980cea7ba264b42f1a119235e6928e5c8f5f40 Mon Sep 17 00:00:00 2001 From: kkthxbye <> Date: Mon, 21 Mar 2022 10:46:51 +0100 Subject: [PATCH 1/2] Speed up rendering of the script list --- netbox/extras/views.py | 2 ++ netbox/templates/extras/script_list.html | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/netbox/extras/views.py b/netbox/extras/views.py index cc53c465d..ae43ac489 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -753,6 +753,8 @@ class ScriptListView(ContentTypePermissionRequiredMixin, View): for _scripts in scripts.values(): for script in _scripts.values(): + # Prevent django from instantiating the class on all accesses + script.do_not_call_in_templates = True script.result = results.get(script.full_name) return render(request, 'extras/script_list.html', { diff --git a/netbox/templates/extras/script_list.html b/netbox/templates/extras/script_list.html index ccbdca705..a6f6833c9 100644 --- a/netbox/templates/extras/script_list.html +++ b/netbox/templates/extras/script_list.html @@ -34,7 +34,7 @@ {% for class_name, script in module_scripts.items %} - {{ script }} + {{ script.Meta.name }} {% include 'extras/inc/job_label.html' with result=script.result %} From ae46cd33b633d9248e38a68ea11e896e35eb3400 Mon Sep 17 00:00:00 2001 From: kkthxbye <> Date: Wed, 23 Mar 2022 12:18:14 +0100 Subject: [PATCH 2/2] - Move do_not_call_in_templates to BaseScript - Fix the name classproperty --- netbox/extras/scripts.py | 6 +++++- netbox/extras/views.py | 2 -- netbox/templates/extras/script_list.html | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index fb3c6558a..f80dfaefa 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -259,6 +259,10 @@ class BaseScript: Base model for custom scripts. User classes should inherit from this model if they want to extend Script functionality for use in other subclasses. """ + + # Prevent django from instantiating the class on all accesses + do_not_call_in_templates = True + class Meta: pass @@ -280,7 +284,7 @@ class BaseScript: @classproperty def name(self): - return getattr(self.Meta, 'name', self.__class__.__name__) + return getattr(self.Meta, 'name', self.__name__) @classproperty def full_name(self): diff --git a/netbox/extras/views.py b/netbox/extras/views.py index ae43ac489..cc53c465d 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -753,8 +753,6 @@ class ScriptListView(ContentTypePermissionRequiredMixin, View): for _scripts in scripts.values(): for script in _scripts.values(): - # Prevent django from instantiating the class on all accesses - script.do_not_call_in_templates = True script.result = results.get(script.full_name) return render(request, 'extras/script_list.html', { diff --git a/netbox/templates/extras/script_list.html b/netbox/templates/extras/script_list.html index a6f6833c9..1c502aacd 100644 --- a/netbox/templates/extras/script_list.html +++ b/netbox/templates/extras/script_list.html @@ -34,7 +34,7 @@ {% for class_name, script in module_scripts.items %} - {{ script.Meta.name }} + {{ script.name }} {% include 'extras/inc/job_label.html' with result=script.result %}