Skip to content

Commit

Permalink
Get rid of PhonePrefixWidget
Browse files Browse the repository at this point in the history
We don't render any actual widgets in the core, phone number is always passed as a single string.
  • Loading branch information
patrys committed May 27, 2020
1 parent ea8e38c commit 31b1870
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 31 deletions.
4 changes: 2 additions & 2 deletions saleor/account/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .models import Address
from .validators import validate_possible_number
from .widgets import DatalistTextWidget, PhonePrefixWidget
from .widgets import DatalistTextWidget

COUNTRY_FORMS = {}
UNKNOWN_COUNTRIES = set()
Expand Down Expand Up @@ -107,7 +107,7 @@ class Meta:
"street_address_2": "Apartment, suite, unit, building, floor, etc",
}

phone = PossiblePhoneNumberFormField(widget=PhonePrefixWidget, required=False)
phone = PossiblePhoneNumberFormField(required=False)

def __init__(self, *args, **kwargs):
autocomplete_type = kwargs.pop("autocomplete_type", None)
Expand Down
30 changes: 1 addition & 29 deletions saleor/account/widgets.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
from django.forms import Select, TextInput
from phonenumber_field.widgets import PhoneNumberPrefixWidget
from phonenumbers import COUNTRY_CODE_TO_REGION_CODE

phone_prefixes = [
("+{}".format(k), "+{}".format(k))
for (k, v) in sorted(COUNTRY_CODE_TO_REGION_CODE.items())
]


class PhonePrefixWidget(PhoneNumberPrefixWidget):
"""Uses choices with tuple in a simple form of "+XYZ: +XYZ".
Workaround for an issue:
https://github.com/stefanfoulis/django-phonenumber-field/issues/82
"""

def __init__(self, attrs=None):
widgets = (Select(attrs=attrs, choices=phone_prefixes), TextInput())
# pylint: disable=bad-super-call
super(PhoneNumberPrefixWidget, self).__init__(widgets, attrs)

def value_from_datadict(self, data, files, name):
value = super().value_from_datadict(data, files, name)
# FIXME: this is a hack, we should not be using a multiwidget
# in forms used by the API but here we are
if not value and name in data:
value = data[name]
return value
from django.forms import Select


class DatalistTextWidget(Select):
Expand Down

0 comments on commit 31b1870

Please sign in to comment.