diff --git a/doc/development/api/general.rst b/doc/development/api/general.rst index 5c135c3ab8..aa6dfae8a5 100644 --- a/doc/development/api/general.rst +++ b/doc/development/api/general.rst @@ -57,7 +57,7 @@ Vouchers """""""" .. automodule:: pretix.control.signals - :members: voucher_form_class, voucher_form_html + :members: voucher_form_class, voucher_form_html, voucher_form_validation Dashboards """""""""" diff --git a/src/pretix/control/forms/vouchers.py b/src/pretix/control/forms/vouchers.py index 605fde7dba..6d62d3192c 100644 --- a/src/pretix/control/forms/vouchers.py +++ b/src/pretix/control/forms/vouchers.py @@ -8,6 +8,7 @@ from django.utils.translation import pgettext_lazy, ugettext_lazy as _ from pretix.base.forms import I18nModelForm from pretix.base.models import Item, ItemVariation, Quota, Voucher +from pretix.control.signals import voucher_form_validation class VoucherForm(I18nModelForm): @@ -121,6 +122,8 @@ class VoucherForm(I18nModelForm): if 'code' in data and Voucher.objects.filter(Q(code=data['code']) & Q(event=self.instance.event) & ~Q(pk=self.instance.pk)).exists(): raise ValidationError(_('A voucher with this code already exists.')) + voucher_form_validation.send(sender=self.instance.event, form=self, data=data) + return data def _clean_quota_needs_checking(self, data): diff --git a/src/pretix/control/signals.py b/src/pretix/control/signals.py index 629b0dd0c2..cf3e011084 100644 --- a/src/pretix/control/signals.py +++ b/src/pretix/control/signals.py @@ -133,6 +133,17 @@ You will receive the default form class (or the class set by a previous plugin) As with all plugin signals, the ``sender`` keyword argument will contain the event. """ +voucher_form_validation = EventPluginSignal( + providing_args=['form'] +) +""" +This signal allows you to add additional validation to the form that is used for +creating and modifying vouchers. You will receive the form instance in the ``form`` +argument and the current data state in the ``data`` argument. + +As with all plugin signals, the ``sender`` keyword argument will contain the event. +""" + quota_detail_html = EventPluginSignal( providing_args=['quota'] )