Generic helpers

Forms

class localflavor.generic.forms.BICFormField(*args, **kwargs)[source]

A BIC consists of 8 (BIC8) or 11 (BIC11) alphanumeric characters.

BICs are also known as SWIFT-BIC, BIC code, SWIFT ID, SWIFT code or ISO 9362.

https://en.wikipedia.org/wiki/ISO_9362

New in version 1.1.

class localflavor.generic.forms.DateField(input_formats=None, *args, **kwargs)[source]

A date input field which uses non-US date input formats by default.

class localflavor.generic.forms.DateTimeField(input_formats=None, *args, **kwargs)[source]

A date and time input field which uses non-US date and time input formats by default.

class localflavor.generic.forms.IBANFormField(use_nordea_extensions=False, include_countries=None, *args, **kwargs)[source]

An IBAN consists of up to 34 alphanumeric characters.

To limit validation to specific countries, set the ‘include_countries’ argument with a tuple or list of ISO 3166-1 alpha-2 codes. For example, include_countries=(‘NL’, ‘BE, ‘LU’).

A list of countries that use IBANs as part of SEPA is included for convenience. To use this feature, set include_countries=IBAN_SEPA_COUNTRIES as an argument to the field.

Example:

from django import forms
from localflavor.generic.forms import IBANFormField
from localflavor.generic.countries.sepa import IBAN_SEPA_COUNTRIES

class MyForm(forms.Form):
    iban = IBANFormField(include_countries=IBAN_SEPA_COUNTRIES)

In addition to validating official IBANs, this field can optionally validate unofficial IBANs that have been catalogued by Nordea by setting the use_nordea_extensions argument to True.

https://en.wikipedia.org/wiki/International_Bank_Account_Number

New in version 1.1.

prepare_value(value)[source]

The display format for IBAN has a space every 4 characters.

class localflavor.generic.forms.SplitDateTimeField(input_date_formats=None, input_time_formats=None, *args, **kwargs)[source]

Split date and time input fields which use non-US date and time input formats by default.

Models

class localflavor.generic.models.BICField(*args, **kwargs)[source]

A BIC consists of 8 (BIC8) or 11 (BIC11) alphanumeric characters.

BICs are also known as SWIFT-BIC, BIC code, SWIFT ID, SWIFT code or ISO 9362.

https://en.wikipedia.org/wiki/ISO_9362

New in version 1.1.

class localflavor.generic.models.IBANField(*args, **kwargs)[source]

An IBAN consists of up to 34 alphanumeric characters.

To limit validation to specific countries, set the ‘include_countries’ argument with a tuple or list of ISO 3166-1 alpha-2 codes. For example, include_countries=(‘NL’, ‘BE, ‘LU’).

A list of countries that use IBANs as part of SEPA is included for convenience. To use this feature, set include_countries=IBAN_SEPA_COUNTRIES as an argument to the field.

Example:

from django.db import models
from localflavor.generic.models import IBANField
from localflavor.generic.countries.sepa import IBAN_SEPA_COUNTRIES

class MyModel(models.Model):
    iban = IBANField(include_countries=IBAN_SEPA_COUNTRIES)

In addition to validating official IBANs, this field can optionally validate unofficial IBANs that have been catalogued by Nordea by setting the use_nordea_extensions argument to True.

https://en.wikipedia.org/wiki/International_Bank_Account_Number

New in version 1.1.

Checksums

Common checksum routines.

localflavor.generic.checksums.luhn(candidate)[source]

Checks a candidate number for validity according to the Luhn algorithm (used in validation of, for example, credit cards). Both numeric and string candidates are accepted.

localflavor.generic.checksums.ean(candidate)[source]

Checks a candidate number for validity according to the EAN checksum calculation. Note that this validator does not enforce any length checks (usually 13 or 8).

http://en.wikipedia.org/wiki/International_Article_Number_(EAN)

New in version 1.1.

Validators

class localflavor.generic.validators.BICValidator[source]

A validator for SWIFT Business Identifier Codes (ISO 9362:2009). Validation is based on the BIC structure found on wikipedia.

https://en.wikipedia.org/wiki/ISO_9362#Structure

deconstruct(obj)

Returns a 3-tuple of class import path, positional arguments, and keyword arguments.

class localflavor.generic.validators.EANValidator(strip_nondigits=False, message=None)[source]

A generic validator for EAN like codes with the last digit being the checksum.

http://en.wikipedia.org/wiki/International_Article_Number_(EAN)

deconstruct(obj)

Returns a 3-tuple of class import path, positional arguments, and keyword arguments.

class localflavor.generic.validators.IBANValidator(use_nordea_extensions=False, include_countries=None)[source]

A validator for International Bank Account Numbers (IBAN - ISO 13616-1:2007).

deconstruct(obj)

Returns a 3-tuple of class import path, positional arguments, and keyword arguments.

static iban_checksum(value)[source]

Returns check digits for an input IBAN number. Original checksum in input value is ignored.

New in version 1.1.

Data

localflavor.generic.countries.iso_3166.ISO_3166_1_ALPHA2_COUNTRY_CODES = ('AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW', 'XK')

ISO 3166-1 country list. Sourced from https://www.iso.org/obp/ui on 2014-11-08

localflavor.generic.countries.sepa.IBAN_SEPA_COUNTRIES = ('AT', 'BE', 'BG', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GI', 'GR', 'HR', 'HU', 'IE', 'IS', 'IT', 'LI', 'LT', 'LU', 'LV', 'MC', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK', 'SM')

European Payments Council list of SEPA scheme countries as of 2 Sep 2015. http://www.europeanpaymentscouncil.eu/index.cfm/knowledge-bank/epc-documents/epc-list-of-sepa-scheme-countries/