# -*- coding: utf-8 -*- # Tests for the different contrib/localflavor/ form fields. localflavor_tests = r""" # USZipCodeField ############################################################## USZipCodeField validates that the data is either a five-digit U.S. zip code or a zip+4. >>> from django.contrib.localflavor.us.forms import USZipCodeField >>> f = USZipCodeField() >>> f.clean('60606') u'60606' >>> f.clean(60606) u'60606' >>> f.clean('04000') u'04000' >>> f.clean('4000') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.'] >>> f.clean('60606-1234') u'60606-1234' >>> f.clean('6060-1234') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.'] >>> f.clean('60606-') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = USZipCodeField(required=False) >>> f.clean('60606') u'60606' >>> f.clean(60606) u'60606' >>> f.clean('04000') u'04000' >>> f.clean('4000') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.'] >>> f.clean('60606-1234') u'60606-1234' >>> f.clean('6060-1234') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.'] >>> f.clean('60606-') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.'] >>> f.clean(None) u'' >>> f.clean('') u'' # USPhoneNumberField ########################################################## USPhoneNumberField validates that the data is a valid U.S. phone number, including the area code. It's normalized to XXX-XXX-XXXX format. >>> from django.contrib.localflavor.us.forms import USPhoneNumberField >>> f = USPhoneNumberField() >>> f.clean('312-555-1212') u'312-555-1212' >>> f.clean('3125551212') u'312-555-1212' >>> f.clean('312 555-1212') u'312-555-1212' >>> f.clean('(312) 555-1212') u'312-555-1212' >>> f.clean('312 555 1212') u'312-555-1212' >>> f.clean('312.555.1212') u'312-555-1212' >>> f.clean('312.555-1212') u'312-555-1212' >>> f.clean(' (312) 555.1212 ') u'312-555-1212' >>> f.clean('555-1212') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.'] >>> f.clean('312-55-1212') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = USPhoneNumberField(required=False) >>> f.clean('312-555-1212') u'312-555-1212' >>> f.clean('3125551212') u'312-555-1212' >>> f.clean('312 555-1212') u'312-555-1212' >>> f.clean('(312) 555-1212') u'312-555-1212' >>> f.clean('312 555 1212') u'312-555-1212' >>> f.clean('312.555.1212') u'312-555-1212' >>> f.clean('312.555-1212') u'312-555-1212' >>> f.clean(' (312) 555.1212 ') u'312-555-1212' >>> f.clean('555-1212') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.'] >>> f.clean('312-55-1212') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.'] >>> f.clean(None) u'' >>> f.clean('') u'' # USStateField ################################################################ USStateField validates that the data is either an abbreviation or name of a U.S. state. >>> from django.contrib.localflavor.us.forms import USStateField >>> f = USStateField() >>> f.clean('il') u'IL' >>> f.clean('IL') u'IL' >>> f.clean('illinois') u'IL' >>> f.clean(' illinois ') u'IL' >>> f.clean(60606) Traceback (most recent call last): ... ValidationError: [u'Enter a U.S. state or territory.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = USStateField(required=False) >>> f.clean('il') u'IL' >>> f.clean('IL') u'IL' >>> f.clean('illinois') u'IL' >>> f.clean(' illinois ') u'IL' >>> f.clean(60606) Traceback (most recent call last): ... ValidationError: [u'Enter a U.S. state or territory.'] >>> f.clean(None) u'' >>> f.clean('') u'' # USStateSelect ############################################################### USStateSelect is a Select widget that uses a list of U.S. states/territories as its choices. >>> from django.contrib.localflavor.us.forms import USStateSelect >>> w = USStateSelect() >>> print w.render('state', 'IL') # USSocialSecurityNumberField ################################################# >>> from django.contrib.localflavor.us.forms import USSocialSecurityNumberField >>> f = USSocialSecurityNumberField() >>> f.clean('987-65-4330') u'987-65-4330' >>> f.clean('987654330') u'987-65-4330' >>> f.clean('078-05-1120') Traceback (most recent call last): ... ValidationError: [u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.'] # UKPostcodeField ############################################################# UKPostcodeField validates that the data is a valid UK postcode. >>> from django.contrib.localflavor.uk.forms import UKPostcodeField >>> f = UKPostcodeField() >>> f.clean('BT32 4PX') u'BT32 4PX' >>> f.clean('GIR 0AA') u'GIR 0AA' >>> f.clean('BT324PX') Traceback (most recent call last): ... ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] >>> f.clean('1NV 4L1D') Traceback (most recent call last): ... ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = UKPostcodeField(required=False) >>> f.clean('BT32 4PX') u'BT32 4PX' >>> f.clean('GIR 0AA') u'GIR 0AA' >>> f.clean('1NV 4L1D') Traceback (most recent call last): ... ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] >>> f.clean('BT324PX') Traceback (most recent call last): ... ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] >>> f.clean(None) u'' >>> f.clean('') u'' # FRZipCodeField ############################################################# FRZipCodeField validates that the data is a valid FR zipcode. >>> from django.contrib.localflavor.fr.forms import FRZipCodeField >>> f = FRZipCodeField() >>> f.clean('75001') u'75001' >>> f.clean('93200') u'93200' >>> f.clean('2A200') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX.'] >>> f.clean('980001') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = FRZipCodeField(required=False) >>> f.clean('75001') u'75001' >>> f.clean('93200') u'93200' >>> f.clean('2A200') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX.'] >>> f.clean('980001') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX.'] >>> f.clean(None) u'' >>> f.clean('') u'' # FRPhoneNumberField ########################################################## FRPhoneNumberField validates that the data is a valid french phone number. It's normalized to 0X XX XX XX XX format. Dots are valid too. >>> from django.contrib.localflavor.fr.forms import FRPhoneNumberField >>> f = FRPhoneNumberField() >>> f.clean('01 55 44 58 64') u'01 55 44 58 64' >>> f.clean('0155445864') u'01 55 44 58 64' >>> f.clean('01 5544 5864') u'01 55 44 58 64' >>> f.clean('01 55.44.58.64') u'01 55 44 58 64' >>> f.clean('01.55.44.58.64') u'01 55 44 58 64' >>> f.clean('01,55,44,58,64') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] >>> f.clean('555 015 544') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = FRPhoneNumberField(required=False) >>> f.clean('01 55 44 58 64') u'01 55 44 58 64' >>> f.clean('0155445864') u'01 55 44 58 64' >>> f.clean('01 5544 5864') u'01 55 44 58 64' >>> f.clean('01 55.44.58.64') u'01 55 44 58 64' >>> f.clean('01.55.44.58.64') u'01 55 44 58 64' >>> f.clean('01,55,44,58,64') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] >>> f.clean('555 015 544') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] >>> f.clean(None) u'' >>> f.clean('') u'' # FRDepartmentSelect ############################################################### FRDepartmentSelect is a Select widget that uses a list of french departments including DOM TOM >>> from django.contrib.localflavor.fr.forms import FRDepartmentSelect >>> w = FRDepartmentSelect() >>> print w.render('dep', 'Paris') # JPPostalCodeField ############################################################### A form field that validates its input is a Japanese postcode. Accepts 7 digits(with/out hyphen). >>> from django.contrib.localflavor.jp.forms import JPPostalCodeField >>> f = JPPostalCodeField() >>> f.clean('251-0032') u'2510032' >>> f.clean('2510032') u'2510032' >>> f.clean('2510-032') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'] >>> f.clean('251a0032') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'] >>> f.clean('a51-0032') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'] >>> f.clean('25100321') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = JPPostalCodeField(required=False) >>> f.clean('251-0032') u'2510032' >>> f.clean('2510032') u'2510032' >>> f.clean('2510-032') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'] >>> f.clean('') u'' >>> f.clean(None) u'' # JPPrefectureSelect ############################################################### A Select widget that uses a list of Japanese prefectures as its choices. >>> from django.contrib.localflavor.jp.forms import JPPrefectureSelect >>> w = JPPrefectureSelect() >>> print w.render('prefecture', 'kanagawa') # ITZipCodeField ############################################################# >>> from django.contrib.localflavor.it.forms import ITZipCodeField >>> f = ITZipCodeField() >>> f.clean('00100') u'00100' >>> f.clean(' 00100') Traceback (most recent call last): ... ValidationError: [u'Enter a valid zip code.'] # ITRegionSelect ############################################################# >>> from django.contrib.localflavor.it.forms import ITRegionSelect >>> w = ITRegionSelect() >>> w.render('regions', 'PMN') u'' # ITSocialSecurityNumberField ################################################# >>> from django.contrib.localflavor.it.forms import ITSocialSecurityNumberField >>> f = ITSocialSecurityNumberField() >>> f.clean('LVSGDU99T71H501L') u'LVSGDU99T71H501L' >>> f.clean('LBRRME11A01L736W') u'LBRRME11A01L736W' >>> f.clean('lbrrme11a01l736w') u'LBRRME11A01L736W' >>> f.clean('LBR RME 11A01 L736W') u'LBRRME11A01L736W' >>> f.clean('LBRRME11A01L736A') Traceback (most recent call last): ... ValidationError: [u'Enter a valid Social Security number.'] >>> f.clean('%BRRME11A01L736W') Traceback (most recent call last): ... ValidationError: [u'Enter a valid Social Security number.'] # ITVatNumberField ########################################################### >>> from django.contrib.localflavor.it.forms import ITVatNumberField >>> f = ITVatNumberField() >>> f.clean('07973780013') u'07973780013' >>> f.clean('7973780013') u'07973780013' >>> f.clean(7973780013) u'07973780013' >>> f.clean('07973780014') Traceback (most recent call last): ... ValidationError: [u'Enter a valid VAT number.'] >>> f.clean('A7973780013') Traceback (most recent call last): ... ValidationError: [u'Enter a valid VAT number.'] # FIZipCodeField ############################################################# FIZipCodeField validates that the data is a valid FI zipcode. >>> from django.contrib.localflavor.fi.forms import FIZipCodeField >>> f = FIZipCodeField() >>> f.clean('20540') u'20540' >>> f.clean('20101') u'20101' >>> f.clean('20s40') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX.'] >>> f.clean('205401') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = FIZipCodeField(required=False) >>> f.clean('20540') u'20540' >>> f.clean('20101') u'20101' >>> f.clean('20s40') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX.'] >>> f.clean('205401') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX.'] >>> f.clean(None) u'' >>> f.clean('') u'' # FIMunicipalitySelect ############################################################### A Select widget that uses a list of Finnish municipalities as its choices. >>> from django.contrib.localflavor.fi.forms import FIMunicipalitySelect >>> w = FIMunicipalitySelect() >>> unicode(w.render('municipalities', 'turku')) u'' # FISocialSecurityNumber ############################################################## >>> from django.contrib.localflavor.fi.forms import FISocialSecurityNumber >>> f = FISocialSecurityNumber() >>> f.clean('010101-0101') u'010101-0101' >>> f.clean('010101+0101') u'010101+0101' >>> f.clean('010101A0101') u'010101A0101' >>> f.clean('101010-0102') Traceback (most recent call last): ... ValidationError: [u'Enter a valid Finnish social security number.'] >>> f.clean('10a010-0101') Traceback (most recent call last): ... ValidationError: [u'Enter a valid Finnish social security number.'] >>> f.clean('101010-0\xe401') Traceback (most recent call last): ... ValidationError: [u'Enter a valid Finnish social security number.'] >>> f.clean('101010b0101') Traceback (most recent call last): ... ValidationError: [u'Enter a valid Finnish social security number.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = FISocialSecurityNumber(required=False) >>> f.clean('010101-0101') u'010101-0101' >>> f.clean(None) u'' >>> f.clean('') u'' # BRZipCodeField ############################################################ >>> from django.contrib.localflavor.br.forms import BRZipCodeField >>> f = BRZipCodeField() >>> f.clean('12345-123') u'12345-123' >>> f.clean('12345_123') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX-XXX.'] >>> f.clean('1234-123') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX-XXX.'] >>> f.clean('abcde-abc') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX-XXX.'] >>> f.clean('12345-') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX-XXX.'] >>> f.clean('-123') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX-XXX.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = BRZipCodeField(required=False) >>> f.clean(None) u'' >>> f.clean('') u'' >>> f.clean('-123') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX-XXX.'] >>> f.clean('12345-') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX-XXX.'] >>> f.clean('abcde-abc') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX-XXX.'] >>> f.clean('1234-123') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX-XXX.'] >>> f.clean('12345_123') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX-XXX.'] >>> f.clean('12345-123') u'12345-123' # BRCNPJField ############################################################ >>> from django.contrib.localflavor.br.forms import BRCNPJField >>> f = BRCNPJField(required=True) >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('12-345-678/9012-10') Traceback (most recent call last): ... ValidationError: [u'Invalid CNPJ number.'] >>> f.clean('12.345.678/9012-10') Traceback (most recent call last): ... ValidationError: [u'Invalid CNPJ number.'] >>> f.clean('12345678/9012-10') Traceback (most recent call last): ... ValidationError: [u'Invalid CNPJ number.'] >>> f.clean('64.132.916/0001-88') '64.132.916/0001-88' >>> f.clean('64-132-916/0001-88') '64-132-916/0001-88' >>> f.clean('64132916/0001-88') '64132916/0001-88' >>> f.clean('64.132.916/0001-XX') Traceback (most recent call last): ... ValidationError: [u'This field requires only numbers.'] >>> f = BRCNPJField(required=False) >>> f.clean('') u'' # BRCPFField ################################################################# >>> from django.contrib.localflavor.br.forms import BRCPFField >>> f = BRCPFField() >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('489.294.654-54') Traceback (most recent call last): ... ValidationError: [u'Invalid CPF number.'] >>> f.clean('295.669.575-98') Traceback (most recent call last): ... ValidationError: [u'Invalid CPF number.'] >>> f.clean('539.315.127-22') Traceback (most recent call last): ... ValidationError: [u'Invalid CPF number.'] >>> f.clean('663.256.017-26') u'663.256.017-26' >>> f.clean('66325601726') u'66325601726' >>> f.clean('375.788.573-20') u'375.788.573-20' >>> f.clean('84828509895') u'84828509895' >>> f.clean('375.788.573-XX') Traceback (most recent call last): ... ValidationError: [u'This field requires only numbers.'] >>> f.clean('375.788.573-000') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at most 14 characters (it has 15).'] >>> f.clean('123.456.78') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at least 11 characters (it has 10).'] >>> f.clean('123456789555') Traceback (most recent call last): ... ValidationError: [u'This field requires at most 11 digits or 14 characters.'] >>> f = BRCPFField(required=False) >>> f.clean('') u'' >>> f.clean(None) u'' # BRPhoneNumberField ######################################################### >>> from django.contrib.localflavor.br.forms import BRPhoneNumberField >>> f = BRPhoneNumberField() >>> f.clean('41-3562-3464') u'41-3562-3464' >>> f.clean('4135623464') u'41-3562-3464' >>> f.clean('41 3562-3464') u'41-3562-3464' >>> f.clean('41 3562 3464') u'41-3562-3464' >>> f.clean('(41) 3562 3464') u'41-3562-3464' >>> f.clean('41.3562.3464') u'41-3562-3464' >>> f.clean('41.3562-3464') u'41-3562-3464' >>> f.clean(' (41) 3562.3464') u'41-3562-3464' >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = BRPhoneNumberField(required=False) >>> f.clean('') u'' >>> f.clean(None) u'' >>> f.clean(' (41) 3562.3464') u'41-3562-3464' >>> f.clean('41.3562-3464') u'41-3562-3464' >>> f.clean('(41) 3562 3464') u'41-3562-3464' >>> f.clean('4135623464') u'41-3562-3464' >>> f.clean('41 3562-3464') u'41-3562-3464' # BRStateSelect ############################################################## >>> from django.contrib.localflavor.br.forms import BRStateSelect >>> w = BRStateSelect() >>> w.render('states', 'PR') u'' # BRStateChoiceField ######################################################### >>> from django.contrib.localflavor.br.forms import BRStateChoiceField >>> f = BRStateChoiceField() >>> ', '.join([f.clean(s) for s, _ in f.widget.choices]) u'AC, AL, AP, AM, BA, CE, DF, ES, GO, MA, MT, MS, MG, PA, PB, PR, PE, PI, RJ, RN, RS, RO, RR, SC, SP, SE, TO' >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('pr') Traceback (most recent call last): ... ValidationError: [u'Select a valid brazilian state. That state is not one of the available states.'] # DEZipCodeField ############################################################## >>> from django.contrib.localflavor.de.forms import DEZipCodeField >>> f = DEZipCodeField() >>> f.clean('99423') u'99423' >>> f.clean(' 99423') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXXX.'] # DEStateSelect ############################################################# >>> from django.contrib.localflavor.de.forms import DEStateSelect >>> w = DEStateSelect() >>> w.render('states', 'TH') u'' # DEIdentityCardNumberField ################################################# >>> from django.contrib.localflavor.de.forms import DEIdentityCardNumberField >>> f = DEIdentityCardNumberField() >>> f.clean('7549313035D-6004103-0903042-0') u'7549313035D-6004103-0903042-0' >>> f.clean('9786324830D 6104243 0910271 2') u'9786324830D-6104243-0910271-2' >>> f.clean('0434657485D-6407276-0508137-9') Traceback (most recent call last): ... ValidationError: [u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.'] # CHZipCodeField ############################################################ >>> from django.contrib.localflavor.ch.forms import CHZipCodeField >>> f = CHZipCodeField() >>> f.clean('800x') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXX.'] >>> f.clean('80 00') Traceback (most recent call last): ... ValidationError: [u'Enter a zip code in the format XXXX.'] >>> f.clean('8000') u'8000' # CHPhoneNumberField ######################################################## >>> from django.contrib.localflavor.ch.forms import CHPhoneNumberField >>> f = CHPhoneNumberField() >>> f.clean('01234567890') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must be in 0XX XXX XX XX format.'] >>> f.clean('1234567890') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must be in 0XX XXX XX XX format.'] >>> f.clean('0123456789') u'012 345 67 89' # CHIdentityCardNumberField ################################################# >>> from django.contrib.localflavor.ch.forms import CHIdentityCardNumberField >>> f = CHIdentityCardNumberField() >>> f.clean('C1234567<0') u'C1234567<0' >>> f.clean('C1234567<1') Traceback (most recent call last): ... ValidationError: [u'Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.'] >>> f.clean('2123456700') u'2123456700' >>> f.clean('2123456701') Traceback (most recent call last): ... ValidationError: [u'Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.'] # CHStateSelect ############################################################# >>> from django.contrib.localflavor.ch.forms import CHStateSelect >>> w = CHStateSelect() >>> w.render('state', 'AG') u'' ## AUPostCodeField ########################################################## A field that accepts a four digit Australian post code. >>> from django.contrib.localflavor.au.forms import AUPostCodeField >>> f = AUPostCodeField() >>> f.clean('1234') u'1234' >>> f.clean('2000') u'2000' >>> f.clean('abcd') Traceback (most recent call last): ... ValidationError: [u'Enter a 4 digit post code.'] >>> f.clean('20001') Traceback (most recent call last): ... ValidationError: [u'Enter a 4 digit post code.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = AUPostCodeField(required=False) >>> f.clean('1234') u'1234' >>> f.clean('2000') u'2000' >>> f.clean('abcd') Traceback (most recent call last): ... ValidationError: [u'Enter a 4 digit post code.'] >>> f.clean('20001') Traceback (most recent call last): ... ValidationError: [u'Enter a 4 digit post code.'] >>> f.clean(None) u'' >>> f.clean('') u'' ## AUPhoneNumberField ######################################################## A field that accepts a 10 digit Australian phone number. llows spaces and parentheses around area code. >>> from django.contrib.localflavor.au.forms import AUPhoneNumberField >>> f = AUPhoneNumberField() >>> f.clean('1234567890') u'1234567890' >>> f.clean('0213456789') u'0213456789' >>> f.clean('02 13 45 67 89') u'0213456789' >>> f.clean('(02) 1345 6789') u'0213456789' >>> f.clean('(02) 1345-6789') u'0213456789' >>> f.clean('(02)1345-6789') u'0213456789' >>> f.clean('0408 123 456') u'0408123456' >>> f.clean('123') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must contain 10 digits.'] >>> f.clean('1800DJANGO') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must contain 10 digits.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = AUPhoneNumberField(required=False) >>> f.clean('1234567890') u'1234567890' >>> f.clean('0213456789') u'0213456789' >>> f.clean('02 13 45 67 89') u'0213456789' >>> f.clean('(02) 1345 6789') u'0213456789' >>> f.clean('(02) 1345-6789') u'0213456789' >>> f.clean('(02)1345-6789') u'0213456789' >>> f.clean('0408 123 456') u'0408123456' >>> f.clean('123') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must contain 10 digits.'] >>> f.clean('1800DJANGO') Traceback (most recent call last): ... ValidationError: [u'Phone numbers must contain 10 digits.'] >>> f.clean(None) u'' >>> f.clean('') u'' ## AUStateSelect ############################################################# AUStateSelect is a Select widget that uses a list of Australian states/territories as its choices. >>> from django.contrib.localflavor.au.forms import AUStateSelect >>> f = AUStateSelect() >>> print f.render('state', 'NSW') ## ISIdNumberField ############################################################# >>> from django.contrib.localflavor.is_.forms import * >>> f = ISIdNumberField() >>> f.clean('2308803449') u'230880-3449' >>> f.clean('230880-3449') u'230880-3449' >>> f.clean('230880 3449') u'230880-3449' >>> f.clean('230880343') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at least 10 characters (it has 9).'] >>> f.clean('230880343234') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at most 11 characters (it has 12).'] >>> f.clean('abcdefghijk') Traceback (most recent call last): ... ValidationError: [u'Enter a valid Icelandic identification number. The format is XXXXXX-XXXX.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('2308803439') Traceback (most recent call last): ... ValidationError: [u'The Icelandic identification number is not valid.'] >>> f.clean('2308803440') u'230880-3440' >>> f = ISIdNumberField(required=False) >>> f.clean(None) u'' >>> f.clean('') u'' ## ISPhoneNumberField ############################################################# >>> from django.contrib.localflavor.is_.forms import * >>> f = ISPhoneNumberField() >>> f.clean('1234567') u'1234567' >>> f.clean('123 4567') u'1234567' >>> f.clean('123-4567') u'1234567' >>> f.clean('123-456') Traceback (most recent call last): ... ValidationError: [u'Enter a valid value.'] >>> f.clean('123456') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at least 7 characters (it has 6).'] >>> f.clean('123456555') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at most 8 characters (it has 9).'] >>> f.clean('abcdefg') Traceback (most recent call last): ValidationError: [u'Enter a valid value.'] >>> f.clean(' 1234567 ') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at most 8 characters (it has 9).'] >>> f.clean(' 12367 ') Traceback (most recent call last): ... ValidationError: [u'Enter a valid value.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = ISPhoneNumberField(required=False) >>> f.clean(None) u'' >>> f.clean('') u'' ## ISPostalCodeSelect ############################################################# >>> from django.contrib.localflavor.is_.forms import * >>> f = ISPostalCodeSelect() >>> f.render('foo', 'bar') u'' ## CLRutField ############################################################# CLRutField is a Field that checks the validity of the Chilean personal identification number (RUT). It has two modes relaxed (default) and strict. >>> from django.contrib.localflavor.cl.forms import CLRutField >>> rut = CLRutField() >>> rut.clean('11-6') u'11-6' >>> rut.clean('116') u'11-6' # valid format, bad verifier. >>> rut.clean('11.111.111-0') Traceback (most recent call last): ... ValidationError: [u'The Chilean RUT is not valid.'] >>> rut.clean('111') Traceback (most recent call last): ... ValidationError: [u'The Chilean RUT is not valid.'] >>> rut.clean('767484100') u'76.748.410-0' >>> rut.clean('78.412.790-7') u'78.412.790-7' >>> rut.clean('8.334.6043') u'8.334.604-3' >>> rut.clean('76793310-K') u'76.793.310-K' Strict RUT usage (does not allow imposible values) >>> rut = CLRutField(strict=True) >>> rut.clean('11-6') Traceback (most recent call last): ... ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'] # valid format, bad verifier. >>> rut.clean('11.111.111-0') Traceback (most recent call last): ... ValidationError: [u'The Chilean RUT is not valid.'] # Correct input, invalid format. >>> rut.clean('767484100') Traceback (most recent call last): ... ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'] >>> rut.clean('78.412.790-7') u'78.412.790-7' >>> rut.clean('8.334.6043') Traceback (most recent call last): ... ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'] >>> rut.clean('76793310-K') Traceback (most recent call last): ... ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'] ## CLRegionSelect ######################################################### >>> from django.contrib.localflavor.cl.forms import CLRegionSelect >>> f = CLRegionSelect() >>> f.render('foo', 'bar') u'' # SKPostalCodeField ######################################################### >>> from django.contrib.localflavor.sk.forms import SKPostalCodeField >>> f = SKPostalCodeField() >>> f.clean('84545x') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.'] >>> f.clean('91909') u'91909' >>> f.clean('917 01') u'91701' # SKRegionSelect ############################################################ >>> from django.contrib.localflavor.sk.forms import SKRegionSelect >>> w = SKRegionSelect() >>> w.render('regions', 'TT') u'' # SKDistrictSelect ########################################################## >>> from django.contrib.localflavor.sk.forms import SKDistrictSelect >>> w = SKDistrictSelect() >>> w.render('Districts', 'RK') u'' # PLVoivodeshipSelect ########################################################## >>> from django.contrib.localflavor.pl.forms import PLVoivodeshipSelect >>> f = PLVoivodeshipSelect() >>> f.render('voivodeships','pomerania') u'' # PLAdministrativeUnitSelect ########################################################## >>> from django.contrib.localflavor.pl.forms import PLAdministrativeUnitSelect >>> f = PLAdministrativeUnitSelect() >>> f.render('administrativeunit','katowice') u'' # PLPostalCodeField ############################################################## >>> from django.contrib.localflavor.pl.forms import PLPostalCodeField >>> f = PLPostalCodeField() >>> f.clean('43--434') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format XX-XXX.'] >>> f.clean('41-403') u'41-403' # PLTaxNumberField ############################################################### >>> from django.contrib.localflavor.pl.forms import PLTaxNumberField >>> f = PLTaxNumberField() >>> f.clean('43-343-234-323') Traceback (most recent call last): ... ValidationError: [u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX or XX-XX-XXX-XXX.'] >>> f.clean('43-34-234-323') u'43-34-234-323' >>> f.clean('433-344-24-23') u'433-344-24-23' # PLNationalIdentificationNumberField ############################################ >>> from django.contrib.localflavor.pl.forms import PLNationalIdentificationNumberField >>> f = PLNationalIdentificationNumberField() >>> f.clean('80071610614') u'80071610614' >>> f.clean('80071610610') Traceback (most recent call last): ... ValidationError: [u'Wrong checksum for the National Identification Number.'] >>> f.clean('80') Traceback (most recent call last): ... ValidationError: [u'National Identification Number consists of 11 digits.'] >>> f.clean('800716106AA') Traceback (most recent call last): ... ValidationError: [u'National Identification Number consists of 11 digits.'] # NLPhoneNumberField ######################################################## >>> from django.contrib.localflavor.nl.forms import NLPhoneNumberField >>> f = NLPhoneNumberField(required=False) >>> f.clean('') u'' >>> f.clean('012-3456789') '012-3456789' >>> f.clean('0123456789') '0123456789' >>> f.clean('+31-12-3456789') '+31-12-3456789' >>> f.clean('(0123) 456789') '(0123) 456789' >>> f.clean('foo') Traceback (most recent call last): ... ValidationError: [u'Enter a valid phone number'] # NLZipCodeField ############################################################ >>> from django.contrib.localflavor.nl.forms import NLZipCodeField >>> f = NLZipCodeField(required=False) >>> f.clean('') u'' >>> f.clean('1234ab') u'1234 AB' >>> f.clean('1234 ab') u'1234 AB' >>> f.clean('1234 AB') u'1234 AB' >>> f.clean('0123AB') Traceback (most recent call last): ... ValidationError: [u'Enter a valid postal code'] >>> f.clean('foo') Traceback (most recent call last): ... ValidationError: [u'Enter a valid postal code'] # NLSoFiNumberField ######################################################### >>> from django.contrib.localflavor.nl.forms import NLSoFiNumberField >>> f = NLSoFiNumberField(required=False) >>> f.clean('') u'' >>> f.clean('123456782') '123456782' >>> f.clean('000000000') Traceback (most recent call last): ... ValidationError: [u'Enter a valid SoFi number'] >>> f.clean('123456789') Traceback (most recent call last): ... ValidationError: [u'Enter a valid SoFi number'] >>> f.clean('foo') Traceback (most recent call last): ... ValidationError: [u'Enter a valid SoFi number'] # NLProvinceSelect ########################################################## >>> from django.contrib.localflavor.nl.forms import NLProvinceSelect >>> s = NLProvinceSelect() >>> s.render('provinces', 'OV') u'' # ARProvinceField ############################################################# >>> from django.contrib.localflavor.ar.forms import ARProvinceSelect >>> f = ARProvinceSelect() >>> f.render('provincias', 'A') u'' # ARPostalCodeField ########################################################### >>> from django.contrib.localflavor.ar.forms import ARPostalCodeField >>> f = ARPostalCodeField() >>> f.clean('5000') u'5000' >>> f.clean('C1064AAB') u'C1064AAB' >>> f.clean('c1064AAB') u'C1064AAB' >>> f.clean('C1064aab') u'C1064AAB' >>> f.clean(u'4400') u'4400' >>> f.clean(u'C1064AAB') u'C1064AAB' >>> f.clean('C1064AABB') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at most 8 characters (it has 9).'] >>> f.clean('C1064AA') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format NNNN or ANNNNAAA.'] >>> f.clean('C106AAB') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format NNNN or ANNNNAAA.'] >>> f.clean('106AAB') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format NNNN or ANNNNAAA.'] >>> f.clean('500') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at least 4 characters (it has 3).'] >>> f.clean('5PPP') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format NNNN or ANNNNAAA.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean(u'') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = ARPostalCodeField(required=False) >>> f.clean('5000') u'5000' >>> f.clean('C1064AAB') u'C1064AAB' >>> f.clean('c1064AAB') u'C1064AAB' >>> f.clean('C1064aab') u'C1064AAB' >>> f.clean(u'4400') u'4400' >>> f.clean(u'C1064AAB') u'C1064AAB' >>> f.clean('C1064AABB') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at most 8 characters (it has 9).'] >>> f.clean('C1064AA') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format NNNN or ANNNNAAA.'] >>> f.clean('C106AAB') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format NNNN or ANNNNAAA.'] >>> f.clean('106AAB') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format NNNN or ANNNNAAA.'] >>> f.clean('500') Traceback (most recent call last): ... ValidationError: [u'Ensure this value has at least 4 characters (it has 3).'] >>> f.clean('5PPP') Traceback (most recent call last): ... ValidationError: [u'Enter a postal code in the format NNNN or ANNNNAAA.'] >>> f.clean(None) u'' >>> f.clean('') u'' >>> f.clean(u'') u'' # ARDNIField ################################################################## >>> from django.contrib.localflavor.ar.forms import ARDNIField >>> f = ARDNIField() >>> f.clean('20123456') u'20123456' >>> f.clean('20.123.456') u'20123456' >>> f.clean('9123456') u'9123456' >>> f.clean('9.123.456') u'9123456' >>> f.clean(u'20123456') u'20123456' >>> f.clean(u'20.123.456') u'20123456' >>> f.clean('20.123456') u'20123456' >>> f.clean('101234566') Traceback (most recent call last): ... ValidationError: [u'This field requires 7 or 8 digits.'] >>> f.clean('W0123456') Traceback (most recent call last): ... ValidationError: [u'This field requires only numbers.'] >>> f.clean('10,123,456') Traceback (most recent call last): ... ValidationError: [u'This field requires only numbers.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean(u'') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = ARDNIField(required=False) >>> f.clean('20123456') u'20123456' >>> f.clean('20.123.456') u'20123456' >>> f.clean('9123456') u'9123456' >>> f.clean('9.123.456') u'9123456' >>> f.clean(u'20123456') u'20123456' >>> f.clean(u'20.123.456') u'20123456' >>> f.clean('20.123456') u'20123456' >>> f.clean('101234566') Traceback (most recent call last): ... ValidationError: [u'This field requires 7 or 8 digits.'] >>> f.clean('W0123456') Traceback (most recent call last): ... ValidationError: [u'This field requires only numbers.'] >>> f.clean('10,123,456') Traceback (most recent call last): ... ValidationError: [u'This field requires only numbers.'] >>> f.clean(None) u'' >>> f.clean('') u'' >>> f.clean(u'') u'' # ARCUITField ################################################################# >>> from django.contrib.localflavor.ar.forms import ARCUITField >>> f = ARCUITField() >>> f.clean('20-10123456-9') u'20-10123456-9' >>> f.clean(u'20-10123456-9') u'20-10123456-9' >>> f.clean('27-10345678-4') u'27-10345678-4' >>> f.clean('20101234569') u'20-10123456-9' >>> f.clean('27103456784') u'27-10345678-4' >>> f.clean('2-10123456-9') Traceback (most recent call last): ... ValidationError: [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'] >>> f.clean('210123456-9') Traceback (most recent call last): ... ValidationError: [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'] >>> f.clean('20-10123456') Traceback (most recent call last): ... ValidationError: [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'] >>> f.clean('20-10123456-') Traceback (most recent call last): ... ValidationError: [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'] >>> f.clean('20-10123456-5') Traceback (most recent call last): ... ValidationError: [u'Invalid CUIT.'] >>> f.clean(u'2-10123456-9') Traceback (most recent call last): ... ValidationError: [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'] >>> f.clean('27-10345678-1') Traceback (most recent call last): ... ValidationError: [u'Invalid CUIT.'] >>> f.clean(u'27-10345678-1') Traceback (most recent call last): ... ValidationError: [u'Invalid CUIT.'] >>> f.clean(None) Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean(u'') Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f = ARCUITField(required=False) >>> f.clean('20-10123456-9') u'20-10123456-9' >>> f.clean(u'20-10123456-9') u'20-10123456-9' >>> f.clean('27-10345678-4') u'27-10345678-4' >>> f.clean('20101234569') u'20-10123456-9' >>> f.clean('27103456784') u'27-10345678-4' >>> f.clean('2-10123456-9') Traceback (most recent call last): ... ValidationError: [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'] >>> f.clean('210123456-9') Traceback (most recent call last): ... ValidationError: [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'] >>> f.clean('20-10123456') Traceback (most recent call last): ... ValidationError: [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'] >>> f.clean('20-10123456-') Traceback (most recent call last): ... ValidationError: [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'] >>> f.clean('20-10123456-5') Traceback (most recent call last): ... ValidationError: [u'Invalid CUIT.'] >>> f.clean(u'2-10123456-9') Traceback (most recent call last): ... ValidationError: [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'] >>> f.clean('27-10345678-1') Traceback (most recent call last): ... ValidationError: [u'Invalid CUIT.'] >>> f.clean(u'27-10345678-1') Traceback (most recent call last): ... ValidationError: [u'Invalid CUIT.'] >>> f.clean(None) u'' >>> f.clean('') u'' >>> f.clean(u'') u'' """