refactor into own helper function for plugins

This commit is contained in:
Matthias 2021-11-20 12:39:27 +01:00
parent 98b0a2995f
commit e82c93ffae
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
4 changed files with 14 additions and 12 deletions

View File

@ -697,12 +697,3 @@ def clean_decimal(number):
return Decimal(0) return Decimal(0)
return clean_number.quantize(Decimal(1)) if clean_number == clean_number.to_integral() else clean_number.normalize() 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)

View File

@ -51,7 +51,7 @@ class PluginAppConfig(AppConfig):
# region public plugin functions # region public plugin functions
def load_plugins(self): def load_plugins(self):
"""load and activate all IntegrationPlugins""" """load and activate all IntegrationPlugins"""
from InvenTree.helpers import log_plugin_error from plugin.helpers import log_plugin_error
logger.info('Start loading plugins') logger.info('Start loading plugins')
# set maintanace mode # set maintanace mode
@ -143,7 +143,7 @@ class PluginAppConfig(AppConfig):
:type disabled: str, optional :type disabled: str, optional
:raises error: PluginLoadingError :raises error: PluginLoadingError
""" """
from InvenTree.helpers import log_plugin_error from plugin.helpers import log_plugin_error
from plugin.models import PluginConfig from plugin.models import PluginConfig
logger.info('Starting plugin initialisation') logger.info('Starting plugin initialisation')

View File

@ -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)

View File

@ -27,7 +27,7 @@ def iter_namespace(pkg):
def get_modules(pkg, recursive: bool = False): def get_modules(pkg, recursive: bool = False):
"""get all modules in a package""" """get all modules in a package"""
from InvenTree.helpers import log_plugin_error from plugin.helpers import log_plugin_error
if not recursive: if not recursive:
return [importlib.import_module(name) for finder, name, ispkg in iter_namespace(pkg)] return [importlib.import_module(name) for finder, name, ispkg in iter_namespace(pkg)]