Allow registry.with_mixin to filter by active status

This commit is contained in:
Oliver 2022-05-19 11:00:31 +10:00
parent ebcb9685b5
commit 11b21a9cca
4 changed files with 12 additions and 3 deletions

View File

@ -60,6 +60,7 @@ class SettingsMixin:
if not plugin:
# Cannot find associated plugin model, return
logger.error(f"Plugin configuration not found for plugin '{self.slug}'")
return # pragma: no cover
PluginSetting.set_setting(key, value, user, plugin=plugin)

View File

@ -243,7 +243,7 @@ class PluginsRegistry:
# endregion
# region registry functions
def with_mixin(self, mixin: str):
def with_mixin(self, mixin: str, active=None):
"""
Returns reference to all plugins that have a specified mixin enabled
"""
@ -251,6 +251,14 @@ class PluginsRegistry:
for plugin in self.plugins.values():
if plugin.mixin_enabled(mixin):
if active is not None:
# Filter by 'enabled' status
config = plugin.plugin_config()
if config.active != active:
continue
result.append(plugin)
return result

View File

@ -58,7 +58,7 @@ class CustomPanelSample(PanelMixin, SettingsMixin, InvenTreePlugin):
panels = [
{
# This panel will not be displayed, as it is missing the 'content' key
# Simple panel without any actual content
'title': 'No Content',
}
]

View File

@ -29,7 +29,7 @@ class InvenTreePluginViewMixin:
panels = []
for plug in registry.with_mixin('panel'):
for plug in registry.with_mixin('panel', active=True):
try:
panels += plug.render_panels(self, self.request, ctx)