diff --git a/doc/development/api/payment.rst b/doc/development/api/payment.rst index c49070b562..e0ac64ab66 100644 --- a/doc/development/api/payment.rst +++ b/doc/development/api/payment.rst @@ -64,6 +64,8 @@ The provider class .. autoattribute:: settings_form_fields + .. automethod:: settings_form_clean + .. automethod:: settings_content_render .. automethod:: is_allowed diff --git a/src/pretix/base/payment.py b/src/pretix/base/payment.py index 3a653c6746..65ceee603b 100644 --- a/src/pretix/base/payment.py +++ b/src/pretix/base/payment.py @@ -267,6 +267,15 @@ class BasePaymentProvider: d['_restricted_countries']._as_type = list return d + def settings_form_clean(self, cleaned_data): + """ + Overriding this method allows you to inject custom validation into the settings form. + + :param cleaned_data: Form data as per previous validations. + :return: Please return the modified cleaned_data + """ + return cleaned_data + def settings_content_render(self, request: HttpRequest) -> str: """ When the event's administrator visits the event configuration diff --git a/src/pretix/control/forms/event.py b/src/pretix/control/forms/event.py index 43f166d769..1aff70866e 100644 --- a/src/pretix/control/forms/event.py +++ b/src/pretix/control/forms/event.py @@ -489,6 +489,7 @@ class ProviderForm(SettingsForm): def __init__(self, *args, **kwargs): self.settingspref = kwargs.pop('settingspref') + self.provider = kwargs.pop('provider', None) super().__init__(*args, **kwargs) def prepare_fields(self): @@ -515,6 +516,9 @@ class ProviderForm(SettingsForm): val = cleaned_data.get(k) if v._required and not val: self.add_error(k, _('This field is required.')) + if self.provider: + cleaned_data = self.provider.settings_form_clean(cleaned_data) + return cleaned_data class InvoiceSettingsForm(SettingsForm): @@ -1189,7 +1193,13 @@ class QuickSetupForm(I18nForm): "bank statements to process the payments within pretix, or mark them as paid manually."), required=False ) - payment_banktransfer_bank_details = BankTransfer.form_field(required=False) + btf = BankTransfer.form_fields() + payment_banktransfer_bank_details_type = btf['bank_details_type'] + payment_banktransfer_bank_details_sepa_name = btf['bank_details_sepa_name'] + payment_banktransfer_bank_details_sepa_iban = btf['bank_details_sepa_iban'] + payment_banktransfer_bank_details_sepa_bic = btf['bank_details_sepa_bic'] + payment_banktransfer_bank_details_sepa_bank = btf['bank_details_sepa_bank'] + payment_banktransfer_bank_details = btf['bank_details'] def __init__(self, *args, **kwargs): self.obj = kwargs.pop('event', None) @@ -1199,6 +1209,16 @@ class QuickSetupForm(I18nForm): if not self.obj.settings.payment_stripe_connect_client_id: del self.fields['payment_stripe__enabled'] self.fields['payment_banktransfer_bank_details'].required = False + for f in self.fields.values(): + if 'data-required-if' in f.widget.attrs: + del f.widget.attrs['data-required-if'] + + def clean(self): + cleaned_data = super().clean() + if cleaned_data.get('payment_banktransfer__enabled'): + provider = BankTransfer(self.obj) + cleaned_data = provider.settings_form_clean(cleaned_data) + return cleaned_data class QuickSetupProductForm(I18nForm): diff --git a/src/pretix/control/templates/pretixcontrol/event/quick_setup.html b/src/pretix/control/templates/pretixcontrol/event/quick_setup.html index f6c23f8dd7..a64ea41aa9 100644 --- a/src/pretix/control/templates/pretixcontrol/event/quick_setup.html +++ b/src/pretix/control/templates/pretixcontrol/event/quick_setup.html @@ -4,25 +4,27 @@ {% load formset_tags %} {% block title %}{{ request.event.name }}{% endblock %} {% block content %} -
- {% trans "You just created an event!" %} -
-- {% blocktrans trimmed %} - You can scroll down and create your first ticket products quickly, or you can use the navigation - on the left to modify the settings of your event in much more detail. - {% endblocktrans %} -
- ++ {% trans "You just created an event!" %} +
++ {% blocktrans trimmed %} + You can scroll down and create your first ticket products quickly, or you can use the navigation + on the left to modify the settings of your event in much more detail. + {% endblocktrans %} +
+ +