Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit c7de28c64c837752d8c69995b3609061e7a7732d 1 parent 6737300
Malcolm Tredinnick authored December 03, 2007
1  AUTHORS
@@ -268,6 +268,7 @@ answer newbie questions, and generally made Django that much better:
268 268
     Massimiliano Ravelli <massimiliano.ravelli@gmail.com>
269 269
     Brian Ray <http://brianray.chipy.org/>
270 270
     remco@diji.biz
  271
+    David Reynolds <david@reynoldsfamily.org.uk>
271 272
     rhettg@gmail.com
272 273
     ricardojbarrios@gmail.com
273 274
     Matt Riggott
18  django/contrib/localflavor/uk/forms.py
@@ -2,7 +2,7 @@
2 2
 UK-specific Form helpers
3 3
 """
4 4
 
5  
-from django.newforms.fields import RegexField
  5
+from django.newforms.fields import RegexField, Select
6 6
 from django.utils.translation import ugettext
7 7
 
8 8
 class UKPostcodeField(RegexField):
@@ -17,3 +17,19 @@ def __init__(self, *args, **kwargs):
17 17
             max_length=None, min_length=None,
18 18
             error_message=ugettext(u'Enter a postcode. A space is required between the two postcode parts.'),
19 19
             *args, **kwargs)
  20
+
  21
+class UKCountySelect(Select):
  22
+    """
  23
+    A Select widget that uses a list of UK Counties/Regions as its choices.
  24
+    """
  25
+    def __init__(self, attrs=None):
  26
+        from uk_regions import UK_REGION_CHOICES
  27
+        super(UKCountySelect, self).__init__(attrs, choices=UK_REGION_CHOICES)
  28
+
  29
+class UKNationSelect(Select):
  30
+    """
  31
+    A Select widget that uses a list of UK Nations as its choices.
  32
+    """
  33
+    def __init__(self, attrs=None):
  34
+        from uk_regions import UK_NATIONS_CHOICES
  35
+        super(UKNationSelect, self).__init__(attrs, choices=UK_NATIONS_CHOICES)
97  django/contrib/localflavor/uk/uk_regions.py
... ...
@@ -0,0 +1,97 @@
  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 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 Down")),
  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
+

0 notes on commit c7de28c

Please sign in to comment.
Something went wrong with that request. Please try again.