Ticket #13729: 13729-with-deprecation-path.diff
File 13729-with-deprecation-path.diff, 19.6 KB (added by , 14 years ago) |
---|
-
new file django/contrib/localflavor/gb/forms.py
commit 9bbe112c08a0ad4dd30b1b59a5ff87a3d7ea69dc Author: Claude Paroz <claude@2xlibre.net> Date: Sat Apr 30 21:51:09 2011 +0200 Rename django.contrib.localflavor.uk to django.contrib.localflavor.gb diff --git a/django/contrib/localflavor/gb/__init__.py b/django/contrib/localflavor/gb/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django/contrib/localflavor/gb/forms.py b/django/contrib/localflavor/gb/forms.py new file mode 100644 index 0000000..0f7d91a
- + 1 """ 2 GB-specific Form helpers 3 """ 4 5 import re 6 7 from django.forms.fields import CharField, Select 8 from django.forms import ValidationError 9 from django.utils.translation import ugettext_lazy as _ 10 11 class GBPostcodeField(CharField): 12 """ 13 A form field that validates its input is a UK postcode. 14 15 The regular expression used is sourced from the schema for British Standard 16 BS7666 address types: http://www.govtalk.gov.uk/gdsc/schemas/bs7666-v2-0.xsd 17 18 The value is uppercased and a space added in the correct place, if required. 19 """ 20 default_error_messages = { 21 'invalid': _(u'Enter a valid postcode.'), 22 } 23 outcode_pattern = '[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|[0-9]|[ABEHMNPRVWXY]))|[0-9][A-HJKSTUW])' 24 incode_pattern = '[0-9][ABD-HJLNP-UW-Z]{2}' 25 postcode_regex = re.compile(r'^(GIR 0AA|%s %s)$' % (outcode_pattern, incode_pattern)) 26 space_regex = re.compile(r' *(%s)$' % incode_pattern) 27 28 def clean(self, value): 29 value = super(GBPostcodeField, self).clean(value) 30 if value == u'': 31 return value 32 postcode = value.upper().strip() 33 # Put a single space before the incode (second part). 34 postcode = self.space_regex.sub(r' \1', postcode) 35 if not self.postcode_regex.search(postcode): 36 raise ValidationError(self.error_messages['invalid']) 37 return postcode 38 39 class GBCountySelect(Select): 40 """ 41 A Select widget that uses a list of UK Counties/Regions as its choices. 42 """ 43 def __init__(self, attrs=None): 44 from gb_regions import GB_REGION_CHOICES 45 super(GBCountySelect, self).__init__(attrs, choices=GB_REGION_CHOICES) 46 47 class GBNationSelect(Select): 48 """ 49 A Select widget that uses a list of UK Nations as its choices. 50 """ 51 def __init__(self, attrs=None): 52 from gb_regions import GB_NATIONS_CHOICES 53 super(GBNationSelect, self).__init__(attrs, choices=GB_NATIONS_CHOICES) -
new file django/contrib/localflavor/gb/gb_regions.py
diff --git a/django/contrib/localflavor/gb/gb_regions.py b/django/contrib/localflavor/gb/gb_regions.py new file mode 100644 index 0000000..c5f5dd7
- + 1 """ 2 Sources: 3 English regions: http://www.statistics.gov.uk/geography/downloads/31_10_01_REGION_names_and_codes_12_00.xls 4 Northern Ireland regions: http://en.wikipedia.org/wiki/List_of_Irish_counties_by_area 5 Welsh regions: http://en.wikipedia.org/wiki/Preserved_counties_of_Wales 6 Scottish regions: http://en.wikipedia.org/wiki/Regions_and_districts_of_Scotland 7 """ 8 from django.utils.translation import ugettext_lazy as _ 9 10 ENGLAND_REGION_CHOICES = ( 11 ("Bedfordshire", _("Bedfordshire")), 12 ("Buckinghamshire", _("Buckinghamshire")), 13 ("Cambridgeshire", ("Cambridgeshire")), 14 ("Cheshire", _("Cheshire")), 15 ("Cornwall and Isles of Scilly", _("Cornwall and Isles of Scilly")), 16 ("Cumbria", _("Cumbria")), 17 ("Derbyshire", _("Derbyshire")), 18 ("Devon", _("Devon")), 19 ("Dorset", _("Dorset")), 20 ("Durham", _("Durham")), 21 ("East Sussex", _("East Sussex")), 22 ("Essex", _("Essex")), 23 ("Gloucestershire", _("Gloucestershire")), 24 ("Greater London", _("Greater London")), 25 ("Greater Manchester", _("Greater Manchester")), 26 ("Hampshire", _("Hampshire")), 27 ("Hertfordshire", _("Hertfordshire")), 28 ("Kent", _("Kent")), 29 ("Lancashire", _("Lancashire")), 30 ("Leicestershire", _("Leicestershire")), 31 ("Lincolnshire", _("Lincolnshire")), 32 ("Merseyside", _("Merseyside")), 33 ("Norfolk", _("Norfolk")), 34 ("North Yorkshire", _("North Yorkshire")), 35 ("Northamptonshire", _("Northamptonshire")), 36 ("Northumberland", _("Northumberland")), 37 ("Nottinghamshire", _("Nottinghamshire")), 38 ("Oxfordshire", _("Oxfordshire")), 39 ("Shropshire", _("Shropshire")), 40 ("Somerset", _("Somerset")), 41 ("South Yorkshire", _("South Yorkshire")), 42 ("Staffordshire", _("Staffordshire")), 43 ("Suffolk", _("Suffolk")), 44 ("Surrey", _("Surrey")), 45 ("Tyne and Wear", _("Tyne and Wear")), 46 ("Warwickshire", _("Warwickshire")), 47 ("West Midlands", _("West Midlands")), 48 ("West Sussex", _("West Sussex")), 49 ("West Yorkshire", _("West Yorkshire")), 50 ("Wiltshire", _("Wiltshire")), 51 ("Worcestershire", _("Worcestershire")), 52 ) 53 54 NORTHERN_IRELAND_REGION_CHOICES = ( 55 ("County Antrim", _("County Antrim")), 56 ("County Armagh", _("County Armagh")), 57 ("County Down", _("County Down")), 58 ("County Fermanagh", _("County Fermanagh")), 59 ("County Londonderry", _("County Londonderry")), 60 ("County Tyrone", _("County Tyrone")), 61 ) 62 63 WALES_REGION_CHOICES = ( 64 ("Clwyd", _("Clwyd")), 65 ("Dyfed", _("Dyfed")), 66 ("Gwent", _("Gwent")), 67 ("Gwynedd", _("Gwynedd")), 68 ("Mid Glamorgan", _("Mid Glamorgan")), 69 ("Powys", _("Powys")), 70 ("South Glamorgan", _("South Glamorgan")), 71 ("West Glamorgan", _("West Glamorgan")), 72 ) 73 74 SCOTTISH_REGION_CHOICES = ( 75 ("Borders", _("Borders")), 76 ("Central Scotland", _("Central Scotland")), 77 ("Dumfries and Galloway", _("Dumfries and Galloway")), 78 ("Fife", _("Fife")), 79 ("Grampian", _("Grampian")), 80 ("Highland", _("Highland")), 81 ("Lothian", _("Lothian")), 82 ("Orkney Islands", _("Orkney Islands")), 83 ("Shetland Islands", _("Shetland Islands")), 84 ("Strathclyde", _("Strathclyde")), 85 ("Tayside", _("Tayside")), 86 ("Western Isles", _("Western Isles")), 87 ) 88 89 GB_NATIONS_CHOICES = ( 90 ("England", _("England")), 91 ("Northern Ireland", _("Northern Ireland")), 92 ("Scotland", _("Scotland")), 93 ("Wales", _("Wales")), 94 ) 95 96 GB_REGION_CHOICES = ENGLAND_REGION_CHOICES + NORTHERN_IRELAND_REGION_CHOICES + WALES_REGION_CHOICES + SCOTTISH_REGION_CHOICES 97 -
django/contrib/localflavor/uk/forms.py
diff --git a/django/contrib/localflavor/uk/forms.py b/django/contrib/localflavor/uk/forms.py index aafe973..c54058c 100644
a b 1 """ 2 UK-specific Form helpers 3 """ 1 from django.contrib.localflavor.gb import forms 4 2 5 import re 3 import warnings 4 warnings.warn( 5 'UK prefix for United Kingdom has been deprecated in favour of the GB code. Please use the new GB-prefixed names.', 6 PendingDeprecationWarning 7 ) 6 8 7 from django.forms.fields import CharField, Select 8 from django.forms import ValidationError 9 from django.utils.translation import ugettext_lazy as _ 10 11 class UKPostcodeField(CharField): 12 """ 13 A form field that validates its input is a UK postcode. 14 15 The regular expression used is sourced from the schema for British Standard 16 BS7666 address types: http://www.govtalk.gov.uk/gdsc/schemas/bs7666-v2-0.xsd 17 18 The value is uppercased and a space added in the correct place, if required. 19 """ 20 default_error_messages = { 21 'invalid': _(u'Enter a valid postcode.'), 22 } 23 outcode_pattern = '[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|[0-9]|[ABEHMNPRVWXY]))|[0-9][A-HJKSTUW])' 24 incode_pattern = '[0-9][ABD-HJLNP-UW-Z]{2}' 25 postcode_regex = re.compile(r'^(GIR 0AA|%s %s)$' % (outcode_pattern, incode_pattern)) 26 space_regex = re.compile(r' *(%s)$' % incode_pattern) 27 28 def clean(self, value): 29 value = super(UKPostcodeField, self).clean(value) 30 if value == u'': 31 return value 32 postcode = value.upper().strip() 33 # Put a single space before the incode (second part). 34 postcode = self.space_regex.sub(r' \1', postcode) 35 if not self.postcode_regex.search(postcode): 36 raise ValidationError(self.error_messages['invalid']) 37 return postcode 38 39 class UKCountySelect(Select): 40 """ 41 A Select widget that uses a list of UK Counties/Regions as its choices. 42 """ 43 def __init__(self, attrs=None): 44 from uk_regions import UK_REGION_CHOICES 45 super(UKCountySelect, self).__init__(attrs, choices=UK_REGION_CHOICES) 46 47 class UKNationSelect(Select): 48 """ 49 A Select widget that uses a list of UK Nations as its choices. 50 """ 51 def __init__(self, attrs=None): 52 from uk_regions import UK_NATIONS_CHOICES 53 super(UKNationSelect, self).__init__(attrs, choices=UK_NATIONS_CHOICES) 9 UKPostcodeField = forms.GBPostcodeField 10 UKCountySelect = forms.GBCountySelect 11 UKNationSelect = forms.GBNationSelect -
django/contrib/localflavor/uk/uk_regions.py
diff --git a/django/contrib/localflavor/uk/uk_regions.py b/django/contrib/localflavor/uk/uk_regions.py index dd92f5e..71fabc0 100644
a b 1 """ 2 Sources: 3 English regions: http://www.statistics.gov.uk/geography/downloads/31_10_01_REGION_names_and_codes_12_00.xls 4 Northern Ireland regions: http://en.wikipedia.org/wiki/List_of_Irish_counties_by_area 5 Welsh regions: http://en.wikipedia.org/wiki/Preserved_counties_of_Wales 6 Scottish regions: http://en.wikipedia.org/wiki/Regions_and_districts_of_Scotland 7 """ 8 from django.utils.translation import ugettext_lazy as _ 1 from django.contrib.localflavor.gb.gb_regions import * 9 2 10 ENGLAND_REGION_CHOICES = ( 11 ("Bedfordshire", _("Bedfordshire")), 12 ("Buckinghamshire", _("Buckinghamshire")), 13 ("Cambridgeshire", ("Cambridgeshire")), 14 ("Cheshire", _("Cheshire")), 15 ("Cornwall and Isles of Scilly", _("Cornwall and Isles of Scilly")), 16 ("Cumbria", _("Cumbria")), 17 ("Derbyshire", _("Derbyshire")), 18 ("Devon", _("Devon")), 19 ("Dorset", _("Dorset")), 20 ("Durham", _("Durham")), 21 ("East Sussex", _("East Sussex")), 22 ("Essex", _("Essex")), 23 ("Gloucestershire", _("Gloucestershire")), 24 ("Greater London", _("Greater London")), 25 ("Greater Manchester", _("Greater Manchester")), 26 ("Hampshire", _("Hampshire")), 27 ("Hertfordshire", _("Hertfordshire")), 28 ("Kent", _("Kent")), 29 ("Lancashire", _("Lancashire")), 30 ("Leicestershire", _("Leicestershire")), 31 ("Lincolnshire", _("Lincolnshire")), 32 ("Merseyside", _("Merseyside")), 33 ("Norfolk", _("Norfolk")), 34 ("North Yorkshire", _("North Yorkshire")), 35 ("Northamptonshire", _("Northamptonshire")), 36 ("Northumberland", _("Northumberland")), 37 ("Nottinghamshire", _("Nottinghamshire")), 38 ("Oxfordshire", _("Oxfordshire")), 39 ("Shropshire", _("Shropshire")), 40 ("Somerset", _("Somerset")), 41 ("South Yorkshire", _("South Yorkshire")), 42 ("Staffordshire", _("Staffordshire")), 43 ("Suffolk", _("Suffolk")), 44 ("Surrey", _("Surrey")), 45 ("Tyne and Wear", _("Tyne and Wear")), 46 ("Warwickshire", _("Warwickshire")), 47 ("West Midlands", _("West Midlands")), 48 ("West Sussex", _("West Sussex")), 49 ("West Yorkshire", _("West Yorkshire")), 50 ("Wiltshire", _("Wiltshire")), 51 ("Worcestershire", _("Worcestershire")), 3 import warnings 4 warnings.warn( 5 'UK prefix for United Kingdom has been deprecated in favour of the GB code. Please use the new GB-prefixed names.', 6 PendingDeprecationWarning 52 7 ) 53 8 54 NORTHERN_IRELAND_REGION_CHOICES = ( 55 ("County Antrim", _("County Antrim")), 56 ("County Armagh", _("County Armagh")), 57 ("County Down", _("County Down")), 58 ("County Fermanagh", _("County Fermanagh")), 59 ("County Londonderry", _("County Londonderry")), 60 ("County Tyrone", _("County Tyrone")), 61 ) 62 63 WALES_REGION_CHOICES = ( 64 ("Clwyd", _("Clwyd")), 65 ("Dyfed", _("Dyfed")), 66 ("Gwent", _("Gwent")), 67 ("Gwynedd", _("Gwynedd")), 68 ("Mid Glamorgan", _("Mid Glamorgan")), 69 ("Powys", _("Powys")), 70 ("South Glamorgan", _("South Glamorgan")), 71 ("West Glamorgan", _("West Glamorgan")), 72 ) 73 74 SCOTTISH_REGION_CHOICES = ( 75 ("Borders", _("Borders")), 76 ("Central Scotland", _("Central Scotland")), 77 ("Dumfries and Galloway", _("Dumfries and Galloway")), 78 ("Fife", _("Fife")), 79 ("Grampian", _("Grampian")), 80 ("Highland", _("Highland")), 81 ("Lothian", _("Lothian")), 82 ("Orkney Islands", _("Orkney Islands")), 83 ("Shetland Islands", _("Shetland Islands")), 84 ("Strathclyde", _("Strathclyde")), 85 ("Tayside", _("Tayside")), 86 ("Western Isles", _("Western Isles")), 87 ) 88 89 UK_NATIONS_CHOICES = ( 90 ("England", _("England")), 91 ("Northern Ireland", _("Northern Ireland")), 92 ("Scotland", _("Scotland")), 93 ("Wales", _("Wales")), 94 ) 95 96 UK_REGION_CHOICES = ENGLAND_REGION_CHOICES + NORTHERN_IRELAND_REGION_CHOICES + WALES_REGION_CHOICES + SCOTTISH_REGION_CHOICES 97 9 UK_NATIONS_CHOICES = GB_NATIONS_CHOICES 10 UK_REGION_CHOICES = GB_REGION_CHOICES -
docs/internals/deprecation.txt
diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index a38823f..98b2138 100644
a b their deprecation, as per the :ref:`Django deprecation policy 175 175 combine paths in templates. 176 176 177 177 * 1.6 178 179 178 * The compatibility modules ``django.utils.copycompat`` and 180 179 ``django.utils.hashcompat`` as well as the functions 181 180 ``django.utils.itercompat.all`` and ``django.utils.itercompat.any`` … … their deprecation, as per the :ref:`Django deprecation policy 195 194 is now an alias for :class:`~django.core.cache.backends.memcached.MemcachedCache`. 196 195 In Django 1.6, the historical alias will be removed. 197 196 197 * The UK-prefixed objects of ``django.contrib.localflavor.uk`` will only 198 be accessible through their new GB-prefixed names (GB is the correct 199 ISO 3166 code for United Kingdom). They have been depreacted since the 200 1.4 release. 201 198 202 * 2.0 199 203 * ``django.views.defaults.shortcut()``. This function has been moved 200 204 to ``django.contrib.contenttypes.views.shortcut()`` as part of the -
docs/ref/contrib/localflavor.txt
diff --git a/docs/ref/contrib/localflavor.txt b/docs/ref/contrib/localflavor.txt index 4935382..f6dab64 100644
a b Here's an example of how to use them:: 123 123 .. _Sweden: `Sweden (se)`_ 124 124 .. _Switzerland: `Switzerland (ch)`_ 125 125 .. _Turkey: `Turkey (tr)`_ 126 .. _United Kingdom: `United Kingdom ( uk)`_126 .. _United Kingdom: `United Kingdom (gb)`_ 127 127 .. _United States of America: `United States of America (us)`_ 128 128 .. _Uruguay: `Uruguay (uy)`_ 129 129 … … Turkey (``tr``) 1054 1054 1055 1055 A ``select`` widget that uses a list of Turkish provinces as its choices. 1056 1056 1057 United Kingdom (`` uk``)1057 United Kingdom (``gb``) 1058 1058 ======================= 1059 1059 1060 .. class:: uk.forms.UKPostcodeField1060 .. class:: gb.forms.GBPostcodeField 1061 1061 1062 1062 A form field that validates input as a UK postcode. The regular 1063 1063 expression used is sourced from the schema for British Standard BS7666 1064 1064 address types at http://www.cabinetoffice.gov.uk/media/291293/bs7666-v2-0.xml. 1065 1065 1066 .. class:: uk.forms.UKCountySelect1066 .. class:: gb.forms.GBCountySelect 1067 1067 1068 1068 A ``Select`` widget that uses a list of UK counties/regions as its choices. 1069 1069 1070 .. class:: uk.forms.UKNationSelect1070 .. class:: gb.forms.GBNationSelect 1071 1071 1072 1072 A ``Select`` widget that uses a list of UK nations as its choices. 1073 1073 -
new file tests/regressiontests/forms/localflavor/gb.py
diff --git a/tests/regressiontests/forms/localflavor/gb.py b/tests/regressiontests/forms/localflavor/gb.py new file mode 100644 index 0000000..7f23ba5
- + 1 from django.contrib.localflavor.gb.forms import GBPostcodeField 2 3 from utils import LocalFlavorTestCase 4 5 6 class GBLocalFlavorTests(LocalFlavorTestCase): 7 def test_GBPostcodeField(self): 8 error_invalid = [u'Enter a valid postcode.'] 9 valid = { 10 'BT32 4PX': 'BT32 4PX', 11 'GIR 0AA': 'GIR 0AA', 12 'BT324PX': 'BT32 4PX', 13 ' so11aa ': 'SO1 1AA', 14 ' so1 1aa ': 'SO1 1AA', 15 'G2 3wt': 'G2 3WT', 16 'EC1A 1BB': 'EC1A 1BB', 17 'Ec1a1BB': 'EC1A 1BB', 18 } 19 invalid = { 20 '1NV 4L1D': error_invalid, 21 '1NV4L1D': error_invalid, 22 ' b0gUS': error_invalid, 23 } 24 self.assertFieldOutput(GBPostcodeField, valid, invalid) 25 valid = {} 26 invalid = { 27 '1NV 4L1D': [u'Enter a bloody postcode!'], 28 } 29 kwargs = {'error_messages': {'invalid': 'Enter a bloody postcode!'}} 30 self.assertFieldOutput(GBPostcodeField, valid, invalid, field_kwargs=kwargs) -
deleted file tests/regressiontests/forms/localflavor/uk.py
diff --git a/tests/regressiontests/forms/localflavor/uk.py b/tests/regressiontests/forms/localflavor/uk.py deleted file mode 100644 index 6fd536f..0000000
+ - 1 from django.contrib.localflavor.uk.forms import UKPostcodeField2 3 from utils import LocalFlavorTestCase4 5 6 class UKLocalFlavorTests(LocalFlavorTestCase):7 def test_UKPostcodeField(self):8 error_invalid = [u'Enter a valid postcode.']9 valid = {10 'BT32 4PX': 'BT32 4PX',11 'GIR 0AA': 'GIR 0AA',12 'BT324PX': 'BT32 4PX',13 ' so11aa ': 'SO1 1AA',14 ' so1 1aa ': 'SO1 1AA',15 'G2 3wt': 'G2 3WT',16 'EC1A 1BB': 'EC1A 1BB',17 'Ec1a1BB': 'EC1A 1BB',18 }19 invalid = {20 '1NV 4L1D': error_invalid,21 '1NV4L1D': error_invalid,22 ' b0gUS': error_invalid,23 }24 self.assertFieldOutput(UKPostcodeField, valid, invalid)25 valid = {}26 invalid = {27 '1NV 4L1D': [u'Enter a bloody postcode!'],28 }29 kwargs = {'error_messages': {'invalid': 'Enter a bloody postcode!'}}30 self.assertFieldOutput(UKPostcodeField, valid, invalid, field_kwargs=kwargs) -
tests/regressiontests/forms/localflavortests.py
diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py index 73f46a7..fb501ab 100644
a b from localflavor.de import DELocalFlavorTests 12 12 from localflavor.es import ESLocalFlavorTests 13 13 from localflavor.fi import FILocalFlavorTests 14 14 from localflavor.fr import FRLocalFlavorTests 15 from localflavor.gb import GBLocalFlavorTests 15 16 from localflavor.generic import GenericLocalFlavorTests 16 17 from localflavor.hr import HRLocalFlavorTests 17 18 from localflavor.id import IDLocalFlavorTests … … from localflavor.ru import RULocalFlavorTests 29 30 from localflavor.se import SELocalFlavorTests 30 31 from localflavor.sk import SKLocalFlavorTests 31 32 from localflavor.tr import TRLocalFlavorTests 32 from localflavor.uk import UKLocalFlavorTests33 33 from localflavor.us import USLocalFlavorTests 34 34 from localflavor.uy import UYLocalFlavorTests 35 35 from localflavor.za import ZALocalFlavorTests -
tests/regressiontests/forms/tests/__init__.py
diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index 2d8f9e9..6366a93 100644
a b from regressiontests.forms.localflavortests import ( 26 26 ESLocalFlavorTests, 27 27 FILocalFlavorTests, 28 28 FRLocalFlavorTests, 29 GBLocalFlavorTests, 29 30 GenericLocalFlavorTests, 30 31 HRLocalFlavorTests, 31 32 IDLocalFlavorTests, … … from regressiontests.forms.localflavortests import ( 43 44 SELocalFlavorTests, 44 45 SKLocalFlavorTests, 45 46 TRLocalFlavorTests, 46 UKLocalFlavorTests,47 47 USLocalFlavorTests, 48 48 UYLocalFlavorTests, 49 49 ZALocalFlavorTests