diff --git a/pyproject.toml b/pyproject.toml index 01392a1f01..7b66f45b08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ dependencies = [ "django-markup", "django-oauth-toolkit==2.3.*", "django-otp==1.6.*", - "django-phonenumber-field==7.3.*", + "django-phonenumber-field==8.3.*", "django-redis==6.0.*", "django-scopes==2.0.*", "django-statici18n==2.6.*", diff --git a/src/pretix/base/forms/questions.py b/src/pretix/base/forms/questions.py index 7d810e3e84..e991084e04 100644 --- a/src/pretix/base/forms/questions.py +++ b/src/pretix/base/forms/questions.py @@ -66,8 +66,10 @@ from geoip2.errors import AddressNotFoundError from phonenumber_field.formfields import PhoneNumberField from phonenumber_field.phonenumber import PhoneNumber from phonenumber_field.widgets import PhoneNumberPrefixWidget -from phonenumbers import NumberParseException, national_significant_number -from phonenumbers.data import _COUNTRY_CODE_TO_REGION_CODE +from phonenumbers import ( + COUNTRY_CODE_TO_REGION_CODE, REGION_CODE_FOR_NON_GEO_ENTITY, + NumberParseException, national_significant_number, +) from PIL import ImageOps from pretix.base.forms.widgets import ( @@ -305,7 +307,9 @@ class WrappedPhonePrefixSelect(Select): choices = [("", "---------")] if initial: - for prefix, values in _COUNTRY_CODE_TO_REGION_CODE.items(): + for prefix, values in COUNTRY_CODE_TO_REGION_CODE.items(): + if all(v == REGION_CODE_FOR_NON_GEO_ENTITY for v in values): + continue if initial in values: self.initial = "+%d" % prefix break @@ -437,7 +441,9 @@ def guess_phone_prefix_from_request(request, event): def get_phone_prefix(country): - for prefix, values in _COUNTRY_CODE_TO_REGION_CODE.items(): + if country == REGION_CODE_FOR_NON_GEO_ENTITY: + return None + for prefix, values in COUNTRY_CODE_TO_REGION_CODE.items(): if country in values: return prefix return None diff --git a/src/pretix/helpers/countries.py b/src/pretix/helpers/countries.py index 9cd4c944b1..eeae03bd51 100644 --- a/src/pretix/helpers/countries.py +++ b/src/pretix/helpers/countries.py @@ -25,7 +25,9 @@ from django.utils import translation from django.utils.translation import gettext_noop from django_countries import Countries, collator from django_countries.fields import CountryField -from phonenumbers.data import _COUNTRY_CODE_TO_REGION_CODE +from phonenumbers import ( + COUNTRY_CODE_TO_REGION_CODE, REGION_CODE_FOR_NON_GEO_ENTITY, +) from pretix.base.i18n import get_babel_locale, get_language_without_region @@ -109,9 +111,11 @@ def get_phone_prefixes_sorted_and_localized(): val = [] locale = Locale(translation.to_locale(language)) - for prefix, values in _COUNTRY_CODE_TO_REGION_CODE.items(): + for prefix, values in COUNTRY_CODE_TO_REGION_CODE.items(): prefix = "+%d" % prefix for country_code in values: + if country_code == REGION_CODE_FOR_NON_GEO_ENTITY: + continue country_name = locale.territories.get(country_code) if country_name: val.append((prefix, "{} {}".format(country_name, prefix)))