Skip to content

Commit

Permalink
Load plugins from Serveradmin apps for Servershell
Browse files Browse the repository at this point in the history
  • Loading branch information
kofrezo committed Mar 12, 2024
1 parent 058d58c commit a4cb315
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions serveradmin/servershell/templates/servershell/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,8 @@
servershell.sync_attrlist_visibility();
});
</script>
{% for plugin in servershell_plugins %}
{# Load javascript files from serveradmin apps for easy extension #}
<script src="{{ STATIC_URL }}{{ plugin }}"></script>
{% endfor %}
{% endblock %}
22 changes: 22 additions & 0 deletions serveradmin/servershell/utils.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions serveradmin/servershell/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
})


Expand Down

0 comments on commit a4cb315

Please sign in to comment.