Ticket #10456: calocal-compatible.diff
File calocal-compatible.diff, 4.7 KB (added by , 16 years ago) |
---|
-
django/contrib/localflavor/ca/ca_provinces.py
1 # -*- coding: utf-8 -*- 1 2 """ 2 3 An alphabetical list of provinces and territories for use as `choices` 3 4 in a formfield., and a mapping of province misspellings/abbreviations to … … 3 4 normalized abbreviations 4 5 5 Source: http://www.canada .gc.ca/othergov/prov_e.html6 Source: http://www.canadapost.ca/tools/pg/manual/PGaddress-e.asp#1380608 6 7 8 For backwards compatibility reasons, incorrect abbreviations (NF and YK) 9 are used for Newfoundland and the Yukon. 10 7 11 This exists in this standalone file so that it's only imported into memory 8 12 when explicitly needed. … … 27 31 28 32 PROVINCES_NORMALIZED = { 29 33 'ab': 'AB', 34 'alta': 'AB', 35 'alta.': 'AB', 30 36 'alberta': 'AB', 31 37 'bc': 'BC', 32 38 'b.c.': 'BC', 33 39 'british columbia': 'BC', 40 'colombie-britannique': 'BC', 41 'colombie britannique': 'BC', 42 'cb': 'BC', 43 'c-b': 'BC', 34 44 'mb': 'MB', 35 45 'manitoba': 'MB', 36 46 'nb': 'NB', 37 47 'new brunswick': 'NB', 48 'nouveau-brunswick': 'NB', 49 'nouveau brunswick': 'NB', 38 50 'nf': 'NF', 51 'nl': 'NF', 39 52 'newfoundland': 'NF', 40 53 'newfoundland and labrador': 'NF', 54 'labrador': 'NF', 55 'nfld': 'NF', 56 'nfld.': 'NF', 57 'terre-neuve-et-labrador': 'NF', 58 'terre-neuve et labrador': 'NF', 59 'terre-neuve': 'NF', 41 60 'nt': 'NT', 42 61 'northwest territories': 'NT', 62 'territoires du nord-ouest': 'NT', 43 63 'ns': 'NS', 44 64 'nova scotia': 'NS', 65 u'nouvelle-écosse': 'NS', 66 u'nouvelle-Écosse': 'NS', 67 u'nouvelle écosse': 'NS', 68 u'nouvelle Écosse': 'NS', 69 'nouvelle-ecosse': 'NS', 70 'nouvelle ecosse': 'NS', 45 71 'nu': 'NU', 46 72 'nunavut': 'NU', 47 73 'on': 'ON', … … 50 76 'pei': 'PE', 51 77 'p.e.i.': 'PE', 52 78 'prince edward island': 'PE', 79 u'île du prince édouard': 'PE', 80 u'Île du prince Édouard': 'PE', 81 'ile du prince edouard': 'PE', 82 u'île-du-prince-édouard': 'PE', 83 u'Île-du-prince-Édouard': 'PE', 84 'ile-du-prince-edouard': 'PE', 85 u'î.p.e.': 'PE', 86 'i.p.e.': 'PE', 53 87 'qc': 'QC', 88 'qu': 'QC', 89 'pq': 'QC', 90 'que': 'QC', 91 'que.': 'QC', 54 92 'quebec': 'QC', 93 u'québec': 'QC', 94 u'quÉbec': 'QC', 55 95 'sk': 'SK', 56 96 'saskatchewan': 'SK', 97 'sask': 'SK', 98 'sask.': 'SK', 57 99 'yk': 'YK', 100 'yt': 'YK', 58 101 'yukon': 'YK', 59 } 60 No newline at end of file 102 'yukon territory': 'YK', 103 } -
django/contrib/localflavor/ca/forms.py
20 20 def __init__(self, *args, **kwargs): 21 21 super(CAPostalCodeField, self).__init__(r'^[ABCEGHJKLMNPRSTVXYZ]\d[A-Z] \d[A-Z]\d$', 22 22 max_length=None, min_length=None, *args, **kwargs) 23 24 def clean(self, value): 25 if value: 26 value = str(value).upper() 27 if len(value) == 6: # Add a space if there isn't one 28 value = value[:3] + ' ' + value[3:] 29 return super(CAPostalCodeField, self).clean(value) 23 30 24 31 class CAPhoneNumberField(Field): 25 32 """Canadian phone number field.""" -
tests/regressiontests/forms/localflavor/ca.py
37 37 >>> f.clean('T2S 2H7') 38 38 u'T2S 2H7' 39 39 >>> f.clean('T2S2H7') 40 Traceback (most recent call last): 41 ... 42 ValidationError: [u'Enter a postal code in the format XXX XXX.'] 40 u'T2S 2H7' 41 >>> f.clean('t2s2h7') 42 u'T2S 2H7' 43 43 >>> f.clean('T2S 2H') 44 44 Traceback (most recent call last): 45 45 ... … … 171 171 u'BC' 172 172 >>> f.clean('nova scotia') 173 173 u'NS' 174 >>> f.clean('nf') 175 u'NF' 176 >>> f.clean('nl') 177 u'NF' 178 >>> f.clean('québec ') 179 u'QC' 174 180 >>> f.clean(' manitoba ') 175 181 u'MB' 176 182 >>> f.clean('T2S 2H7') -
docs/ref/contrib/localflavor.txt
206 206 .. class:: ca.forms.CAProvinceField 207 207 208 208 A form field that validates input as a Canadian province name or abbreviation. 209 Note that the normalized abbreviations used by this field are not standard 210 Canadian postal abbreviations (NF is used rather than the postal NL, YK 211 rather than YT). 209 212 210 213 .. class:: ca.forms.CASocialInsuranceNumberField 211 214