mirror of
https://github.com/inventree/InvenTree.git
synced 2025-09-15 23:21:32 +00:00
Refactor: BaseInvenTreeSetting (#4834)
* Added typing for settings * Refactored common.BaseInvenTreeSetting model to make it more generic * Use older syntax for union types * Added protected option to typing * Remove now unused code * Remove old 'get_kwargs' method as it is replaced by 'get_filters_for_instance' * Trigger ci
This commit is contained in:
@@ -1,14 +1,25 @@
|
||||
"""Plugin mixin class for SettingsMixin."""
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Dict
|
||||
|
||||
from django.db.utils import OperationalError, ProgrammingError
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
# import only for typechecking, otherwise this throws a model is unready error
|
||||
if TYPE_CHECKING:
|
||||
from common.models import SettingsKeyType
|
||||
else:
|
||||
class SettingsKeyType:
|
||||
"""Dummy class, so that python throws no error"""
|
||||
pass
|
||||
|
||||
|
||||
class SettingsMixin:
|
||||
"""Mixin that enables global settings for the plugin."""
|
||||
|
||||
SETTINGS: Dict[str, SettingsKeyType] = {}
|
||||
|
||||
class MixinMeta:
|
||||
"""Meta for mixin."""
|
||||
MIXIN_NAME = 'Settings'
|
||||
@@ -56,7 +67,7 @@ class SettingsMixin:
|
||||
"""
|
||||
from plugin.models import PluginSetting
|
||||
|
||||
return PluginSetting.get_setting(key, plugin=self, cache=cache)
|
||||
return PluginSetting.get_setting(key, plugin=self.plugin_config(), cache=cache)
|
||||
|
||||
def set_setting(self, key, value, user=None):
|
||||
"""Set plugin setting value by key."""
|
||||
|
Reference in New Issue
Block a user