forked from CGM_Public/pretix_original
Add phone number to customer profile (Z#178346) (#2414)
This commit is contained in:
committed by
GitHub
parent
cbdafac999
commit
768bb8c106
@@ -42,15 +42,11 @@ from django.utils.html import escape
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from phonenumber_field.formfields import PhoneNumberField
|
||||
from phonenumber_field.phonenumber import PhoneNumber
|
||||
from phonenumbers import NumberParseException
|
||||
from phonenumbers.data import _COUNTRY_CODE_TO_REGION_CODE
|
||||
|
||||
from pretix.base.forms.questions import (
|
||||
BaseInvoiceAddressForm, BaseQuestionsForm, WrappedPhoneNumberPrefixWidget,
|
||||
guess_country,
|
||||
guess_phone_prefix,
|
||||
)
|
||||
from pretix.base.i18n import get_babel_locale, language
|
||||
from pretix.base.validators import EmailBanlistValidator
|
||||
from pretix.presale.signals import contact_form_fields
|
||||
|
||||
@@ -75,27 +71,20 @@ class ContactForm(forms.Form):
|
||||
)
|
||||
|
||||
if self.event.settings.order_phone_asked:
|
||||
with language(get_babel_locale()):
|
||||
default_country = guess_country(self.event)
|
||||
default_prefix = None
|
||||
for prefix, values in _COUNTRY_CODE_TO_REGION_CODE.items():
|
||||
if str(default_country) in values:
|
||||
default_prefix = prefix
|
||||
try:
|
||||
initial = self.initial.pop('phone', None)
|
||||
initial = PhoneNumber().from_string(initial) if initial else "+{}.".format(default_prefix)
|
||||
except NumberParseException:
|
||||
initial = None
|
||||
self.fields['phone'] = PhoneNumberField(
|
||||
label=_('Phone number'),
|
||||
required=self.event.settings.order_phone_required,
|
||||
help_text=self.event.settings.checkout_phone_helptext,
|
||||
if not self.initial.get('phone'):
|
||||
phone_prefix = guess_phone_prefix(self.event)
|
||||
if phone_prefix:
|
||||
# We now exploit an implementation detail in PhoneNumberPrefixWidget to allow us to pass just
|
||||
# a country code but no number as an initial value. It's a bit hacky, but should be stable for
|
||||
# the future.
|
||||
initial=initial,
|
||||
widget=WrappedPhoneNumberPrefixWidget()
|
||||
)
|
||||
self.initial['phone'] = "+{}.".format(phone_prefix)
|
||||
|
||||
self.fields['phone'] = PhoneNumberField(
|
||||
label=_('Phone number'),
|
||||
required=self.event.settings.order_phone_required,
|
||||
help_text=self.event.settings.checkout_phone_helptext,
|
||||
widget=WrappedPhoneNumberPrefixWidget()
|
||||
)
|
||||
|
||||
if not self.request.session.get('iframe_session', False):
|
||||
# There is a browser quirk in Chrome that leads to incorrect initial scrolling in iframes if there
|
||||
|
||||
Reference in New Issue
Block a user