From c7de28c64c837752d8c69995b3609061e7a7732d Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 3 Dec 2007 00:35:31 +0000 Subject: [PATCH] Fixed #5523 -- Added counties and regions for the United Kingdom to localflavors. Thanks, David Reynolds. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6855 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/contrib/localflavor/uk/forms.py | 18 +++- django/contrib/localflavor/uk/uk_regions.py | 97 +++++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 django/contrib/localflavor/uk/uk_regions.py diff --git a/AUTHORS b/AUTHORS index 7969c2a12f..ffb9e87690 100644 --- a/AUTHORS +++ b/AUTHORS @@ -268,6 +268,7 @@ answer newbie questions, and generally made Django that much better: Massimiliano Ravelli Brian Ray remco@diji.biz + David Reynolds rhettg@gmail.com ricardojbarrios@gmail.com Matt Riggott diff --git a/django/contrib/localflavor/uk/forms.py b/django/contrib/localflavor/uk/forms.py index 84d6c0e157..2b162230de 100644 --- a/django/contrib/localflavor/uk/forms.py +++ b/django/contrib/localflavor/uk/forms.py @@ -2,7 +2,7 @@ UK-specific Form helpers """ -from django.newforms.fields import RegexField +from django.newforms.fields import RegexField, Select from django.utils.translation import ugettext class UKPostcodeField(RegexField): @@ -17,3 +17,19 @@ class UKPostcodeField(RegexField): max_length=None, min_length=None, error_message=ugettext(u'Enter a postcode. A space is required between the two postcode parts.'), *args, **kwargs) + +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) diff --git a/django/contrib/localflavor/uk/uk_regions.py b/django/contrib/localflavor/uk/uk_regions.py new file mode 100644 index 0000000000..3e2c16ef5d --- /dev/null +++ b/django/contrib/localflavor/uk/uk_regions.py @@ -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 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 Down")), + ("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 +