1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Only use module.name for human-facing display

This commit is contained in:
Jeremy Stretch
2019-10-30 09:13:26 -04:00
parent fd3f718a0a
commit 0f65cf23a5
3 changed files with 10 additions and 5 deletions

View File

@ -220,6 +220,10 @@ class BaseScript:
def __str__(self):
return getattr(self.Meta, 'name', self.__class__.__name__)
@classmethod
def module(cls):
return cls.__module__
@classmethod
def _get_vars(cls):
vars = OrderedDict()
@ -361,9 +365,10 @@ def run_script(script, data, files, commit=True):
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()
@ -371,7 +376,7 @@ def get_scripts():
# defined.
for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
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_scripts = OrderedDict()
for name, cls in inspect.getmembers(module, is_script):

View File

@ -375,7 +375,7 @@ class ScriptListView(PermissionRequiredMixin, View):
def get(self, request):
return render(request, 'extras/script_list.html', {
'scripts': get_scripts(),
'scripts': get_scripts(use_names=True),
})

View File

@ -19,7 +19,7 @@
{% for class_name, script in module_scripts.items %}
<tr>
<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>{{ script.Meta.description }}</td>
</tr>