forked from CGM_Public/pretix_original
Add is_available hook for plugin configs
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user