move mixin registry stuff into own class

This commit is contained in:
Matthias 2021-09-19 17:12:16 +02:00
parent 5ce525400d
commit 369f92abf1
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -11,6 +11,15 @@ import plugins.plugin as plugin
logger = logging.getLogger("inventree") logger = logging.getLogger("inventree")
class MixinBase:
"""general base for mixins"""
def add_mixin(self, key: str, fnc_enabled=True, cls=None):
if not hasattr(self, '_mixins'):
self._mixins = {}
self._mixins[key] = fnc_enabled
# region mixins # region mixins
class SettingsMixin: class SettingsMixin:
"""Mixin that enables settings for the plugin""" """Mixin that enables settings for the plugin"""
@ -101,7 +110,7 @@ class NavigationMixin:
# endregion # endregion
class IntegrationPlugin(plugin.InvenTreePlugin): class IntegrationPlugin(MixinBase, plugin.InvenTreePlugin):
""" """
The IntegrationPlugin class is used to integrate with 3rd party software The IntegrationPlugin class is used to integrate with 3rd party software
""" """
@ -109,11 +118,6 @@ class IntegrationPlugin(plugin.InvenTreePlugin):
def __init__(self): def __init__(self):
self.add_mixin('base') self.add_mixin('base')
def add_mixin(self, key: str, fnc_enabled=True):
if not hasattr(self, '_mixins'):
self._mixins = {}
self._mixins[key] = fnc_enabled
def mixin(self, key): def mixin(self, key):
return key in self._mixins return key in self._mixins