legacy-views
legacy-views copied to clipboard
Address won't validate for Hong Kong
In settings.py I set DEFAULT_COUNTRY = 'HK' COUNTRIES_ONLY = ['HK']
I input a valid Hong Kong address and it keeps asking me to input an "Area" no matter what I put in there it gives me an error as shown.
The address fields are in the wrong order as well

Here are the validation rules It looks like there is already a drop down selection but you have to click inside the textbox to see it is one, I originally thought it was chrome's autofill
get_validation_rules({'country_code': 'HK'}) ValidationRules(country_code='HK', country_name='HONG KONG', address_format='%S%n%C%n%A%n%O%n%N', address_latin_format='%N%n%O%n%A%n%C%n%S', allowed_fields={'company_name', 'street_address', 'city', 'name', 'country_area'}, required_fields={'street_address', 'country_area'}, upper_fields={'country_area'}, country_area_type='area', country_area_choices=[('九龍', 'Kowloon'), ('九龍', '九龍'), ('香港島', 'Hong Kong Island'), ('香港島', '香港島'), ('新界', 'New Territories'), ('新界', '新界')], city_type='district', city_choices=[], city_area_type='suburb', city_area_choices=[], postal_code_type='postal', postal_code_matchers=[], postal_code_examples=[], postal_code_prefix='')
Once submitted however, I get an exception when I input any valid selection (In this case: Hong Kong Island)
Exception Value: | 'HK/香港島--en'
-- | --
KeyError at /checkout/shipping-address/
'HK/香港島--en'
Request Method: | POST
-- | --
http://localhost:8000/checkout/shipping-address/
2.0.2
KeyError
'HK/香港島--en'
/usr/local/lib/python3.6/site-packages/i18naddress/__init__.py in get_validation_rules, line 249
/usr/local/bin/python
3.6.4
['/app', '/usr/local/lib/python36.zip', '/usr/local/lib/python3.6', '/usr/local/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/site-packages', '/app']
Here is an address you can use for testing I got from http://www.bitboost.com/ref/international-address-formats/hong-kong/:
CHAN Kwok-kwong Flat 25, 12/F, Acacia Building 150 Kennedy Road WAN CHAI Hong Kong Island HONG KONG
For anyone else with this problem, I am just going to comment out the code in get_validation_rules in i18naddress/init.py, at least this way I can take orders instead of throwing exceptions
if 'sub_keys' in country_data:
country_area_keys = country_data['sub_keys'].split('~')
country_area_choices = _make_choices(country_data)
'''for language in languages:
localized_country_data = database[
'%s--%s' % (country_code, language)]
country_area_choices += _make_choices(
localized_country_data, translated=True)'''
country_area_choices = _compact_choices(
country_area_choices, country_area_keys)
country_area = _match_choices(
address.get('country_area'), country_area_choices)
I also had to customize the order submission process, had a lot of problems in the address area.
The problem is, from my perspective, that, for example, a shop can choose to supply in a single country, or can choose to omit several countries, etc. There's no way to provide different validation rules, etc, the only solution is monkeypatching.
I think there should be a list of problematic countries for which country area validation is not applied (any value accepted). Perhaps over time we can fix the individual issues affecting them (in this case different languages for areas within one country). But at least make the checkout process usable from all other countries which should be a major priority.
@tiberiuichim I can accept orders, but can't find a good way to reorder and rename the fields to something more logical (i.e. for Hong Kong city is actually asking for a district), could you share your solution?