mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
settting to control app loading
This commit is contained in:
parent
c16c26c496
commit
99e4b6f6a5
@ -759,13 +759,9 @@ INTEGRATION_PLUGINS = []
|
||||
INTEGRATION_PLUGIN_SETTINGS = {}
|
||||
INTEGRATION_PLUGIN_SETTING = {}
|
||||
INTEGRATION_PLUGIN_LIST = {}
|
||||
INTEGRATION_APPS_LOADED = False # Marks if apps were reloaded yet
|
||||
|
||||
for plugin in inventree_plugins.load_integration_plugins():
|
||||
plugin = plugin()
|
||||
|
||||
INTEGRATION_PLUGINS.append(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]
|
||||
|
@ -872,6 +872,12 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
||||
'default': False,
|
||||
'validator': bool,
|
||||
},
|
||||
'ENABLE_PLUGINS_APP': {
|
||||
'name': _('Enable app integration'),
|
||||
'description': _('Enable plugins to add apps'),
|
||||
'default': False,
|
||||
'validator': bool,
|
||||
},
|
||||
}
|
||||
|
||||
class Meta:
|
||||
|
@ -1,7 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
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
|
||||
|
||||
|
||||
@ -11,9 +14,30 @@ class PluginConfig(AppConfig):
|
||||
def ready(self):
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
# if plugin settings are enabled enhance the settings
|
||||
if InvenTreeSetting.get_setting('ENABLE_PLUGINS_SETTING'):
|
||||
for slug, plugin in settings.INTEGRATION_PLUGIN_LIST.items():
|
||||
if plugin.mixin_enabled('settings'):
|
||||
plugin_setting = plugin.settingspatterns
|
||||
settings.INTEGRATION_PLUGIN_SETTING[slug] = 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)
|
||||
|
@ -19,6 +19,7 @@
|
||||
{% 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_SETTING"%}
|
||||
{% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_APP"%}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user