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: if not plugin:
# Cannot find associated plugin model, return # Cannot find associated plugin model, return
logger.error(f"Plugin configuration not found for plugin '{self.slug}'")
return # pragma: no cover return # pragma: no cover
PluginSetting.set_setting(key, value, user, plugin=plugin) PluginSetting.set_setting(key, value, user, plugin=plugin)

View File

@ -243,7 +243,7 @@ class PluginsRegistry:
# endregion # endregion
# region registry functions # 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 Returns reference to all plugins that have a specified mixin enabled
""" """
@ -251,6 +251,14 @@ class PluginsRegistry:
for plugin in self.plugins.values(): for plugin in self.plugins.values():
if plugin.mixin_enabled(mixin): 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) result.append(plugin)
return result return result

View File

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

View File

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