From 2e511a17b40d60b0cf7799291ae6c3b10fc04bc9 Mon Sep 17 00:00:00 2001 From: Graham Gilbert Date: Tue, 11 Aug 2015 16:02:40 +0100 Subject: [PATCH] Load in default plugins if there aren't any --- docker/Dockerfile | 1 - docker/README.md | 1 - docker/settings.py | 2 +- docker/settings_import.py | 6 ------ server/utils.py | 14 +++++++++++++- server/views.py | 2 ++ 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index d7f5c175..83adbba8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -12,7 +12,6 @@ ENV DOCKER_SAL_TZ Europe/London ENV DOCKER_SAL_ADMINS Docker User, docker@localhost ENV DOCKER_SAL_LANG en_GB ENV DOCKER_SAL_DISPLAY_NAME Sal -ENV DOCKER_SAL_PLUGIN_ORDER Activity,Status,OperatingSystem,Uptime,Memory ENV DOCKER_SAL_DEBUG false RUN apt-get update && \ diff --git a/docker/README.md b/docker/README.md index db9e99c5..05eeb75d 100644 --- a/docker/README.md +++ b/docker/README.md @@ -11,7 +11,6 @@ Several options, such as the timezone and admin password are customizable using * ``DOCKER_SAL_DISPLAY_NAME``: This sets the name that appears in the title bar of the window. Defaults to ``Sal``. * ``DOCKER_SAL_TZ``: The desired [timezone](http://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Defaults to ``Europe/London``. * ``DOCKER_SAL_ADMINS``: The admin user's details. Defaults to ``Docker User, docker@localhost``. -* ``DOCKER_SAL_PLUGIN_ORDER``: The order plugins are displayed in. Defaults to ``Activity,Status,OperatingSystem,Uptime,Memory``. * ``DOCKER_SAL_DEBUG``: Whether debug mode is enabled or not. Valid values are ``true`` and ``false``. Defaults to ``false``. If you require more advanced settings, for example if you want to hide certain plugins from certain Business Units or if you have a plugin that needs settings, you can override ``settings.py`` with your own. A good starting place can be found on this image's [Github repository](https://github.com/salopensource/sal/blob/master/docker/settings.py). diff --git a/docker/settings.py b/docker/settings.py index 81e18fed..abec4432 100644 --- a/docker/settings.py +++ b/docker/settings.py @@ -1,6 +1,6 @@ # Django settings for sal project. from system_settings import * -from settings_import import ADMINS, TIME_ZONE, LANGUAGE_CODE, ALLOWED_HOSTS, DISPLAY_NAME, PLUGIN_ORDER, DEBUG +from settings_import import ADMINS, TIME_ZONE, LANGUAGE_CODE, ALLOWED_HOSTS, DISPLAY_NAME, DEBUG DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. diff --git a/docker/settings_import.py b/docker/settings_import.py index 88014ac3..2b3cf901 100644 --- a/docker/settings_import.py +++ b/docker/settings_import.py @@ -64,9 +64,3 @@ DISPLAY_NAME = getenv('DOCKER_SAL_DISPLAY_NAME') else: DISPLAY_NAME = 'Sal' - -# The order plugins (if they're able to be shown on that particular page) will be displayed in. If not listed here, will be listed alphabetically after. -if getenv('DOCKER_SAL_PLUGIN_ORDER'): - PLUGIN_ORDER = getenv('DOCKER_SAL_PLUGIN_ORDER').split(',') -else: - PLUGIN_ORDER = ['Activity','Status', 'MunkiVersion','OperatingSystem','Uptime', 'Memory'] diff --git a/server/utils.py b/server/utils.py index d87ad195..cb2188bd 100644 --- a/server/utils.py +++ b/server/utils.py @@ -6,12 +6,24 @@ from django.db.models import Max import os +def loadDefaultPlugins(): + # Are there any plugin objects? If not, add in the defaults + plugin_objects = Plugin.objects.all().count() + if plugin_objects == 0: + order = 0 + PLUGIN_ORDER = ['Activity','Status','OperatingSystem', 'MunkiVersion', 'Uptime', 'Memory', 'DiskSpace', 'PendingAppleUpdates', 'Pending3rdPartyUpdates', 'PuppetStatus'] + for item in PLUGIN_ORDER: + order = order + 1 + plugin = Plugin(name=item, order=order) + plugin.save() + def reloadPluginsModel(): # Are there any plugin objects? If not, add in the defaults plugin_objects = Plugin.objects.all().count() if plugin_objects == 0: order = 0 - for item in settings.PLUGIN_ORDER: + PLUGIN_ORDER = ['Activity','Status','OperatingSystem', 'MunkiVersion', 'Uptime', 'Memory', 'DiskSpace', 'PendingAppleUpdates', 'Pending3rdPartyUpdates', 'PuppetStatus'] + for item in PLUGIN_ORDER: order = order + 1 plugin = Plugin(name=item, order=order) plugin.save() diff --git a/server/views.py b/server/views.py index 075c6b03..b2b31754 100644 --- a/server/views.py +++ b/server/views.py @@ -67,6 +67,8 @@ def index(request): for group in business_unit.machinegroup_set.all(): machines = machines | group.machine_set.all() + # Load in the default plugins if needed + utils.loadDefaultPlugins() # Build the manager manager = PluginManager() # Tell it the default place(s) where to find plugins