Ticket #10456: calocal-oldabbrevs.diff
File calocal-oldabbrevs.diff, 4.1 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 'nfld': 'NF', 55 'nfld.': 'NF', 56 'terre-neuve-et-labrador': 'NF', 57 'terre-neuve et labrador': 'NF', 58 'terre-neuve': 'NF', 41 59 'nt': 'NT', 42 60 'northwest territories': 'NT', 61 'territoires du nord-ouest': 'NT', 43 62 'ns': 'NS', 44 63 'nova scotia': 'NS', 64 'nouvelle-écosse': 'NS', 65 'nouvelle-Écosse': 'NS', 66 'nouvelle écosse': 'NS', 67 'nouvelle Écosse': 'NS', 68 'nouvelle-ecosse': 'NS', 69 'nouvelle ecosse': 'NS', 45 70 'nu': 'NU', 46 71 'nunavut': 'NU', 47 72 'on': 'ON', … … 50 75 'pei': 'PE', 51 76 'p.e.i.': 'PE', 52 77 'prince edward island': 'PE', 78 'île du prince édouard': 'PE', 79 'Île du prince Édouard': 'PE', 80 'ile du prince edouard': 'PE', 81 'île-du-prince-édouard': 'PE', 82 'Île-du-prince-Édouard': 'PE', 83 'ile-du-prince-edouard': 'PE', 84 'î.p.e.': 'PE', 85 'i.p.e.': 'PE', 53 86 'qc': 'QC', 87 'qu': 'QC', 88 'pq': 'QC', 89 'que': 'QC', 90 'que.': 'QC', 54 91 'quebec': 'QC', 92 'québec': 'QC', 93 'quÉbec': 'QC', 55 94 'sk': 'SK', 56 95 'saskatchewan': 'SK', 96 'sask': 'SK', 97 'sask.': 'SK', 57 98 'yk': 'YK', 99 'yt': 'YK', 58 100 'yukon': 'YK', 59 } 60 No newline at end of file 101 'yukon territory': 'YK', 102 } -
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')