Add is_available hook for plugin configs

This commit is contained in:
Raphael Michel
2019-01-12 16:54:37 +01:00
parent 75a966529e
commit d5ac155914
5 changed files with 13 additions and 5 deletions
+3
View File
@@ -79,6 +79,9 @@ human-readable error messages. We recommend using the ``django.utils.functional.
decorator, as it might get called a lot. You can also implement ``compatibility_warnings``,
those will be displayed but not block the plugin execution.
The ``AppConfig`` class may implement a method ``is_available(event)`` that checks if a plugin
is available for a specific event. If not, it will not be shown in the plugin list of that event.
Plugin registration
-------------------
+1 -1
View File
@@ -95,7 +95,7 @@ class EventSerializer(I18nAwareModelSerializer):
from pretix.base.plugins import get_all_plugins
plugins_available = {
p.module for p in get_all_plugins()
p.module for p in get_all_plugins(self.instance)
if not p.name.startswith('.') and getattr(p, 'visible', True)
}
+1 -1
View File
@@ -759,7 +759,7 @@ class Event(EventMixin, LoggedModel):
plugins_active = self.get_plugins()
plugins_available = {
p.module: p for p in get_all_plugins()
p.module: p for p in get_all_plugins(self)
if not p.name.startswith('.') and getattr(p, 'visible', True)
}
+6 -1
View File
@@ -17,7 +17,7 @@ class PluginType(Enum):
EXPORT = 4
def get_all_plugins() -> List[type]:
def get_all_plugins(event=None) -> List[type]:
"""
Returns the PretixPluginMeta classes of all plugins found in the installed Django apps.
"""
@@ -29,6 +29,11 @@ def get_all_plugins() -> List[type]:
meta.app = app
if app.name in settings.PRETIX_PLUGINS_EXCLUDE:
continue
if hasattr(app, 'is_available') and event:
if not app.is_available(event):
continue
plugins.append(meta)
return sorted(
plugins,
+2 -2
View File
@@ -188,7 +188,7 @@ class EventPlugins(EventSettingsViewMixin, EventPermissionRequiredMixin, Templat
from pretix.base.plugins import get_all_plugins
context = super().get_context_data(*args, **kwargs)
context['plugins'] = [p for p in get_all_plugins() if not p.name.startswith('.')
context['plugins'] = [p for p in get_all_plugins(self.object) if not p.name.startswith('.')
and getattr(p, 'visible', True)]
context['plugins_active'] = self.object.get_plugins()
return context
@@ -204,7 +204,7 @@ class EventPlugins(EventSettingsViewMixin, EventPermissionRequiredMixin, Templat
self.object = self.get_object()
plugins_available = {
p.module: p for p in get_all_plugins()
p.module: p for p in get_all_plugins(self.object)
if not p.name.startswith('.') and getattr(p, 'visible', True)
}