diff --git a/InvenTree/plugin/builtin/integration/mixins.py b/InvenTree/plugin/builtin/integration/mixins.py index 3a6b558db7..c7edc8ac36 100644 --- a/InvenTree/plugin/builtin/integration/mixins.py +++ b/InvenTree/plugin/builtin/integration/mixins.py @@ -1,44 +1,45 @@ -"""default mixins for IntegrationMixins""" +""" +Plugin mixin classes +""" + from django.conf.urls import url, include from plugin.urls import PLUGIN_BASE -class GlobalSettingsMixin: - """Mixin that enables global settings for the plugin""" +class SettingsMixin: + """ + Mixin that enables global settings for the plugin + """ + class MixinMeta: - """meta options for this mixin""" - MIXIN_NAME = 'Global settings' + MIXIN_NAME = 'Settings' def __init__(self): super().__init__() - self.add_mixin('globalsettings', 'has_globalsettings', __class__) - self.globalsettings = self.setup_globalsettings() - - def setup_globalsettings(self): - """ - setup global settings for this plugin - """ - return getattr(self, 'GLOBALSETTINGS', None) + self.add_mixin('settings', 'has_globalsettings', __class__) + self.globalsettings = getattr(self, 'SETTINGS', None) @property def has_globalsettings(self): """ - does this plugin use custom global settings + Does this plugin use custom global settings """ return bool(self.globalsettings) @property def globalsettingspatterns(self): """ - get patterns for InvenTreeSetting defintion + Get patterns for InvenTreeSetting defintion """ if self.has_globalsettings: return {f'PLUGIN_{self.slug.upper()}_{key}': value for key, value in self.globalsettings.items()} return None def _globalsetting_name(self, key): - """get global name of setting""" + """ + Get global name of setting + """ return f'PLUGIN_{self.slug.upper()}_{key}' def get_globalsetting(self, key): @@ -57,9 +58,11 @@ class GlobalSettingsMixin: class UrlsMixin: - """Mixin that enables urls for the plugin""" + """ + Mixin that enables custom URLs for the plugin + """ + class MixinMeta: - """meta options for this mixin""" MIXIN_NAME = 'URLs' def __init__(self): @@ -105,7 +108,10 @@ class UrlsMixin: class NavigationMixin: - """Mixin that enables adding navigation links with the plugin""" + """ + Mixin that enables custom navigation links with the plugin + """ + NAVIGATION_TAB_NAME = None NAVIGATION_TAB_ICON = "fas fa-question" @@ -152,7 +158,10 @@ class NavigationMixin: class AppMixin: - """Mixin that enables full django app functions for a plugin""" + """ + Mixin that enables full django app functions for a plugin + """ + class MixinMeta: """meta options for this mixin""" MIXIN_NAME = 'App registration' diff --git a/InvenTree/plugin/mixins/__init__.py b/InvenTree/plugin/mixins/__init__.py index feb6bc3466..ceb5de5885 100644 --- a/InvenTree/plugin/mixins/__init__.py +++ b/InvenTree/plugin/mixins/__init__.py @@ -1,6 +1,9 @@ """utility class to enable simpler imports""" -from ..builtin.integration.mixins import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin +from ..builtin.integration.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin __all__ = [ - 'AppMixin', 'GlobalSettingsMixin', 'UrlsMixin', 'NavigationMixin', + 'AppMixin', + 'NavigationMixin', + 'SettingsMixin', + 'UrlsMixin', ] diff --git a/InvenTree/plugin/models.py b/InvenTree/plugin/models.py index b8178440af..811ed5b431 100644 --- a/InvenTree/plugin/models.py +++ b/InvenTree/plugin/models.py @@ -54,7 +54,11 @@ class PluginConfig(models.Model): # extra attributes from the registry def mixins(self): - return self.plugin._mixinreg + + if self.plugin: + return self.plugin._mixinreg + else: + return {} # functions diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index 4fc5330f8b..d858d6c7f0 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -251,7 +251,7 @@ class Plugins: if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_GLOBALSETTING'): logger.info('Registering IntegrationPlugin global settings') for slug, plugin in plugins: - if plugin.mixin_enabled('globalsettings'): + if plugin.mixin_enabled('settings'): plugin_setting = plugin.globalsettingspatterns self.mixins_globalsettings[slug] = plugin_setting diff --git a/InvenTree/plugin/samples/integration/sample.py b/InvenTree/plugin/samples/integration/sample.py index d7321f8a88..afc4a8fe8a 100644 --- a/InvenTree/plugin/samples/integration/sample.py +++ b/InvenTree/plugin/samples/integration/sample.py @@ -1,15 +1,18 @@ -"""sample implementations for IntegrationPlugin""" +""" +Sample implementations for IntegrationPlugin +""" + from plugin import IntegrationPluginBase -from plugin.mixins import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin +from plugin.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin from django.http import HttpResponse from django.utils.translation import ugettext_lazy as _ from django.conf.urls import url, include -class SampleIntegrationPlugin(AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin, IntegrationPluginBase): +class SampleIntegrationPlugin(AppMixin, SettingsMixin, UrlsMixin, NavigationMixin, IntegrationPluginBase): """ - An full integration plugin + A full integration plugin example """ PLUGIN_NAME = "SampleIntegrationPlugin" diff --git a/InvenTree/plugin/test_integration.py b/InvenTree/plugin/test_integration.py index df80016dc8..1371535cfa 100644 --- a/InvenTree/plugin/test_integration.py +++ b/InvenTree/plugin/test_integration.py @@ -8,7 +8,7 @@ from django.contrib.auth import get_user_model from datetime import datetime from plugin import IntegrationPluginBase -from plugin.mixins import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin +from plugin.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin from plugin.urls import PLUGIN_BASE @@ -20,19 +20,19 @@ class BaseMixinDefinition: self.assertEqual(self.mixin.registered_mixins[0]['human_name'], self.MIXIN_HUMAN_NAME) -class GlobalSettingsMixinTest(BaseMixinDefinition, TestCase): - MIXIN_HUMAN_NAME = 'Global settings' - MIXIN_NAME = 'globalsettings' +class SettingsMixinTest(BaseMixinDefinition, TestCase): + MIXIN_HUMAN_NAME = 'Settings' + MIXIN_NAME = 'settings' MIXIN_ENABLE_CHECK = 'has_globalsettings' TEST_SETTINGS = {'SETTING1': {'default': '123', }} def setUp(self): - class SettingsCls(GlobalSettingsMixin, IntegrationPluginBase): - GLOBALSETTINGS = self.TEST_SETTINGS + class SettingsCls(SettingsMixin, IntegrationPluginBase): + SETTINGS = self.TEST_SETTINGS self.mixin = SettingsCls() - class NoSettingsCls(GlobalSettingsMixin, IntegrationPluginBase): + class NoSettingsCls(SettingsMixin, IntegrationPluginBase): pass self.mixin_nothing = NoSettingsCls() diff --git a/InvenTree/templates/InvenTree/settings/mixins/urls.html b/InvenTree/templates/InvenTree/settings/mixins/urls.html index 1f317b5dc0..4bebfbce89 100644 --- a/InvenTree/templates/InvenTree/settings/mixins/urls.html +++ b/InvenTree/templates/InvenTree/settings/mixins/urls.html @@ -18,7 +18,7 @@
{% trans 'The code information is pulled from the latest git commit for this plugin. It might not reflect official version numbers or information but the actual code running.' %}
+