forked from CGM_Public/pretix_original
Fix address validation for attendee data
This commit is contained in:
@@ -573,6 +573,7 @@ class BaseQuestionsForm(forms.Form):
|
|||||||
the attendee name for admission tickets, if the corresponding setting is enabled,
|
the attendee name for admission tickets, if the corresponding setting is enabled,
|
||||||
as well as additional questions defined by the organizer.
|
as well as additional questions defined by the organizer.
|
||||||
"""
|
"""
|
||||||
|
address_validation = False
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@@ -920,8 +921,14 @@ class BaseQuestionsForm(forms.Form):
|
|||||||
v.widget.attrs['autocomplete'] = 'section-{} '.format(self.prefix) + v.widget.attrs.get('autocomplete', '')
|
v.widget.attrs['autocomplete'] = 'section-{} '.format(self.prefix) + v.widget.attrs.get('autocomplete', '')
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
from pretix.base.addressvalidation import \
|
||||||
|
validate_address # local import to prevent impact on startup time
|
||||||
|
|
||||||
d = super().clean()
|
d = super().clean()
|
||||||
|
|
||||||
|
if self.address_validation:
|
||||||
|
self.cleaned_data = d = validate_address(d, True)
|
||||||
|
|
||||||
if d.get('city') and d.get('country') and str(d['country']) in COUNTRIES_WITH_STATE_IN_ADDRESS:
|
if d.get('city') and d.get('country') and str(d['country']) in COUNTRIES_WITH_STATE_IN_ADDRESS:
|
||||||
if not d.get('state'):
|
if not d.get('state'):
|
||||||
self.add_error('state', _('This field is required.'))
|
self.add_error('state', _('This field is required.'))
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ class QuestionsForm(BaseQuestionsForm):
|
|||||||
as well as additional questions defined by the organizer.
|
as well as additional questions defined by the organizer.
|
||||||
"""
|
"""
|
||||||
required_css_class = 'required'
|
required_css_class = 'required'
|
||||||
|
address_validation = True
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
allow_save = kwargs.pop('allow_save', False)
|
allow_save = kwargs.pop('allow_save', False)
|
||||||
|
|||||||
Reference in New Issue
Block a user