From e82c93ffaecdf573b399f80eeb64d5401cb268f0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 20 Nov 2021 12:39:27 +0100 Subject: [PATCH] refactor into own helper function for plugins --- InvenTree/InvenTree/helpers.py | 9 --------- InvenTree/plugin/apps.py | 4 ++-- InvenTree/plugin/helpers.py | 11 +++++++++++ InvenTree/plugin/plugins.py | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 InvenTree/plugin/helpers.py diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 829e845ce0..2b511bc09f 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -697,12 +697,3 @@ def clean_decimal(number): return Decimal(0) return clean_number.quantize(Decimal(1)) if clean_number == clean_number.to_integral() else clean_number.normalize() - - -def log_plugin_error(error, reference: str = 'general'): - # make sure the registry is set up - if reference not in settings.INTEGRATION_ERRORS: - settings.INTEGRATION_ERRORS[reference] = [] - - # add error to stack - settings.INTEGRATION_ERRORS[reference].append(error) diff --git a/InvenTree/plugin/apps.py b/InvenTree/plugin/apps.py index 1cfec7c2ed..b7ed20f365 100644 --- a/InvenTree/plugin/apps.py +++ b/InvenTree/plugin/apps.py @@ -51,7 +51,7 @@ class PluginAppConfig(AppConfig): # region public plugin functions def load_plugins(self): """load and activate all IntegrationPlugins""" - from InvenTree.helpers import log_plugin_error + from plugin.helpers import log_plugin_error logger.info('Start loading plugins') # set maintanace mode @@ -143,7 +143,7 @@ class PluginAppConfig(AppConfig): :type disabled: str, optional :raises error: PluginLoadingError """ - from InvenTree.helpers import log_plugin_error + from plugin.helpers import log_plugin_error from plugin.models import PluginConfig logger.info('Starting plugin initialisation') diff --git a/InvenTree/plugin/helpers.py b/InvenTree/plugin/helpers.py new file mode 100644 index 0000000000..1ebe146f41 --- /dev/null +++ b/InvenTree/plugin/helpers.py @@ -0,0 +1,11 @@ +"""Helpers for plugin app""" +from django.conf import settings + + +def log_plugin_error(error, reference: str = 'general'): + # make sure the registry is set up + if reference not in settings.INTEGRATION_ERRORS: + settings.INTEGRATION_ERRORS[reference] = [] + + # add error to stack + settings.INTEGRATION_ERRORS[reference].append(error) diff --git a/InvenTree/plugin/plugins.py b/InvenTree/plugin/plugins.py index a8b08cf6b4..66f841d95b 100644 --- a/InvenTree/plugin/plugins.py +++ b/InvenTree/plugin/plugins.py @@ -27,7 +27,7 @@ def iter_namespace(pkg): def get_modules(pkg, recursive: bool = False): """get all modules in a package""" - from InvenTree.helpers import log_plugin_error + from plugin.helpers import log_plugin_error if not recursive: return [importlib.import_module(name) for finder, name, ispkg in iter_namespace(pkg)]