mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Make plugin dependencies optional by allowing plugins to report errors
This commit is contained in:
@@ -20,5 +20,6 @@ def get_all_plugins() -> "List[class]":
|
||||
if hasattr(app, 'PretixPluginMeta'):
|
||||
meta = app.PretixPluginMeta
|
||||
meta.module = app.name
|
||||
meta.app = app
|
||||
plugins.append(meta)
|
||||
return plugins
|
||||
|
||||
@@ -39,8 +39,9 @@ class EventPluginSignal(django.dispatch.Signal):
|
||||
|
||||
# Only fire receivers from active plugins
|
||||
if app.name in sender.get_plugins():
|
||||
response = receiver(signal=self, sender=sender, **named)
|
||||
responses.append((receiver, response))
|
||||
if not hasattr(app, 'compatibility_errors') or not app.compatibility_errors:
|
||||
response = receiver(signal=self, sender=sender, **named)
|
||||
responses.append((receiver, response))
|
||||
return responses
|
||||
|
||||
"""
|
||||
|
||||
@@ -14,6 +14,9 @@ td > .form-group > .checkbox {
|
||||
.has-success .form-control {
|
||||
border-color: #cccccc;
|
||||
}
|
||||
.panel-body div.alert:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-horizontal [data-formset] .form-group {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@@ -12,18 +12,19 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for plugin in plugins %}
|
||||
<div class="panel panel-{% if plugin.module in plugins_active %}success{% else %}default{% endif %}">
|
||||
<div class="panel panel-{% if plugin.app.compatibility_errors %}warning{% elif plugin.module in plugins_active %}success{% else %}default{% endif %}">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-sm-10">
|
||||
<h3 class="panel-title">{{ plugin.name }}</h3>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
{% if plugin.module in plugins_active %}
|
||||
{% if plugin.app.compatibility_errors %}
|
||||
<button class="btn disabled btn-block btn-default">{% trans "Incompatible" %}</button>
|
||||
{% elif plugin.module in plugins_active %}
|
||||
<button class="btn btn-default btn-block" name="plugin:{{ plugin.module }}" value="disable">{% trans "Disable" %}</button>
|
||||
{% else %}
|
||||
<button class="btn btn-primary btn-block" name="plugin:{{ plugin.module }}" value="enable">{% trans "Enable" %}</button>
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@@ -33,6 +34,26 @@
|
||||
Version {{ v }} by <em>{{ a }}</em>
|
||||
{% endblocktrans %}</p>
|
||||
<p>{{ plugin.description }}</p>
|
||||
{% if plugin.app.compatibility_errors %}
|
||||
<div class="alert alert-warning">
|
||||
{% trans "This plugin cannot be enabled for the following reasons:" %}
|
||||
<ul>
|
||||
{% for e in plugin.app.compatibility_errors %}
|
||||
<li>{{ e }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if plugin.app.compatibility_warnings %}
|
||||
<div class="alert alert-warning">
|
||||
{% trans "This plugin reports the following problems:" %}
|
||||
<ul>
|
||||
{% for e in plugin.app.compatibility_warnings %}
|
||||
<li>{{ e }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from pretix.base.plugins import PluginType
|
||||
|
||||
@@ -18,5 +19,14 @@ class BankTransferApp(AppConfig):
|
||||
def ready(self):
|
||||
from . import signals # NOQA
|
||||
|
||||
@cached_property
|
||||
def compatibility_warnings(self):
|
||||
errs = []
|
||||
try:
|
||||
import chardet
|
||||
except ImportError:
|
||||
errs.append(_("Install the python package 'chardet' for better CSV import capabilities."))
|
||||
return errs
|
||||
|
||||
|
||||
default_app_config = 'pretix.plugins.banktransfer.BankTransferApp'
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from pretix.base.plugins import PluginType
|
||||
|
||||
@@ -17,5 +18,13 @@ class PaypalApp(AppConfig):
|
||||
def ready(self):
|
||||
from . import signals # NOQA
|
||||
|
||||
@cached_property
|
||||
def compatibility_errors(self):
|
||||
errs = []
|
||||
try:
|
||||
import paypalrestsdk
|
||||
except ImportError:
|
||||
errs.append("Python package 'paypalrestsdk' is not installed.")
|
||||
return errs
|
||||
|
||||
default_app_config = 'pretix.plugins.paypal.PaypalApp'
|
||||
|
||||
@@ -2,9 +2,8 @@ from django.dispatch import receiver
|
||||
|
||||
from pretix.base.signals import register_payment_providers
|
||||
|
||||
from .payment import Paypal
|
||||
|
||||
|
||||
@receiver(register_payment_providers)
|
||||
def register_payment_provider(sender, **kwargs):
|
||||
from .payment import Paypal
|
||||
return Paypal
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from pretix.base.plugins import PluginType
|
||||
|
||||
@@ -18,5 +19,14 @@ class StripeApp(AppConfig):
|
||||
def ready(self):
|
||||
from . import signals # NOQA
|
||||
|
||||
@cached_property
|
||||
def compatibility_errors(self):
|
||||
errs = []
|
||||
try:
|
||||
import stripe
|
||||
except ImportError:
|
||||
errs.append("Python package 'stripe' is not installed.")
|
||||
return errs
|
||||
|
||||
|
||||
default_app_config = 'pretix.plugins.stripe.StripeApp'
|
||||
|
||||
@@ -5,17 +5,18 @@ from django.template.loader import get_template
|
||||
|
||||
from pretix.base.signals import register_payment_providers
|
||||
|
||||
from .payment import Stripe
|
||||
from pretix.presale.signals import html_head
|
||||
|
||||
|
||||
@receiver(register_payment_providers)
|
||||
def register_payment_provider(sender, **kwargs):
|
||||
from .payment import Stripe
|
||||
return Stripe
|
||||
|
||||
|
||||
@receiver(html_head)
|
||||
def html_head_presale(sender, request=None, **kwargs):
|
||||
from .payment import Stripe
|
||||
provider = Stripe(sender)
|
||||
url = resolve(request.path_info)
|
||||
if provider.is_enabled and "checkout.payment" in url.url_name:
|
||||
|
||||
Reference in New Issue
Block a user