mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
move stacks to registry
This commit is contained in:
parent
8fbbcb3a8d
commit
b1fbac925d
@ -884,9 +884,6 @@ if DEBUG or TESTING:
|
||||
PLUGINS = []
|
||||
INTEGRATION_PLUGIN_GLOBALSETTING = {}
|
||||
|
||||
INTEGRATION_APPS_PATHS = [] # Holds all added plugin_paths
|
||||
INTEGRATION_ERRORS = {} # Holds discovering errors
|
||||
|
||||
# Test settings
|
||||
PLUGIN_TESTING = get_setting('PLUGIN_TESTING', TESTING) # used to force enable everything plugin
|
||||
PLUGIN_TESTING_SETUP = get_setting('PLUGIN_TESTING_SETUP', False)
|
||||
|
@ -10,12 +10,14 @@ from django.conf import settings
|
||||
|
||||
# region logging / errors
|
||||
def log_plugin_error(error, reference: str = 'general'):
|
||||
from plugin import plugin_reg
|
||||
|
||||
# make sure the registry is set up
|
||||
if reference not in settings.INTEGRATION_ERRORS:
|
||||
settings.INTEGRATION_ERRORS[reference] = []
|
||||
if reference not in plugin_reg.errors:
|
||||
plugin_reg.errors[reference] = []
|
||||
|
||||
# add error to stack
|
||||
settings.INTEGRATION_ERRORS[reference].append(error)
|
||||
plugin_reg.errors[reference].append(error)
|
||||
|
||||
|
||||
class IntegrationPluginError(Exception):
|
||||
|
@ -41,7 +41,12 @@ class Plugins:
|
||||
|
||||
# flags
|
||||
self.is_loading = False
|
||||
self.apps_loading = True # Marks if apps were reloaded yet
|
||||
self.apps_loading = True # Marks if apps were reloaded yet
|
||||
|
||||
# integration specific
|
||||
self.installed_apps = [] # Holds all added plugin_paths
|
||||
|
||||
self.errors = {} # Holds discovering errors
|
||||
|
||||
# region public plugin functions
|
||||
def load_plugins(self):
|
||||
@ -265,7 +270,7 @@ class Plugins:
|
||||
plugin_path = self._get_plugin_path(plugin)
|
||||
if plugin_path not in settings.INSTALLED_APPS:
|
||||
settings.INSTALLED_APPS += [plugin_path]
|
||||
settings.INTEGRATION_APPS_PATHS += [plugin_path]
|
||||
self.installed_apps += [plugin_path]
|
||||
apps_changed = True
|
||||
|
||||
# if apps were changed or force loading base apps -> reload
|
||||
@ -288,7 +293,7 @@ class Plugins:
|
||||
this is needed if plugins were loaded earlier and then reloaded as models and admins rely on imports
|
||||
those register models and admin in their respective objects (e.g. admin.site for admin)
|
||||
"""
|
||||
for plugin_path in settings.INTEGRATION_APPS_PATHS:
|
||||
for plugin_path in self.installed_apps:
|
||||
try:
|
||||
app_name = plugin_path.split('.')[-1]
|
||||
app_config = apps.get_app_config(app_name)
|
||||
@ -332,7 +337,7 @@ class Plugins:
|
||||
def deactivate_integration_app(self):
|
||||
"""deactivate integration app - some magic required"""
|
||||
# unregister models from admin
|
||||
for plugin_path in settings.INTEGRATION_APPS_PATHS:
|
||||
for plugin_path in self.installed_apps:
|
||||
models = [] # the modelrefs need to be collected as poping an item in a iter is not welcomed
|
||||
app_name = plugin_path.split('.')[-1]
|
||||
try:
|
||||
@ -370,11 +375,11 @@ class Plugins:
|
||||
self._update_urls()
|
||||
|
||||
def _clean_installed_apps(self):
|
||||
for plugin in settings.INTEGRATION_APPS_PATHS:
|
||||
for plugin in self.installed_apps:
|
||||
if plugin in settings.INSTALLED_APPS:
|
||||
settings.INSTALLED_APPS.remove(plugin)
|
||||
|
||||
settings.INTEGRATION_APPS_PATHS = []
|
||||
self.installed_apps = []
|
||||
|
||||
def _clean_registry(self):
|
||||
# remove all plugins from registry
|
||||
|
@ -57,4 +57,4 @@ def safe_url(view_name, *args, **kwargs):
|
||||
@register.simple_tag()
|
||||
def plugin_errors(*args, **kwargs):
|
||||
"""Return all plugin errors"""
|
||||
return djangosettings.INTEGRATION_ERRORS
|
||||
return plugin_reg.errors
|
||||
|
Loading…
Reference in New Issue
Block a user