<commit_before># -*- coding: utf-8 -*-
import re
from babel import Locale
from django import forms
from django.conf import settings
from django.contrib import messages
from django.contrib.localflavor.ca.forms import CAProvinceField, CAProvinceSelect
from django.contrib.localflavor.ca.ca_provinces import PROVINCE_CHOICES as CA_PROVINCE_CHOICES
from django.contrib.localflavor.de.forms import DEZipCodeField
from django.contrib.localflavor.us.forms import USStateField, USStateSelect, USZipCodeField
from django.contrib.localflavor.us.us_states import STATE_CHOICES as US_STATE_CHOICES
from django.http import QueryDict
from django.utils.translation import ugettext, ugettext_lazy as _

from apps.reaktor_auth.forms import CustomErrorList
from apps.reaktor.forms import ReaktorForm
from apps.reaktor.mapper import WST_MAP_EMPTY_VALUE_VARIANTS
from apps.reaktor_users import get_current_reaktor_user
from apps.reaktor_users.mapper import SETTINGS_FROM_API, SETTINGS_TO_API
from apps.reaktor_users.models import ReaktorUser

from apps.reaktor_barrel.basket.models import VoucherItem


##############################################################################
# BillingAddressForm start
##############################################################################


class BillingAddressForm(ReaktorForm):
    """
    Form for the billing address used in the checkout plugin.
    """
    first_name = forms.CharField(required=True,
        label = _('First Name'),
        widget=forms.TextInput(attrs={'placeholder': _('First Name')}))
    last_name = forms.CharField(required=True,
        label = _('Last Name'),
        widget=forms.TextInput(attrs={'placeholder': _('Last Name')}))
    address = forms.CharField(required=True,
        label = _('Address'),
        widget=forms.TextInput(attrs={'placeholder': _('Address')}))
    address_continued = forms.CharField(required=False,
        label =_('Address continued'),
        widget=forms.TextInput(attrs={'placeholder': _('Address continued')}))
    zipcode = forms.CharField(required=True,
        label = _('Zip code'),
        widget=forms.TextInput(attrs={'placeholder': _('Zip code')}))
    city = forms.CharField(required=True,
        label = _('City'),
        widget=forms.TextInput(attrs={'placeholder': _('City')}))
    # hidden fields
    billing_address_form = forms.BooleanField(required=True, widget=forms.HiddenInput)

    disabled_for_facebook_users = False
    disabled_fields_for_facebook_users = True
    reaktor_changed = False

    def _get_territories(self, territories):
        """Filter Babel territories to exclude non ISO 3166-2 territories.

        :param territores: Babel territories
        :return: filtered territories
        """
        result = {
            k: v for k, v in territories.items() if re.match(r'[a-zA-Z]{2}', k)
        }
        return result

    def _get_country_choices(self, country_code):
        """
        Get the available country choices.

        :param country_code: the shop's home country code
        :return: available country choices
        """
        # get the current locale
        if self.request.LANGUAGE_CODE:
            locale = Locale(self.request.LANGUAGE_CODE)
        else:
            locale = Locale('en')

        if country_code != 'WO': # international store
            return [(country_code,<commit_msg>add support for lang-country locales in search filter, checkout and catalog page info plugin<commit_after># -*- coding: utf-8 -*-
import re
from babel import Locale
from django import forms
from django.conf import settings
from django.contrib import messages
from django.contrib.localflavor.ca.forms import CAProvinceField, CAProvinceSelect
from django.contrib.localflavor.ca.ca_provinces import PROVINCE_CHOICES as CA_PROVINCE_CHOICES
from django.contrib.localflavor.de.forms import DEZipCodeField
from django.contrib.localflavor.us.forms import USStateField, USStateSelect, USZipCodeField
from django.contrib.localflavor.us.us_states import STATE_CHOICES as US_STATE_CHOICES
from django.http import QueryDict
from django.utils.translation import ugettext, ugettext_lazy as _

from apps.reaktor_auth.forms import CustomErrorList
from apps.reaktor.forms import ReaktorForm
from apps.reaktor.mapper import WST_MAP_EMPTY_VALUE_VARIANTS
from apps.reaktor_users import get_current_reaktor_user
from apps.reaktor_users.mapper import SETTINGS_FROM_API, SETTINGS_TO_API
from apps.reaktor_users.models import ReaktorUser

from apps.reaktor_barrel.basket.models import VoucherItem


##############################################################################
# BillingAddressForm start
##############################################################################


class BillingAddressForm(ReaktorForm):
    """
    Form for the billing address used in the checkout plugin.
    """
    first_name = forms.CharField(required=True,
        label = _('First Name'),
        widget=forms.TextInput(attrs={'placeholder': _('First Name')}))
    last_name = forms.CharField(required=True,
        label = _('Last Name'),
        widget=forms.TextInput(attrs={'placeholder': _('Last Name')}))
    address = forms.CharField(required=True,
        label = _('Address'),
        widget=forms.TextInput(attrs={'placeholder': _('Address')}))
    address_continued = forms.CharField(required=False,
        label =_('Address continued'),
        widget=forms.TextInput(attrs={'placeholder': _('Address continued')}))
    zipcode = forms.CharField(required=True,
        label = _('Zip code'),
        widget=forms.TextInput(attrs={'placeholder': _('Zip code')}))
    city = forms.CharField(required=True,
        label = _('City'),
        widget=forms.TextInput(attrs={'placeholder': _('City')}))
    # hidden fields
    billing_address_form = forms.BooleanField(required=True, widget=forms.HiddenInput)

    disabled_for_facebook_users = False
    disabled_fields_for_facebook_users = True
    reaktor_changed = False

    def _get_territories(self, territories):
        """Filter Babel territories to exclude non ISO 3166-2 territories.

        :param territores: Babel territories
        :return: filtered territories
        """
        result = {
            k: v for k, v in territories.items() if re.match(r'[a-zA-Z]{2}', k)
        }
        return result

    def _get_country_choices(self, country_code):
        """
        Get the available country choices.

        :param country_code: the shop's home country code
        :return: available country choices
        """
        # get the current locale
        if self.request.LANGUAGE_CODE:
            locale = Locale.parse(self.request.LANGUAGE_CODE, sep="-")
        else:
            locale = Locale.parse('en-us', sep="-")

        if country_code != 'WO': # international store
            return [(country_code,
{'fraction_non_alphanumeric': 0.13902724875476122, 'fraction_numerical': 0.0020509815411661296, 'mean_word_length': 3.9614825581395348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4462340', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1899, 'n_words': 464}