mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 04:02:52 -06:00
Only use module.name for human-facing display
This commit is contained in:
parent
fd3f718a0a
commit
0f65cf23a5
@ -220,6 +220,10 @@ class BaseScript:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return getattr(self.Meta, 'name', self.__class__.__name__)
|
return getattr(self.Meta, 'name', self.__class__.__name__)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def module(cls):
|
||||||
|
return cls.__module__
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_vars(cls):
|
def _get_vars(cls):
|
||||||
vars = OrderedDict()
|
vars = OrderedDict()
|
||||||
@ -361,9 +365,10 @@ def run_script(script, data, files, commit=True):
|
|||||||
return output, execution_time
|
return output, execution_time
|
||||||
|
|
||||||
|
|
||||||
def get_scripts():
|
def get_scripts(use_names=False):
|
||||||
"""
|
"""
|
||||||
Return a dict of dicts mapping all scripts to their modules.
|
Return a dict of dicts mapping all scripts to their modules. Set use_names to True to use each module's human-
|
||||||
|
defined name in place of the actual module name.
|
||||||
"""
|
"""
|
||||||
scripts = OrderedDict()
|
scripts = OrderedDict()
|
||||||
|
|
||||||
@ -371,7 +376,7 @@ def get_scripts():
|
|||||||
# defined.
|
# defined.
|
||||||
for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
|
for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
|
||||||
module = importer.find_module(module_name).load_module(module_name)
|
module = importer.find_module(module_name).load_module(module_name)
|
||||||
if hasattr(module, 'name'):
|
if use_names and hasattr(module, 'name'):
|
||||||
module_name = module.name
|
module_name = module.name
|
||||||
module_scripts = OrderedDict()
|
module_scripts = OrderedDict()
|
||||||
for name, cls in inspect.getmembers(module, is_script):
|
for name, cls in inspect.getmembers(module, is_script):
|
||||||
|
@ -375,7 +375,7 @@ class ScriptListView(PermissionRequiredMixin, View):
|
|||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
||||||
return render(request, 'extras/script_list.html', {
|
return render(request, 'extras/script_list.html', {
|
||||||
'scripts': get_scripts(),
|
'scripts': get_scripts(use_names=True),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
{% for class_name, script in module_scripts.items %}
|
{% for class_name, script in module_scripts.items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url 'extras:script' module=module name=class_name %}" name="script.{{ class_name }}"><strong>{{ script }}</strong></a>
|
<a href="{% url 'extras:script' module=script.module name=class_name %}" name="script.{{ class_name }}"><strong>{{ script }}</strong></a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ script.Meta.description }}</td>
|
<td>{{ script.Meta.description }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user