mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
PEP fix
This commit is contained in:
parent
9ae8474ed9
commit
da7dd0a4ac
@ -57,29 +57,30 @@ class PluginAppConfig(AppConfig):
|
|||||||
from plugin.models import PluginConfig
|
from plugin.models import PluginConfig
|
||||||
|
|
||||||
logger.info('Starting plugin initialisation')
|
logger.info('Starting plugin initialisation')
|
||||||
# Initialize integration plugins
|
# Initialize integration plugins
|
||||||
for plugin in inventree_plugins.load_integration_plugins():
|
for plugin in inventree_plugins.load_integration_plugins():
|
||||||
# check if package
|
# check if package
|
||||||
was_packaged = getattr(plugin, 'is_package', False)
|
was_packaged = getattr(plugin, 'is_package', False)
|
||||||
|
|
||||||
# check if activated
|
# check if activated
|
||||||
# these checks only use attributes - never use plugin supplied functions -> that would lead to arbitrary code execution!!
|
# these checks only use attributes - never use plugin supplied functions -> that would lead to arbitrary code execution!!
|
||||||
plug_name = plugin.PLUGIN_NAME
|
plug_name = plugin.PLUGIN_NAME
|
||||||
plug_key = plugin.PLUGIN_SLUG if getattr(plugin, 'PLUGIN_SLUG', None) else plug_name
|
plug_key = plugin.PLUGIN_SLUG if getattr(plugin, 'PLUGIN_SLUG', None) else plug_name
|
||||||
plugin_db_setting, _ = PluginConfig.objects.get_or_create(key=plug_key, name=plug_name)
|
plugin_db_setting, _ = PluginConfig.objects.get_or_create(key=plug_key, name=plug_name)
|
||||||
|
|
||||||
if plugin_db_setting.active:
|
if plugin_db_setting.active:
|
||||||
# init package
|
# init package
|
||||||
# now we can be sure that an admin has activated the plugin -> as of Nov 2021 there are not many checks in place
|
# now we can be sure that an admin has activated the plugin -> as of Nov 2021 there are not many checks in place
|
||||||
# but we could enhance those to check signatures, run the plugin against a whitelist etc.
|
# but we could enhance those to check signatures, run the plugin against a whitelist etc.
|
||||||
logger.info(f'Loading integration plugin {plugin.PLUGIN_NAME}')
|
logger.info(f'Loading integration plugin {plugin.PLUGIN_NAME}')
|
||||||
plugin = plugin()
|
plugin = plugin()
|
||||||
logger.info(f'Loaded integration plugin {plugin.slug}')
|
logger.info(f'Loaded integration plugin {plugin.slug}')
|
||||||
plugin.is_package = was_packaged
|
plugin.is_package = was_packaged
|
||||||
# safe reference
|
|
||||||
|
# safe reference
|
||||||
settings.INTEGRATION_PLUGINS[plugin.slug] = plugin
|
settings.INTEGRATION_PLUGINS[plugin.slug] = plugin
|
||||||
else:
|
else:
|
||||||
# save for later reference
|
# save for later reference
|
||||||
settings.INTEGRATION_PLUGINS_INACTIVE[plug_key] = plugin_db_setting
|
settings.INTEGRATION_PLUGINS_INACTIVE[plug_key] = plugin_db_setting
|
||||||
|
|
||||||
def activate_integration(self):
|
def activate_integration(self):
|
||||||
@ -115,21 +116,21 @@ class PluginAppConfig(AppConfig):
|
|||||||
settings.INTEGRATION_APPS_LOADED = True # ensure this section will not run again
|
settings.INTEGRATION_APPS_LOADED = True # ensure this section will not run again
|
||||||
apps_changed = False
|
apps_changed = False
|
||||||
|
|
||||||
# add them to the INSTALLED_APPS
|
# add them to the INSTALLED_APPS
|
||||||
for slug, plugin in plugins:
|
for slug, plugin in plugins:
|
||||||
if plugin.mixin_enabled('app'):
|
if plugin.mixin_enabled('app'):
|
||||||
try:
|
try:
|
||||||
# for local path plugins
|
# for local path plugins
|
||||||
plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(settings.BASE_DIR).parts)
|
plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(settings.BASE_DIR).parts)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# plugin is shipped as package
|
# plugin is shipped as package
|
||||||
plugin_path = plugin.PLUGIN_NAME
|
plugin_path = plugin.PLUGIN_NAME
|
||||||
if plugin_path not in settings.INSTALLED_APPS:
|
if plugin_path not in settings.INSTALLED_APPS:
|
||||||
settings.INSTALLED_APPS += [plugin_path]
|
settings.INSTALLED_APPS += [plugin_path]
|
||||||
apps_changed = True
|
apps_changed = True
|
||||||
|
|
||||||
# if apps were changed reload
|
# if apps were changed reload
|
||||||
# TODO this is a bit jankey to be honest
|
# TODO this is a bit jankey to be honest
|
||||||
if apps_changed:
|
if apps_changed:
|
||||||
apps.app_configs = OrderedDict()
|
apps.app_configs = OrderedDict()
|
||||||
apps.apps_ready = apps.models_ready = apps.loading = apps.ready = False
|
apps.apps_ready = apps.models_ready = apps.loading = apps.ready = False
|
||||||
|
Loading…
Reference in New Issue
Block a user