mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
refactor into own helper function for plugins
This commit is contained in:
parent
98b0a2995f
commit
e82c93ffae
@ -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)
|
||||
|
@ -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')
|
||||
|
11
InvenTree/plugin/helpers.py
Normal file
11
InvenTree/plugin/helpers.py
Normal 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)
|
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user