settting to control app loading

This commit is contained in:
Matthias 2021-10-16 17:47:05 +02:00
parent c16c26c496
commit 99e4b6f6a5
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
4 changed files with 33 additions and 6 deletions

View File

@ -759,13 +759,9 @@ INTEGRATION_PLUGINS = []
INTEGRATION_PLUGIN_SETTINGS = {} INTEGRATION_PLUGIN_SETTINGS = {}
INTEGRATION_PLUGIN_SETTING = {} INTEGRATION_PLUGIN_SETTING = {}
INTEGRATION_PLUGIN_LIST = {} INTEGRATION_PLUGIN_LIST = {}
INTEGRATION_APPS_LOADED = False # Marks if apps were reloaded yet
for plugin in inventree_plugins.load_integration_plugins(): for plugin in inventree_plugins.load_integration_plugins():
plugin = plugin() plugin = plugin()
INTEGRATION_PLUGINS.append(plugin) INTEGRATION_PLUGINS.append(plugin)
INTEGRATION_PLUGIN_LIST[plugin.slug] = plugin INTEGRATION_PLUGIN_LIST[plugin.slug] = plugin
if plugin.mixin_enabled('app'):
plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(BASE_DIR).parts)
INSTALLED_APPS += [plugin_path]

View File

@ -872,6 +872,12 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'default': False, 'default': False,
'validator': bool, 'validator': bool,
}, },
'ENABLE_PLUGINS_APP': {
'name': _('Enable app integration'),
'description': _('Enable plugins to add apps'),
'default': False,
'validator': bool,
},
} }
class Meta: class Meta:

View File

@ -1,7 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import pathlib
from typing import OrderedDict
from allauth.socialaccount import app_settings
from django.apps import AppConfig from django.apps import AppConfig, apps
from django.conf import settings from django.conf import settings
@ -11,9 +14,30 @@ class PluginConfig(AppConfig):
def ready(self): def ready(self):
from common.models import InvenTreeSetting from common.models import InvenTreeSetting
# if plugin settings are enabled enhance the settings
if InvenTreeSetting.get_setting('ENABLE_PLUGINS_SETTING'): if InvenTreeSetting.get_setting('ENABLE_PLUGINS_SETTING'):
for slug, plugin in settings.INTEGRATION_PLUGIN_LIST.items(): for slug, plugin in settings.INTEGRATION_PLUGIN_LIST.items():
if plugin.mixin_enabled('settings'): if plugin.mixin_enabled('settings'):
plugin_setting = plugin.settingspatterns plugin_setting = plugin.settingspatterns
settings.INTEGRATION_PLUGIN_SETTING[slug] = plugin_setting settings.INTEGRATION_PLUGIN_SETTING[slug] = plugin_setting
settings.INTEGRATION_PLUGIN_SETTINGS.update(plugin_setting) settings.INTEGRATION_PLUGIN_SETTINGS.update(plugin_setting)
# if plugin apps are enabled
if (not settings.INTEGRATION_APPS_LOADED) and InvenTreeSetting.get_setting('ENABLE_PLUGINS_APP'):
settings.INTEGRATION_APPS_LOADED = True # ensure this section will not run again
apps_changed = False
# add them to the INSTALLED_APPS
for slug, plugin in settings.INTEGRATION_PLUGIN_LIST.items():
if plugin.mixin_enabled('app'):
plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(settings.BASE_DIR).parts)
settings.INSTALLED_APPS += [plugin_path]
apps_changed = True
# if apps were changed reload
# TODO this is a bit jankey to be honest
if apps_changed:
apps.app_configs = OrderedDict()
apps.apps_ready = apps.models_ready = apps.loading = apps.ready = False
apps.clear_cache()
apps.populate(settings.INSTALLED_APPS)

View File

@ -19,6 +19,7 @@
{% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_URL" %} {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_URL" %}
{% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_NAVIGATION" %} {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_NAVIGATION" %}
{% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_SETTING"%} {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_SETTING"%}
{% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_APP"%}
</tbody> </tbody>
</table> </table>