forked from CGM_Public/pretix_original
Allow plugins to disable and pre-fill questions and contact form fields (#1824)
Co-authored-by: Raphael Michel <michel@rami.io> Co-authored-by: Raphael Michel <mail@raphaelmichel.de>
This commit is contained in:
@@ -32,7 +32,9 @@ from pretix.presale.forms.checkout import (
|
||||
)
|
||||
from pretix.presale.signals import (
|
||||
checkout_all_optional, checkout_confirm_messages, checkout_flow_steps,
|
||||
contact_form_fields, order_meta_from_request, question_form_fields,
|
||||
contact_form_fields, contact_form_fields_overrides,
|
||||
order_meta_from_request, question_form_fields,
|
||||
question_form_fields_overrides,
|
||||
)
|
||||
from pretix.presale.views import (
|
||||
CartMixin, get_cart, get_cart_is_free, get_cart_total,
|
||||
@@ -423,6 +425,16 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
||||
return True
|
||||
return False
|
||||
|
||||
@cached_property
|
||||
def _contact_override_sets(self):
|
||||
return [
|
||||
resp for recv, resp in contact_form_fields_overrides.send(
|
||||
self.request.event,
|
||||
request=self.request,
|
||||
order=None,
|
||||
)
|
||||
]
|
||||
|
||||
@cached_property
|
||||
def contact_form(self):
|
||||
wd = self.cart_session.get('widget_data', {})
|
||||
@@ -433,14 +445,36 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
||||
)
|
||||
}
|
||||
initial.update(self.cart_session.get('contact_form_data', {}))
|
||||
|
||||
override_sets = self._contact_override_sets
|
||||
for overrides in override_sets:
|
||||
initial.update({
|
||||
k: v['initial'] for k, v in overrides.items() if 'initial' in v
|
||||
})
|
||||
|
||||
f = ContactForm(data=self.request.POST if self.request.method == "POST" else None,
|
||||
event=self.request.event,
|
||||
request=self.request,
|
||||
initial=initial, all_optional=self.all_optional)
|
||||
if wd.get('email', '') and wd.get('fix', '') == "true":
|
||||
f.fields['email'].disabled = True
|
||||
|
||||
for overrides in override_sets:
|
||||
for fname, val in overrides.items():
|
||||
if 'disabled' in val and fname in f.fields:
|
||||
f.fields[fname].disabled = val['disabled']
|
||||
|
||||
return f
|
||||
|
||||
def get_question_override_sets(self, cart_position):
|
||||
return [
|
||||
resp for recv, resp in question_form_fields_overrides.send(
|
||||
self.request.event,
|
||||
position=cart_position,
|
||||
request=self.request
|
||||
)
|
||||
]
|
||||
|
||||
@cached_property
|
||||
def eu_reverse_charge_relevant(self):
|
||||
return any([p.item.tax_rule and (p.item.tax_rule.eu_reverse_charge or p.item.tax_rule.custom_rules)
|
||||
@@ -466,6 +500,13 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
||||
else:
|
||||
wd_initial = {}
|
||||
initial = dict(wd_initial)
|
||||
|
||||
override_sets = self._contact_override_sets
|
||||
for overrides in override_sets:
|
||||
initial.update({
|
||||
k: v['initial'] for k, v in overrides.items() if 'initial' in v
|
||||
})
|
||||
|
||||
if not self.address_asked and self.request.event.settings.invoice_name_required:
|
||||
f = InvoiceNameForm(data=self.request.POST if self.request.method == "POST" else None,
|
||||
event=self.request.event,
|
||||
@@ -483,6 +524,12 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
||||
for name, field in f.fields.items():
|
||||
if wd_initial.get(name) and wd.get('fix', '') == 'true':
|
||||
field.disabled = True
|
||||
|
||||
for overrides in override_sets:
|
||||
for fname, val in overrides.items():
|
||||
if 'disabled' in val and fname in f.fields:
|
||||
f.fields[fname].disabled = val['disabled']
|
||||
|
||||
return f
|
||||
|
||||
@cached_property
|
||||
|
||||
Reference in New Issue
Block a user