mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	settings per plugin
This commit is contained in:
		| @@ -26,6 +26,8 @@ import yaml | |||||||
| from django.utils.translation import gettext_lazy as _ | from django.utils.translation import gettext_lazy as _ | ||||||
| from django.contrib.messages import constants as messages | from django.contrib.messages import constants as messages | ||||||
|  |  | ||||||
|  | from plugins import plugins as inventree_plugins | ||||||
|  |  | ||||||
|  |  | ||||||
| def _is_true(x): | def _is_true(x): | ||||||
|     # Shortcut function to determine if a value "looks" like a boolean |     # Shortcut function to determine if a value "looks" like a boolean | ||||||
| @@ -646,3 +648,17 @@ MESSAGE_TAGS = { | |||||||
|     messages.ERROR: 'alert alert-block alert-danger', |     messages.ERROR: 'alert alert-block alert-danger', | ||||||
|     messages.INFO: 'alert alert-block alert-info', |     messages.INFO: 'alert alert-block alert-info', | ||||||
| } | } | ||||||
|  |  | ||||||
|  | # Plugins | ||||||
|  | INTEGRATION_PLUGINS = inventree_plugins.load_integration_plugins() | ||||||
|  |  | ||||||
|  | INTEGRATION_PLUGIN_SETTINGS = {} | ||||||
|  | INTEGRATION_PLUGIN_SETTING = {} | ||||||
|  | INTEGRATION_PLUGIN_LIST = {} | ||||||
|  |  | ||||||
|  | for plugin in INTEGRATION_PLUGINS: | ||||||
|  |     plugin = plugin() | ||||||
|  |     if plugin.has_settings: | ||||||
|  |         INTEGRATION_PLUGIN_LIST[plugin.plugin_name()] = plugin | ||||||
|  |         INTEGRATION_PLUGIN_SETTING[plugin.plugin_name()] = plugin.settingspatterns | ||||||
|  |         INTEGRATION_PLUGIN_SETTINGS.update(plugin.settingspatterns) | ||||||
|   | |||||||
| @@ -827,6 +827,8 @@ class InvenTreeSetting(BaseInvenTreeSetting): | |||||||
|             'default': True, |             'default': True, | ||||||
|             'validator': bool, |             'validator': bool, | ||||||
|         }, |         }, | ||||||
|  |  | ||||||
|  |         **settings.INTEGRATION_PLUGIN_SETTINGS | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     class Meta: |     class Meta: | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ class IntegrationPlugin(plugin.InvenTreePlugin): | |||||||
|         plugin.InvenTreePlugin.__init__(self) |         plugin.InvenTreePlugin.__init__(self) | ||||||
|  |  | ||||||
|         self.urls = self.setup_urls() |         self.urls = self.setup_urls() | ||||||
|  |         self.settings = self.setup_settings() | ||||||
|  |  | ||||||
|     def setup_urls(self): |     def setup_urls(self): | ||||||
|         """ |         """ | ||||||
| @@ -45,3 +46,23 @@ class IntegrationPlugin(plugin.InvenTreePlugin): | |||||||
|         """ |         """ | ||||||
|         return bool(self.urls) |         return bool(self.urls) | ||||||
|  |  | ||||||
|  |     def setup_settings(self): | ||||||
|  |         """ | ||||||
|  |         setup settings for this plugin | ||||||
|  |         """ | ||||||
|  |         if self.SETTINGS: | ||||||
|  |             return self.SETTINGS | ||||||
|  |         return None | ||||||
|  |  | ||||||
|  |     @property | ||||||
|  |     def has_settings(self): | ||||||
|  |         """ | ||||||
|  |         does this plugin use custom settings | ||||||
|  |         """ | ||||||
|  |         return bool(self.settings) | ||||||
|  |  | ||||||
|  |     @property | ||||||
|  |     def settingspatterns(self): | ||||||
|  |         if self.has_settings: | ||||||
|  |             return {f'PLUGIN_{self.plugin_name().upper()}_{key}': value for key, value in self.settings.items()} | ||||||
|  |         return None | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user