From 9eadcce0eb885b06e36e42d4c51fb6d9c5c52074 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 11 May 2022 14:48:36 +0200 Subject: [PATCH] move mixins --- InvenTree/plugin/plugin.py | 42 ++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/InvenTree/plugin/plugin.py b/InvenTree/plugin/plugin.py index 703482089e..0eefe42080 100644 --- a/InvenTree/plugin/plugin.py +++ b/InvenTree/plugin/plugin.py @@ -121,6 +121,26 @@ class MixinBase: self._mixins = {} 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): """ Add a mixin to the plugins registry @@ -274,28 +294,6 @@ class InvenTreePlugin(MixinBase, MetaBase): """ 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 def _get_package_commit(self): """