Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move AddressForm to i18n module
Artur Smęt4c7737fc448e
diff --git a/saleor/userprofile/forms.py b/saleor/userprofile/forms.pyindex 3f861be958..2f4c50367b 100644--- a/saleor/userprofile/forms.py+++ b/saleor/userprofile/forms.py@@ -1,42 +1,31 @@# encoding: utf-8from __future__ import unicode_literals-from collections import defaultdict+from .i18n import AddressMetaForm, get_address_form_class, AddressForm-from django import forms-from .models import Address+def get_address_form(data, country_code, initial, instance, **kwargs):+ country_form = AddressMetaForm(data, initial=initial)+ preview = False+ if country_form.is_valid():+ country_code = country_form.cleaned_data['country']+ preview = country_form.cleaned_data['preview']-class AddressForm(forms.ModelForm):- AUTOCOMPLETE_MAPPING = (- ('first_name', 'given-name'),- ('last_name', 'family-name'),- ('company_name', 'organization'),- ('street_address_1', 'address-line1'),- ('street_address_2', 'address-line2'),- ('city', 'address-level2'),- ('postal_code', 'postal-code'),- ('country_area', 'address-level1'),- ('country', 'country'),- ('city_area', 'address-level3'),- ('phone', 'tel'),- ('email', 'email')- )+ address_form_class = get_address_form_class(country_code)- class Meta:- model = Address- exclude = []-- def __init__(self, *args, **kwargs):- autocomplete_type = kwargs.pop('autocomplete_type', None)- super(AddressForm, self).__init__(*args, **kwargs)- autocomplete_dict = defaultdict(- lambda: 'off', self.AUTOCOMPLETE_MAPPING)- for field_name, field in self.fields.items():- if autocomplete_type:- autocomplete = '%s %s' % (- autocomplete_type, autocomplete_dict[field_name])- else:- autocomplete = autocomplete_dict[field_name]- field.widget.attrs['autocomplete'] = autocomplete+ if not preview and instance is not None:+ address_form_class = get_address_form_class(+ instance.country.code)+ address_form = address_form_class(+ data, instance=instance,+ **kwargs)+ else:+ initial_address = (+ initial if not preview+ else data.dict() if data is not None else data)+ address_form = address_form_class(+ not preview and data or None,+ initial=initial_address,+ **kwargs)+ return address_form, preview