diff --git a/serveradmin/servershell/templates/servershell/index.html b/serveradmin/servershell/templates/servershell/index.html index 058b1bbb..4c2c4c18 100644 --- a/serveradmin/servershell/templates/servershell/index.html +++ b/serveradmin/servershell/templates/servershell/index.html @@ -235,4 +235,8 @@ servershell.sync_attrlist_visibility(); }); +{% for plugin in servershell_plugins %} + {# Load javascript files from serveradmin apps for easy extension #} + +{% endfor %} {% endblock %} diff --git a/serveradmin/servershell/utils.py b/serveradmin/servershell/utils.py new file mode 100644 index 00000000..a860d55f --- /dev/null +++ b/serveradmin/servershell/utils.py @@ -0,0 +1,22 @@ +from django.apps import apps +from django.contrib.staticfiles import finders + + +def servershell_plugins(): + """Find $app.servershell.plugin.js files from Serveradmin apps + + Scans all apps beginning with serveradmin_ for files that follow the pattern + $app.servershell.plugin.js and return them. This allows apps to add + commands to the Servershell. + + @return: + """ + js_files = list() + app_names = [app.name for app in apps.get_app_configs() if app.name.startswith("serveradmin_")] + for app_name in app_names: + path = f"js/{app_name}.servershell.plugin.js" + js_file = finders.find(path) + if js_file: + js_files.append(path) + + return js_files diff --git a/serveradmin/servershell/views.py b/serveradmin/servershell/views.py index 200b5fa5..66e7a42e 100644 --- a/serveradmin/servershell/views.py +++ b/serveradmin/servershell/views.py @@ -49,6 +49,7 @@ attribute_startswith ) from serveradmin.servershell.merged_query_iterator import MergedQuery +from serveradmin.servershell.utils import servershell_plugins MAX_DISTINGUISHED_VALUES = 50 NUM_SERVERS_DEFAULT = 25 @@ -106,6 +107,7 @@ def index(request): 'order_by': 'hostname', 'filters': sorted([(f.__name__, f.__doc__) for f in filter_classes]), 'search_settings': search_settings, + 'servershell_plugins': servershell_plugins(), })