From 279ed78119652ca25862eae2ea4d163d60239f4c Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 17 Oct 2021 04:47:10 +0200 Subject: [PATCH] refactor --- InvenTree/InvenTree/settings.py | 4 ++-- InvenTree/InvenTree/urls.py | 2 +- InvenTree/part/templatetags/plugin_extras.py | 2 +- InvenTree/plugin/apps.py | 7 +++++-- InvenTree/plugin/loader.py | 2 +- InvenTree/plugin/test_plugin.py | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 0eaa5b592c..a4e7870143 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -753,10 +753,10 @@ for plugin in PLUGIN_DIRS: [PLUGINS.append(item) for item in modules] # collect integration plugins +INTEGRATION_PLUGINS = {} INTEGRATION_PLUGIN_SETTING = {} -INTEGRATION_PLUGIN_LIST = {} INTEGRATION_APPS_LOADED = False # Marks if apps were reloaded yet for plugin in inventree_plugins.load_integration_plugins(): plugin = plugin() - INTEGRATION_PLUGIN_LIST[plugin.slug] = plugin + INTEGRATION_PLUGINS[plugin.slug] = plugin diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 5145442f23..d0b7d1cedf 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -128,7 +128,7 @@ translated_javascript_urls = [ # Integration plugin urls interation_urls = [] if InvenTreeSetting.get_setting('ENABLE_PLUGINS_URL'): - for plugin in settings.INTEGRATION_PLUGIN_LIST.values(): + for plugin in settings.INTEGRATION_PLUGINS.values(): if plugin.mixin_enabled('urls'): interation_urls.append(plugin.urlpatterns) diff --git a/InvenTree/part/templatetags/plugin_extras.py b/InvenTree/part/templatetags/plugin_extras.py index 6f214340f7..e0592f8f28 100644 --- a/InvenTree/part/templatetags/plugin_extras.py +++ b/InvenTree/part/templatetags/plugin_extras.py @@ -12,7 +12,7 @@ register = template.Library() @register.simple_tag() def plugin_list(*args, **kwargs): """ Return a list of all installed integration plugins """ - return djangosettings.INTEGRATION_PLUGIN_LIST + return djangosettings.INTEGRATION_PLUGINS @register.simple_tag() diff --git a/InvenTree/plugin/apps.py b/InvenTree/plugin/apps.py index 639f43bd55..996aa4c8a4 100644 --- a/InvenTree/plugin/apps.py +++ b/InvenTree/plugin/apps.py @@ -12,13 +12,16 @@ class PluginConfig(AppConfig): def ready(self): from common.models import InvenTreeSetting + plugins = settings.INTEGRATION_PLUGINS.items() # if plugin settings are enabled enhance the settings if InvenTreeSetting.get_setting('ENABLE_PLUGINS_SETTING'): - for slug, plugin in settings.INTEGRATION_PLUGIN_LIST.items(): + for slug, plugin in plugins: if plugin.mixin_enabled('settings'): plugin_setting = plugin.settingspatterns settings.INTEGRATION_PLUGIN_SETTING[slug] = plugin_setting + + # Add to settings dir InvenTreeSetting.GLOBAL_SETTINGS.update(plugin_setting) # if plugin apps are enabled @@ -27,7 +30,7 @@ class PluginConfig(AppConfig): apps_changed = False # add them to the INSTALLED_APPS - for slug, plugin in settings.INTEGRATION_PLUGIN_LIST.items(): + for slug, plugin in plugins: if plugin.mixin_enabled('app'): plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(settings.BASE_DIR).parts) settings.INSTALLED_APPS += [plugin_path] diff --git a/InvenTree/plugin/loader.py b/InvenTree/plugin/loader.py index 5331418b24..21938f81c6 100644 --- a/InvenTree/plugin/loader.py +++ b/InvenTree/plugin/loader.py @@ -12,7 +12,7 @@ class PluginTemplateLoader(FilesystemLoader): def get_dirs(self): dirname = 'templates' template_dirs = [] - for plugin in settings.INTEGRATION_PLUGIN_LIST.values(): + for plugin in settings.INTEGRATION_PLUGINS.values(): new_path = Path(plugin.path) / dirname if Path(new_path).is_dir(): template_dirs.append(new_path) diff --git a/InvenTree/plugin/test_plugin.py b/InvenTree/plugin/test_plugin.py index 4e3248cb26..8ff47987b3 100644 --- a/InvenTree/plugin/test_plugin.py +++ b/InvenTree/plugin/test_plugin.py @@ -57,7 +57,7 @@ class PluginTagTests(TestCase): def test_tag_plugin_list(self): """test that all plugins are listed""" - self.assertEqual(plugin_tags.plugin_list(), settings.INTEGRATION_PLUGIN_LIST) + self.assertEqual(plugin_tags.plugin_list(), settings.INTEGRATION_PLUGINS) def test_tag_plugin_settings(self): """check all plugins are listed"""