2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-04 06:18:48 +00:00

settings per plugin

This commit is contained in:
Matthias 2021-09-17 22:44:11 +02:00
parent d5f022f2cb
commit 682ee87267
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
3 changed files with 39 additions and 0 deletions

View File

@ -26,6 +26,8 @@ import yaml
from django.utils.translation import gettext_lazy as _
from django.contrib.messages import constants as messages
from plugins import plugins as inventree_plugins
def _is_true(x):
# 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.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)

View File

@ -827,6 +827,8 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'default': True,
'validator': bool,
},
**settings.INTEGRATION_PLUGIN_SETTINGS
}
class Meta:

View File

@ -20,6 +20,7 @@ class IntegrationPlugin(plugin.InvenTreePlugin):
plugin.InvenTreePlugin.__init__(self)
self.urls = self.setup_urls()
self.settings = self.setup_settings()
def setup_urls(self):
"""
@ -45,3 +46,23 @@ class IntegrationPlugin(plugin.InvenTreePlugin):
"""
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