diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 7b511e0f9b..bd69fafc93 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -667,14 +667,13 @@ INTEGRATION_PLUGIN_LIST = {} for plugin in inventree_plugins.load_integration_plugins(): plugin = plugin() - plugin_name = plugin.plugin_name() INTEGRATION_PLUGINS.append(plugin) - INTEGRATION_PLUGIN_LIST[plugin_name] = plugin + INTEGRATION_PLUGIN_LIST[plugin.slug] = plugin if plugin.mixin_enabled('settings'): plugin_setting = plugin.settingspatterns - INTEGRATION_PLUGIN_SETTING[plugin_name] = plugin_setting + INTEGRATION_PLUGIN_SETTING[plugin.slug] = plugin_setting INTEGRATION_PLUGIN_SETTINGS.update(plugin_setting) if plugin.mixin_enabled('app'): diff --git a/InvenTree/plugins/integration.py b/InvenTree/plugins/integration.py index d376f7c651..f8641af6cd 100644 --- a/InvenTree/plugins/integration.py +++ b/InvenTree/plugins/integration.py @@ -8,6 +8,7 @@ import inspect from django.conf.urls import url, include from django.conf import settings +from django.utils.text import slugify import plugins.plugin as plugin @@ -82,7 +83,7 @@ class SettingsMixin: get patterns for InvenTreeSetting defintion """ if self.has_settings: - return {f'PLUGIN_{self.plugin_name().upper()}_{key}': value for key, value in self.settings.items()} + return {f'PLUGIN_{self.slug.upper()}_{key}': value for key, value in self.settings.items()} return None def get_setting(self, key): @@ -90,7 +91,7 @@ class SettingsMixin: get plugin setting by key """ from common.models import InvenTreeSetting - return InvenTreeSetting.get_setting(f'PLUGIN_{self.PLUGIN_NAME.upper()}_{key}') + return InvenTreeSetting.get_setting(f'PLUGIN_{self.slug.upper()}_{key}') class UrlsMixin: @@ -115,7 +116,14 @@ class UrlsMixin: """ returns base url for this plugin """ - return f'{settings.PLUGIN_URL}/{self.plugin_name()}/' + return f'{settings.PLUGIN_URL}/{self.slug}/' + + @property + def internal_name(self): + """ + returns the internal url pattern name + """ + return f'plugin:{self.slug}:' @property def urlpatterns(self): @@ -123,7 +131,7 @@ class UrlsMixin: returns the urlpatterns for this plugin """ if self.has_urls: - return url(f'^{self.plugin_name()}/', include((self.urls, self.plugin_name())), name=self.plugin_name()) + return url(f'^{self.slug}/', include((self.urls, self.slug)), name=self.slug) return None @property @@ -238,6 +246,12 @@ class IntegrationPluginBase(MixinBase, plugin.InvenTreePlugin): self.set_sign_values() + @property + def slug(self): + """slug for the plugin""" + name = getattr(self, 'PLUGIN_SLUG', self.plugin_name()) + return slugify(name) + def mixin(self, key): """check if mixin is registered""" return key in self._mixins diff --git a/InvenTree/plugins/samples/integration/sample.py b/InvenTree/plugins/samples/integration/sample.py index 447c39057a..34d5b78786 100644 --- a/InvenTree/plugins/samples/integration/sample.py +++ b/InvenTree/plugins/samples/integration/sample.py @@ -12,6 +12,7 @@ class SampleIntegrationPlugin(SettingsMixin, UrlsMixin, NavigationMixin, Integra """ PLUGIN_NAME = "SampleIntegrationPlugin" + PLUGIN_SLUG= "sample" def view_test(self, request): """very basic view""" @@ -38,5 +39,5 @@ class SampleIntegrationPlugin(SettingsMixin, UrlsMixin, NavigationMixin, Integra } NAVIGATION = [ - {'name': 'SampleIntegration', 'link': 'plugin:SampleIntegrationPlugin:hi'}, + {'name': 'SampleIntegration', 'link': 'plugin:sample:hi'}, ] diff --git a/InvenTree/plugins/test_integration.py b/InvenTree/plugins/test_integration.py index 0f28674021..0bfbbeb530 100644 --- a/InvenTree/plugins/test_integration.py +++ b/InvenTree/plugins/test_integration.py @@ -36,7 +36,7 @@ class SettingsMixinTest(BaseMixinDefinition, TestCase): self.assertEqual(self.mixin.settings, self.TEST_SETTINGS) # settings pattern - target_pattern = {f'PLUGIN_{self.mixin.plugin_name().upper()}_{key}': value for key, value in self.mixin.settings.items()} + target_pattern = {f'PLUGIN_{self.mixin.slug.upper()}_{key}': value for key, value in self.mixin.settings.items()} self.assertEqual(self.mixin.settingspatterns, target_pattern) # no settings