2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-02 13:28:49 +00:00

move mixins

This commit is contained in:
Matthias 2022-05-11 14:48:36 +02:00
parent 355695c679
commit 9eadcce0eb
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093

View File

@ -121,6 +121,26 @@ class MixinBase:
self._mixins = {} self._mixins = {}
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def mixin(self, key):
"""
Check if mixin is registered
"""
return key in self._mixins
def mixin_enabled(self, key):
"""
Check if mixin is registered, enabled and ready
"""
if self.mixin(key):
fnc_name = self._mixins.get(key)
# Allow for simple case where the mixin is "always" ready
if fnc_name is True:
return True
return getattr(self, fnc_name, True)
return False
def add_mixin(self, key: str, fnc_enabled=True, cls=None): def add_mixin(self, key: str, fnc_enabled=True, cls=None):
""" """
Add a mixin to the plugins registry Add a mixin to the plugins registry
@ -274,28 +294,6 @@ class InvenTreePlugin(MixinBase, MetaBase):
""" """
return f'{reverse("settings")}#select-plugin-{self.slug}' return f'{reverse("settings")}#select-plugin-{self.slug}'
# region mixins
def mixin(self, key):
"""
Check if mixin is registered
"""
return key in self._mixins
def mixin_enabled(self, key):
"""
Check if mixin is registered, enabled and ready
"""
if self.mixin(key):
fnc_name = self._mixins.get(key)
# Allow for simple case where the mixin is "always" ready
if fnc_name is True:
return True
return getattr(self, fnc_name, True)
return False
# endregion
# region package info # region package info
def _get_package_commit(self): def _get_package_commit(self):
""" """