Ticket #10456: calocal-oldabbrevs.diff

File calocal-oldabbrevs.diff, 4.1 KB (added by mmulley, 15 years ago)

Patch (maintains old, incorrect 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
     8For backwards compatibility reasons, incorrect abbreviations (NF and YK)
     9are used for Newfoundland and the Yukon.
     10
    711This exists in this standalone file so that it's only imported into memory
    812when explicitly needed.
     
    2731
    2832PROVINCES_NORMALIZED = {
    2933    'ab': 'AB',
     34    'alta': 'AB',
     35    'alta.': 'AB',
    3036    'alberta': 'AB',
    3137    'bc': 'BC',
    3238    'b.c.': 'BC',
    3339    'british columbia': 'BC',
     40    'colombie-britannique': 'BC',
     41    'colombie britannique': 'BC',
     42    'cb': 'BC',
     43    'c-b': 'BC',
    3444    'mb': 'MB',
    3545    'manitoba': 'MB',
    3646    'nb': 'NB',
    3747    'new brunswick': 'NB',
     48    'nouveau-brunswick': 'NB',
     49    'nouveau brunswick': 'NB',
    3850    'nf': 'NF',
     51    'nl': 'NF',
    3952    'newfoundland': 'NF',
    4053    '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',
    4159    'nt': 'NT',
    4260    'northwest territories': 'NT',
     61    'territoires du nord-ouest': 'NT',
    4362    'ns': 'NS',
    4463    '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',
    4570    'nu': 'NU',
    4671    'nunavut': 'NU',
    4772    'on': 'ON',
     
    5075    'pei': 'PE',
    5176    'p.e.i.': 'PE',
    5277    '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',
    5386    'qc': 'QC',
     87    'qu': 'QC',
     88    'pq': 'QC',
     89    'que': 'QC',
     90    'que.': 'QC',
    5491    'quebec': 'QC',
     92    'québec': 'QC',
     93    'quÉbec': 'QC',
    5594    'sk': 'SK',
    5695    'saskatchewan': 'SK',
     96    'sask': 'SK',
     97    'sask.': 'SK',
    5798    'yk': 'YK',
     99    'yt': 'YK',
    58100    'yukon': 'YK',
    59 }
    60  No newline at end of file
     101    'yukon territory': 'YK',
     102}
  • 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'NF'
     176>>> f.clean('nl')
     177u'NF'
     178>>> f.clean('québec  ')
     179u'QC'
    174180>>> f.clean('  manitoba ')
    175181u'MB'
    176182>>> f.clean('T2S 2H7')
Back to Top