Ticket #10456: calocal.diff

File calocal.diff, 5.1 KB (added by mmulley, 15 years ago)

Patch (using correct postal abbreviations)

  • django/contrib/localflavor/ca/ca_provinces.py

     
     1# -*- coding: utf-8 -*-
    12"""
    23An alphabetical list of provinces and territories for use as `choices`
    34in a formfield., and a mapping of province misspellings/abbreviations to
     
    34normalized abbreviations
    45
    5 Source: http://www.canada.gc.ca/othergov/prov_e.html
     6Source: http://www.canadapost.ca/tools/pg/manual/PGaddress-e.asp#1380608
    67
    78This exists in this standalone file so that it's only imported into memory
     
    1415    ('BC', 'British Columbia'),
    1516    ('MB', 'Manitoba'),
    1617    ('NB', 'New Brunswick'),
    17     ('NF', 'Newfoundland and Labrador'),
     18    ('NL', 'Newfoundland and Labrador'),
    1819    ('NT', 'Northwest Territories'),
    1920    ('NS', 'Nova Scotia'),
    2021    ('NU', 'Nunavut'),
     
    2223    ('PE', 'Prince Edward Island'),
    2324    ('QC', 'Quebec'),
    2425    ('SK', 'Saskatchewan'),
    25     ('YK', 'Yukon')
     26    ('YT', 'Yukon')
    2627)
    2728
    2829PROVINCES_NORMALIZED = {
    2930    'ab': 'AB',
     31    'alta': 'AB',
     32    'alta.': 'AB',
    3033    'alberta': 'AB',
    3134    'bc': 'BC',
    3235    'b.c.': 'BC',
    3336    'british columbia': 'BC',
     37    'colombie-britannique': 'BC',
     38    'colombie britannique': 'BC',
     39    'cb': 'BC',
     40    'c-b': 'BC',
    3441    'mb': 'MB',
    3542    'manitoba': 'MB',
    3643    'nb': 'NB',
    3744    'new brunswick': 'NB',
    38     'nf': 'NF',
    39     'newfoundland': 'NF',
    40     'newfoundland and labrador': 'NF',
     45    'nouveau-brunswick': 'NB',
     46    'nouveau brunswick': 'NB',
     47    'nf': 'NL',
     48    'nl': 'NL',
     49    'newfoundland': 'NL',
     50    'newfoundland and labrador': 'NL',
     51    'nfld': 'NL',
     52    'nfld.': 'NL',
     53    'terre-neuve-et-labrador': 'NL',
     54    'terre-neuve et labrador': 'NL',
     55    'terre-neuve': 'NL',
    4156    'nt': 'NT',
    4257    'northwest territories': 'NT',
     58    'territoires du nord-ouest': 'NT',
    4359    'ns': 'NS',
    4460    'nova scotia': 'NS',
     61    'nouvelle-écosse': 'NS',
     62    'nouvelle-Écosse': 'NS',
     63    'nouvelle écosse': 'NS',
     64    'nouvelle Écosse': 'NS',
     65    'nouvelle-ecosse': 'NS',
     66    'nouvelle ecosse': 'NS',
    4567    'nu': 'NU',
    4668    'nunavut': 'NU',
    4769    'on': 'ON',
     
    5072    'pei': 'PE',
    5173    'p.e.i.': 'PE',
    5274    'prince edward island': 'PE',
     75    'île du prince édouard': 'PE',
     76    'Île du prince Édouard': 'PE',
     77    'ile du prince edouard': 'PE',
     78    'île-du-prince-édouard': 'PE',
     79    'Île-du-prince-Édouard': 'PE',
     80    'ile-du-prince-edouard': 'PE',
     81    'î.p.e.': 'PE',
     82    'i.p.e.': 'PE',
    5383    'qc': 'QC',
     84    'qu': 'QC',
     85    'pq': 'QC',
     86    'que': 'QC',
     87    'que.': 'QC',
    5488    'quebec': 'QC',
     89    'québec': 'QC',
     90    'quÉbec': 'QC',
    5591    'sk': 'SK',
    5692    'saskatchewan': 'SK',
    57     'yk': 'YK',
    58     'yukon': 'YK',
    59 }
    60  No newline at end of file
     93    'sask': 'SK',
     94    'sask.': 'SK',
     95    'yk': 'YT',
     96    'yt': 'YT',
     97    'yukon': 'YT',
     98    'yukon territory': 'YT',
     99}
  • django/contrib/localflavor/ca/forms.py

     
    2020    def __init__(self, *args, **kwargs):
    2121        super(CAPostalCodeField, self).__init__(r'^[ABCEGHJKLMNPRSTVXYZ]\d[A-Z] \d[A-Z]\d$',
    2222            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)
    2330
    2431class CAPhoneNumberField(Field):
    2532    """Canadian phone number field."""
  • tests/regressiontests/forms/localflavor/ca.py

     
    3737>>> f.clean('T2S 2H7')
    3838u'T2S 2H7'
    3939>>> f.clean('T2S2H7')
    40 Traceback (most recent call last):
    41 ...
    42 ValidationError: [u'Enter a postal code in the format XXX XXX.']
     40u'T2S 2H7'
     41>>> f.clean('t2s2h7')
     42u'T2S 2H7'
    4343>>> f.clean('T2S 2H')
    4444Traceback (most recent call last):
    4545...
     
    171171u'BC'
    172172>>> f.clean('nova scotia')
    173173u'NS'
     174>>> f.clean('nf')
     175u'NL'
     176>>> f.clean('québec  ')
     177u'QC'
    174178>>> f.clean('  manitoba ')
    175179u'MB'
    176180>>> f.clean('T2S 2H7')
     
    194198<option value="BC">British Columbia</option>
    195199<option value="MB">Manitoba</option>
    196200<option value="NB">New Brunswick</option>
    197 <option value="NF">Newfoundland and Labrador</option>
     201<option value="NL">Newfoundland and Labrador</option>
    198202<option value="NT">Northwest Territories</option>
    199203<option value="NS">Nova Scotia</option>
    200204<option value="NU">Nunavut</option>
     
    202206<option value="PE">Prince Edward Island</option>
    203207<option value="QC">Quebec</option>
    204208<option value="SK">Saskatchewan</option>
    205 <option value="YK">Yukon</option>
     209<option value="YT">Yukon</option>
    206210</select>
    207211
    208212# CASocialInsuranceNumberField #################################################
Back to Top