From 71f74f9cc41877aac576941e532d86f1c67f9604 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 20 Nov 2021 18:39:24 +0100 Subject: [PATCH] move globalsettings mixin reg to registry --- InvenTree/InvenTree/settings.py | 1 - InvenTree/plugin/registry.py | 8 +++++--- InvenTree/plugin/templatetags/plugin_extras.py | 2 +- InvenTree/plugin/test_plugin.py | 5 ++++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index f02d832725..724ff26c7c 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -882,7 +882,6 @@ if DEBUG or TESTING: PLUGIN_DIRS.append('plugin.samples') PLUGINS = [] -INTEGRATION_PLUGIN_GLOBALSETTING = {} # Test settings PLUGIN_TESTING = get_setting('PLUGIN_TESTING', TESTING) # used to force enable everything plugin diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index ca0bb1876f..bea13e032b 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -45,6 +45,8 @@ class Plugins: # integration specific self.installed_apps = [] # Holds all added plugin_paths + # mixins + self.mixins_globalsettings = {} self.errors = {} # Holds discovering errors @@ -228,7 +230,7 @@ class Plugins: for slug, plugin in plugins: if plugin.mixin_enabled('globalsettings'): plugin_setting = plugin.globalsettingspatterns - settings.INTEGRATION_PLUGIN_GLOBALSETTING[slug] = plugin_setting + self.mixins_globalsettings[slug] = plugin_setting # Add to settings dir InvenTreeSetting.GLOBAL_SETTINGS.update(plugin_setting) @@ -238,7 +240,7 @@ class Plugins: # collect all settings plugin_settings = {} - for _, plugin_setting in settings.INTEGRATION_PLUGIN_GLOBALSETTING.items(): + for _, plugin_setting in self.mixins_globalsettings.items(): plugin_settings.update(plugin_setting) # remove settings @@ -246,7 +248,7 @@ class Plugins: InvenTreeSetting.GLOBAL_SETTINGS.pop(setting) # clear cache - settings.INTEGRATION_PLUGIN_GLOBALSETTING = {} + self.mixins_globalsettings = {} # endregion # region integration_app diff --git a/InvenTree/plugin/templatetags/plugin_extras.py b/InvenTree/plugin/templatetags/plugin_extras.py index 2d288647ac..1b4b269844 100644 --- a/InvenTree/plugin/templatetags/plugin_extras.py +++ b/InvenTree/plugin/templatetags/plugin_extras.py @@ -28,7 +28,7 @@ def inactive_plugin_list(*args, **kwargs): @register.simple_tag() def plugin_globalsettings(plugin, *args, **kwargs): """ Return a list of all global settings for a plugin """ - return djangosettings.INTEGRATION_PLUGIN_GLOBALSETTING.get(plugin) + return plugin_reg.mixins_globalsettings.get(plugin) @register.simple_tag() diff --git a/InvenTree/plugin/test_plugin.py b/InvenTree/plugin/test_plugin.py index d127bd5be8..b3205ec16c 100644 --- a/InvenTree/plugin/test_plugin.py +++ b/InvenTree/plugin/test_plugin.py @@ -62,7 +62,10 @@ class PluginTagTests(TestCase): def test_tag_plugin_globalsettings(self): """check all plugins are listed""" - self.assertEqual(plugin_tags.plugin_globalsettings(self.sample), settings.INTEGRATION_PLUGIN_GLOBALSETTING.get(self.sample)) + self.assertEqual( + plugin_tags.plugin_globalsettings(self.sample), + plugin_reg.mixins_globalsettings.get(self.sample) + ) def test_tag_mixin_enabled(self): """check that mixin enabled functions work"""