From b1fbac925d103539c56a5c57e29407f60c081337 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 20 Nov 2021 18:26:41 +0100 Subject: [PATCH] move stacks to registry --- InvenTree/InvenTree/settings.py | 3 --- InvenTree/plugin/helpers.py | 8 +++++--- InvenTree/plugin/registry.py | 17 +++++++++++------ InvenTree/plugin/templatetags/plugin_extras.py | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 9c1c14ce31..f02d832725 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -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) diff --git a/InvenTree/plugin/helpers.py b/InvenTree/plugin/helpers.py index 55d3305da8..6e09130d93 100644 --- a/InvenTree/plugin/helpers.py +++ b/InvenTree/plugin/helpers.py @@ -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): diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index da6659fffb..ca0bb1876f 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -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 diff --git a/InvenTree/plugin/templatetags/plugin_extras.py b/InvenTree/plugin/templatetags/plugin_extras.py index 140d2d5298..2d288647ac 100644 --- a/InvenTree/plugin/templatetags/plugin_extras.py +++ b/InvenTree/plugin/templatetags/plugin_extras.py @@ -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