Author: jezdez Date: 2011-05-03 04:52:20 -0700 (Tue, 03 May 2011) New Revision: 16147
Added: django/trunk/django/contrib/localflavor/gb/ django/trunk/django/contrib/localflavor/gb/__init__.py django/trunk/django/contrib/localflavor/gb/forms.py django/trunk/django/contrib/localflavor/gb/gb_regions.py django/trunk/tests/regressiontests/forms/localflavor/gb.py Removed: django/trunk/tests/regressiontests/forms/localflavor/uk.py Modified: django/trunk/django/contrib/localflavor/uk/forms.py django/trunk/django/contrib/localflavor/uk/uk_regions.py django/trunk/docs/internals/deprecation.txt django/trunk/docs/ref/contrib/localflavor.txt django/trunk/tests/regressiontests/forms/localflavortests.py django/trunk/tests/regressiontests/forms/tests/__init__.py Log: Fixed #13729 -- Renamed UK localflavor to GB to correctly follow ISO 3166. Thanks, Claude Paroz. Added: django/trunk/django/contrib/localflavor/gb/__init__.py =================================================================== Copied: django/trunk/django/contrib/localflavor/gb/forms.py (from rev 16146, django/trunk/django/contrib/localflavor/uk/forms.py) =================================================================== --- django/trunk/django/contrib/localflavor/gb/forms.py (rev 0) +++ django/trunk/django/contrib/localflavor/gb/forms.py 2011-05-03 11:52:20 UTC (rev 16147) @@ -0,0 +1,53 @@ +""" +GB-specific Form helpers +""" + +import re + +from django.forms.fields import CharField, Select +from django.forms import ValidationError +from django.utils.translation import ugettext_lazy as _ + +class GBPostcodeField(CharField): + """ + A form field that validates its input is a UK postcode. + + The regular expression used is sourced from the schema for British Standard + BS7666 address types: http://www.govtalk.gov.uk/gdsc/schemas/bs7666-v2-0.xsd + + The value is uppercased and a space added in the correct place, if required. + """ + default_error_messages = { + 'invalid': _(u'Enter a valid postcode.'), + } + outcode_pattern = '[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|[0-9]|[ABEHMNPRVWXY]))|[0-9][A-HJKSTUW])' + incode_pattern = '[0-9][ABD-HJLNP-UW-Z]{2}' + postcode_regex = re.compile(r'^(GIR 0AA|%s %s)$' % (outcode_pattern, incode_pattern)) + space_regex = re.compile(r' *(%s)$' % incode_pattern) + + def clean(self, value): + value = super(GBPostcodeField, self).clean(value) + if value == u'': + return value + postcode = value.upper().strip() + # Put a single space before the incode (second part). + postcode = self.space_regex.sub(r' \1', postcode) + if not self.postcode_regex.search(postcode): + raise ValidationError(self.error_messages['invalid']) + return postcode + +class GBCountySelect(Select): + """ + A Select widget that uses a list of UK Counties/Regions as its choices. + """ + def __init__(self, attrs=None): + from gb_regions import GB_REGION_CHOICES + super(GBCountySelect, self).__init__(attrs, choices=GB_REGION_CHOICES) + +class GBNationSelect(Select): + """ + A Select widget that uses a list of UK Nations as its choices. + """ + def __init__(self, attrs=None): + from gb_regions import GB_NATIONS_CHOICES + super(GBNationSelect, self).__init__(attrs, choices=GB_NATIONS_CHOICES) Copied: django/trunk/django/contrib/localflavor/gb/gb_regions.py (from rev 16146, django/trunk/django/contrib/localflavor/uk/uk_regions.py) =================================================================== --- django/trunk/django/contrib/localflavor/gb/gb_regions.py (rev 0) +++ django/trunk/django/contrib/localflavor/gb/gb_regions.py 2011-05-03 11:52:20 UTC (rev 16147) @@ -0,0 +1,97 @@ +""" +Sources: + English regions: http://www.statistics.gov.uk/geography/downloads/31_10_01_REGION_names_and_codes_12_00.xls + Northern Ireland regions: http://en.wikipedia.org/wiki/List_of_Irish_counties_by_area + Welsh regions: http://en.wikipedia.org/wiki/Preserved_counties_of_Wales + Scottish regions: http://en.wikipedia.org/wiki/Regions_and_districts_of_Scotland +""" +from django.utils.translation import ugettext_lazy as _ + +ENGLAND_REGION_CHOICES = ( + ("Bedfordshire", _("Bedfordshire")), + ("Buckinghamshire", _("Buckinghamshire")), + ("Cambridgeshire", ("Cambridgeshire")), + ("Cheshire", _("Cheshire")), + ("Cornwall and Isles of Scilly", _("Cornwall and Isles of Scilly")), + ("Cumbria", _("Cumbria")), + ("Derbyshire", _("Derbyshire")), + ("Devon", _("Devon")), + ("Dorset", _("Dorset")), + ("Durham", _("Durham")), + ("East Sussex", _("East Sussex")), + ("Essex", _("Essex")), + ("Gloucestershire", _("Gloucestershire")), + ("Greater London", _("Greater London")), + ("Greater Manchester", _("Greater Manchester")), + ("Hampshire", _("Hampshire")), + ("Hertfordshire", _("Hertfordshire")), + ("Kent", _("Kent")), + ("Lancashire", _("Lancashire")), + ("Leicestershire", _("Leicestershire")), + ("Lincolnshire", _("Lincolnshire")), + ("Merseyside", _("Merseyside")), + ("Norfolk", _("Norfolk")), + ("North Yorkshire", _("North Yorkshire")), + ("Northamptonshire", _("Northamptonshire")), + ("Northumberland", _("Northumberland")), + ("Nottinghamshire", _("Nottinghamshire")), + ("Oxfordshire", _("Oxfordshire")), + ("Shropshire", _("Shropshire")), + ("Somerset", _("Somerset")), + ("South Yorkshire", _("South Yorkshire")), + ("Staffordshire", _("Staffordshire")), + ("Suffolk", _("Suffolk")), + ("Surrey", _("Surrey")), + ("Tyne and Wear", _("Tyne and Wear")), + ("Warwickshire", _("Warwickshire")), + ("West Midlands", _("West Midlands")), + ("West Sussex", _("West Sussex")), + ("West Yorkshire", _("West Yorkshire")), + ("Wiltshire", _("Wiltshire")), + ("Worcestershire", _("Worcestershire")), +) + +NORTHERN_IRELAND_REGION_CHOICES = ( + ("County Antrim", _("County Antrim")), + ("County Armagh", _("County Armagh")), + ("County Down", _("County Down")), + ("County Fermanagh", _("County Fermanagh")), + ("County Londonderry", _("County Londonderry")), + ("County Tyrone", _("County Tyrone")), +) + +WALES_REGION_CHOICES = ( + ("Clwyd", _("Clwyd")), + ("Dyfed", _("Dyfed")), + ("Gwent", _("Gwent")), + ("Gwynedd", _("Gwynedd")), + ("Mid Glamorgan", _("Mid Glamorgan")), + ("Powys", _("Powys")), + ("South Glamorgan", _("South Glamorgan")), + ("West Glamorgan", _("West Glamorgan")), +) + +SCOTTISH_REGION_CHOICES = ( + ("Borders", _("Borders")), + ("Central Scotland", _("Central Scotland")), + ("Dumfries and Galloway", _("Dumfries and Galloway")), + ("Fife", _("Fife")), + ("Grampian", _("Grampian")), + ("Highland", _("Highland")), + ("Lothian", _("Lothian")), + ("Orkney Islands", _("Orkney Islands")), + ("Shetland Islands", _("Shetland Islands")), + ("Strathclyde", _("Strathclyde")), + ("Tayside", _("Tayside")), + ("Western Isles", _("Western Isles")), +) + +GB_NATIONS_CHOICES = ( + ("England", _("England")), + ("Northern Ireland", _("Northern Ireland")), + ("Scotland", _("Scotland")), + ("Wales", _("Wales")), +) + +GB_REGION_CHOICES = ENGLAND_REGION_CHOICES + NORTHERN_IRELAND_REGION_CHOICES + WALES_REGION_CHOICES + SCOTTISH_REGION_CHOICES + Modified: django/trunk/django/contrib/localflavor/uk/forms.py =================================================================== --- django/trunk/django/contrib/localflavor/uk/forms.py 2011-05-03 11:52:04 UTC (rev 16146) +++ django/trunk/django/contrib/localflavor/uk/forms.py 2011-05-03 11:52:20 UTC (rev 16147) @@ -1,53 +1,10 @@ -""" -UK-specific Form helpers -""" +from django.contrib.localflavor.gb import forms -import re +import warnings +warnings.warn( + 'The "UK" prefix for United Kingdom has been deprecated in favour of the ' + 'GB code. Please use the new GB-prefixed names.', PendingDeprecationWarning) -from django.forms.fields import CharField, Select -from django.forms import ValidationError -from django.utils.translation import ugettext_lazy as _ - -class UKPostcodeField(CharField): - """ - A form field that validates its input is a UK postcode. - - The regular expression used is sourced from the schema for British Standard - BS7666 address types: http://www.govtalk.gov.uk/gdsc/schemas/bs7666-v2-0.xsd - - The value is uppercased and a space added in the correct place, if required. - """ - default_error_messages = { - 'invalid': _(u'Enter a valid postcode.'), - } - outcode_pattern = '[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|[0-9]|[ABEHMNPRVWXY]))|[0-9][A-HJKSTUW])' - incode_pattern = '[0-9][ABD-HJLNP-UW-Z]{2}' - postcode_regex = re.compile(r'^(GIR 0AA|%s %s)$' % (outcode_pattern, incode_pattern)) - space_regex = re.compile(r' *(%s)$' % incode_pattern) - - def clean(self, value): - value = super(UKPostcodeField, self).clean(value) - if value == u'': - return value - postcode = value.upper().strip() - # Put a single space before the incode (second part). - postcode = self.space_regex.sub(r' \1', postcode) - if not self.postcode_regex.search(postcode): - raise ValidationError(self.error_messages['invalid']) - return postcode - -class UKCountySelect(Select): - """ - A Select widget that uses a list of UK Counties/Regions as its choices. - """ - def __init__(self, attrs=None): - from uk_regions import UK_REGION_CHOICES - super(UKCountySelect, self).__init__(attrs, choices=UK_REGION_CHOICES) - -class UKNationSelect(Select): - """ - A Select widget that uses a list of UK Nations as its choices. - """ - def __init__(self, attrs=None): - from uk_regions import UK_NATIONS_CHOICES - super(UKNationSelect, self).__init__(attrs, choices=UK_NATIONS_CHOICES) +UKPostcodeField = forms.GBPostcodeField +UKCountySelect = forms.GBCountySelect +UKNationSelect = forms.GBNationSelect Modified: django/trunk/django/contrib/localflavor/uk/uk_regions.py =================================================================== --- django/trunk/django/contrib/localflavor/uk/uk_regions.py 2011-05-03 11:52:04 UTC (rev 16146) +++ django/trunk/django/contrib/localflavor/uk/uk_regions.py 2011-05-03 11:52:20 UTC (rev 16147) @@ -1,97 +1,12 @@ -""" -Sources: - English regions: http://www.statistics.gov.uk/geography/downloads/31_10_01_REGION_names_and_codes_12_00.xls - Northern Ireland regions: http://en.wikipedia.org/wiki/List_of_Irish_counties_by_area - Welsh regions: http://en.wikipedia.org/wiki/Preserved_counties_of_Wales - Scottish regions: http://en.wikipedia.org/wiki/Regions_and_districts_of_Scotland -""" -from django.utils.translation import ugettext_lazy as _ +from django.contrib.localflavor.gb.gb_regions import ( + ENGLAND_REGION_CHOICES, NORTHERN_IRELAND_REGION_CHOICES, + WALES_REGION_CHOICES, SCOTTISH_REGION_CHOICES, GB_NATIONS_CHOICES, + GB_REGION_CHOICES) -ENGLAND_REGION_CHOICES = ( - ("Bedfordshire", _("Bedfordshire")), - ("Buckinghamshire", _("Buckinghamshire")), - ("Cambridgeshire", ("Cambridgeshire")), - ("Cheshire", _("Cheshire")), - ("Cornwall and Isles of Scilly", _("Cornwall and Isles of Scilly")), - ("Cumbria", _("Cumbria")), - ("Derbyshire", _("Derbyshire")), - ("Devon", _("Devon")), - ("Dorset", _("Dorset")), - ("Durham", _("Durham")), - ("East Sussex", _("East Sussex")), - ("Essex", _("Essex")), - ("Gloucestershire", _("Gloucestershire")), - ("Greater London", _("Greater London")), - ("Greater Manchester", _("Greater Manchester")), - ("Hampshire", _("Hampshire")), - ("Hertfordshire", _("Hertfordshire")), - ("Kent", _("Kent")), - ("Lancashire", _("Lancashire")), - ("Leicestershire", _("Leicestershire")), - ("Lincolnshire", _("Lincolnshire")), - ("Merseyside", _("Merseyside")), - ("Norfolk", _("Norfolk")), - ("North Yorkshire", _("North Yorkshire")), - ("Northamptonshire", _("Northamptonshire")), - ("Northumberland", _("Northumberland")), - ("Nottinghamshire", _("Nottinghamshire")), - ("Oxfordshire", _("Oxfordshire")), - ("Shropshire", _("Shropshire")), - ("Somerset", _("Somerset")), - ("South Yorkshire", _("South Yorkshire")), - ("Staffordshire", _("Staffordshire")), - ("Suffolk", _("Suffolk")), - ("Surrey", _("Surrey")), - ("Tyne and Wear", _("Tyne and Wear")), - ("Warwickshire", _("Warwickshire")), - ("West Midlands", _("West Midlands")), - ("West Sussex", _("West Sussex")), - ("West Yorkshire", _("West Yorkshire")), - ("Wiltshire", _("Wiltshire")), - ("Worcestershire", _("Worcestershire")), -) +import warnings +warnings.warn( + 'The "UK" prefix for United Kingdom has been deprecated in favour of the ' + 'GB code. Please use the new GB-prefixed names.', PendingDeprecationWarning) -NORTHERN_IRELAND_REGION_CHOICES = ( - ("County Antrim", _("County Antrim")), - ("County Armagh", _("County Armagh")), - ("County Down", _("County Down")), - ("County Fermanagh", _("County Fermanagh")), - ("County Londonderry", _("County Londonderry")), - ("County Tyrone", _("County Tyrone")), -) - -WALES_REGION_CHOICES = ( - ("Clwyd", _("Clwyd")), - ("Dyfed", _("Dyfed")), - ("Gwent", _("Gwent")), - ("Gwynedd", _("Gwynedd")), - ("Mid Glamorgan", _("Mid Glamorgan")), - ("Powys", _("Powys")), - ("South Glamorgan", _("South Glamorgan")), - ("West Glamorgan", _("West Glamorgan")), -) - -SCOTTISH_REGION_CHOICES = ( - ("Borders", _("Borders")), - ("Central Scotland", _("Central Scotland")), - ("Dumfries and Galloway", _("Dumfries and Galloway")), - ("Fife", _("Fife")), - ("Grampian", _("Grampian")), - ("Highland", _("Highland")), - ("Lothian", _("Lothian")), - ("Orkney Islands", _("Orkney Islands")), - ("Shetland Islands", _("Shetland Islands")), - ("Strathclyde", _("Strathclyde")), - ("Tayside", _("Tayside")), - ("Western Isles", _("Western Isles")), -) - -UK_NATIONS_CHOICES = ( - ("England", _("England")), - ("Northern Ireland", _("Northern Ireland")), - ("Scotland", _("Scotland")), - ("Wales", _("Wales")), -) - -UK_REGION_CHOICES = ENGLAND_REGION_CHOICES + NORTHERN_IRELAND_REGION_CHOICES + WALES_REGION_CHOICES + SCOTTISH_REGION_CHOICES - +UK_NATIONS_CHOICES = GB_NATIONS_CHOICES +UK_REGION_CHOICES = GB_REGION_CHOICES Modified: django/trunk/docs/internals/deprecation.txt =================================================================== --- django/trunk/docs/internals/deprecation.txt 2011-05-03 11:52:04 UTC (rev 16146) +++ django/trunk/docs/internals/deprecation.txt 2011-05-03 11:52:20 UTC (rev 16147) @@ -175,7 +175,6 @@ combine paths in templates. * 1.6 - * The compatibility modules ``django.utils.copycompat`` and ``django.utils.hashcompat`` as well as the functions ``django.utils.itercompat.all`` and ``django.utils.itercompat.any`` @@ -195,6 +194,11 @@ is now an alias for :class:`~django.core.cache.backends.memcached.MemcachedCache`. In Django 1.6, the historical alias will be removed. + * The UK-prefixed objects of ``django.contrib.localflavor.uk`` will only + be accessible through their new GB-prefixed names (GB is the correct + ISO 3166 code for United Kingdom). They have been depreacted since the + 1.4 release. + * 2.0 * ``django.views.defaults.shortcut()``. This function has been moved to ``django.contrib.contenttypes.views.shortcut()`` as part of the Modified: django/trunk/docs/ref/contrib/localflavor.txt =================================================================== --- django/trunk/docs/ref/contrib/localflavor.txt 2011-05-03 11:52:04 UTC (rev 16146) +++ django/trunk/docs/ref/contrib/localflavor.txt 2011-05-03 11:52:20 UTC (rev 16147) @@ -123,7 +123,7 @@ .. _Sweden: `Sweden (se)`_ .. _Switzerland: `Switzerland (ch)`_ .. _Turkey: `Turkey (tr)`_ -.. _United Kingdom: `United Kingdom (uk)`_ +.. _United Kingdom: `United Kingdom (gb)`_ .. _United States of America: `United States of America (us)`_ .. _Uruguay: `Uruguay (uy)`_ @@ -1054,20 +1054,20 @@ A ``select`` widget that uses a list of Turkish provinces as its choices. -United Kingdom (``uk``) +United Kingdom (``gb``) ======================= -.. class:: uk.forms.UKPostcodeField +.. class:: gb.forms.GBPostcodeField A form field that validates input as a UK postcode. The regular expression used is sourced from the schema for British Standard BS7666 address types at http://www.cabinetoffice.gov.uk/media/291293/bs7666-v2-0.xml. -.. class:: uk.forms.UKCountySelect +.. class:: gb.forms.GBCountySelect A ``Select`` widget that uses a list of UK counties/regions as its choices. -.. class:: uk.forms.UKNationSelect +.. class:: gb.forms.GBNationSelect A ``Select`` widget that uses a list of UK nations as its choices. Copied: django/trunk/tests/regressiontests/forms/localflavor/gb.py (from rev 16146, django/trunk/tests/regressiontests/forms/localflavor/uk.py) =================================================================== --- django/trunk/tests/regressiontests/forms/localflavor/gb.py (rev 0) +++ django/trunk/tests/regressiontests/forms/localflavor/gb.py 2011-05-03 11:52:20 UTC (rev 16147) @@ -0,0 +1,30 @@ +from django.contrib.localflavor.gb.forms import GBPostcodeField + +from utils import LocalFlavorTestCase + + +class GBLocalFlavorTests(LocalFlavorTestCase): + def test_GBPostcodeField(self): + error_invalid = [u'Enter a valid postcode.'] + valid = { + 'BT32 4PX': 'BT32 4PX', + 'GIR 0AA': 'GIR 0AA', + 'BT324PX': 'BT32 4PX', + ' so11aa ': 'SO1 1AA', + ' so1 1aa ': 'SO1 1AA', + 'G2 3wt': 'G2 3WT', + 'EC1A 1BB': 'EC1A 1BB', + 'Ec1a1BB': 'EC1A 1BB', + } + invalid = { + '1NV 4L1D': error_invalid, + '1NV4L1D': error_invalid, + ' b0gUS': error_invalid, + } + self.assertFieldOutput(GBPostcodeField, valid, invalid) + valid = {} + invalid = { + '1NV 4L1D': [u'Enter a bloody postcode!'], + } + kwargs = {'error_messages': {'invalid': 'Enter a bloody postcode!'}} + self.assertFieldOutput(GBPostcodeField, valid, invalid, field_kwargs=kwargs) Deleted: django/trunk/tests/regressiontests/forms/localflavor/uk.py =================================================================== --- django/trunk/tests/regressiontests/forms/localflavor/uk.py 2011-05-03 11:52:04 UTC (rev 16146) +++ django/trunk/tests/regressiontests/forms/localflavor/uk.py 2011-05-03 11:52:20 UTC (rev 16147) @@ -1,30 +0,0 @@ -from django.contrib.localflavor.uk.forms import UKPostcodeField - -from utils import LocalFlavorTestCase - - -class UKLocalFlavorTests(LocalFlavorTestCase): - def test_UKPostcodeField(self): - error_invalid = [u'Enter a valid postcode.'] - valid = { - 'BT32 4PX': 'BT32 4PX', - 'GIR 0AA': 'GIR 0AA', - 'BT324PX': 'BT32 4PX', - ' so11aa ': 'SO1 1AA', - ' so1 1aa ': 'SO1 1AA', - 'G2 3wt': 'G2 3WT', - 'EC1A 1BB': 'EC1A 1BB', - 'Ec1a1BB': 'EC1A 1BB', - } - invalid = { - '1NV 4L1D': error_invalid, - '1NV4L1D': error_invalid, - ' b0gUS': error_invalid, - } - self.assertFieldOutput(UKPostcodeField, valid, invalid) - valid = {} - invalid = { - '1NV 4L1D': [u'Enter a bloody postcode!'], - } - kwargs = {'error_messages': {'invalid': 'Enter a bloody postcode!'}} - self.assertFieldOutput(UKPostcodeField, valid, invalid, field_kwargs=kwargs) Modified: django/trunk/tests/regressiontests/forms/localflavortests.py =================================================================== --- django/trunk/tests/regressiontests/forms/localflavortests.py 2011-05-03 11:52:04 UTC (rev 16146) +++ django/trunk/tests/regressiontests/forms/localflavortests.py 2011-05-03 11:52:20 UTC (rev 16147) @@ -12,6 +12,7 @@ from localflavor.es import ESLocalFlavorTests from localflavor.fi import FILocalFlavorTests from localflavor.fr import FRLocalFlavorTests +from localflavor.gb import GBLocalFlavorTests from localflavor.generic import GenericLocalFlavorTests from localflavor.hr import HRLocalFlavorTests from localflavor.id import IDLocalFlavorTests @@ -29,7 +30,6 @@ from localflavor.se import SELocalFlavorTests from localflavor.sk import SKLocalFlavorTests from localflavor.tr import TRLocalFlavorTests -from localflavor.uk import UKLocalFlavorTests from localflavor.us import USLocalFlavorTests from localflavor.uy import UYLocalFlavorTests from localflavor.za import ZALocalFlavorTests Modified: django/trunk/tests/regressiontests/forms/tests/__init__.py =================================================================== --- django/trunk/tests/regressiontests/forms/tests/__init__.py 2011-05-03 11:52:04 UTC (rev 16146) +++ django/trunk/tests/regressiontests/forms/tests/__init__.py 2011-05-03 11:52:20 UTC (rev 16147) @@ -26,6 +26,7 @@ ESLocalFlavorTests, FILocalFlavorTests, FRLocalFlavorTests, + GBLocalFlavorTests, GenericLocalFlavorTests, HRLocalFlavorTests, IDLocalFlavorTests, @@ -43,7 +44,6 @@ SELocalFlavorTests, SKLocalFlavorTests, TRLocalFlavorTests, - UKLocalFlavorTests, USLocalFlavorTests, UYLocalFlavorTests, ZALocalFlavorTests -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.