Code

Ticket #5523: ukcountieslocalflavor-5523.diff

File ukcountieslocalflavor-5523.diff, 1.3 KB (added by DavidReynolds, 7 years ago)

adding in the form widgets as suggested.

Line 
1diff --git a/django/contrib/localflavor/uk/forms.py b/django/contrib/localflavor/uk/forms.py
2index 84d6c0e..23c4c79 100644
3--- a/django/contrib/localflavor/uk/forms.py
4+++ b/django/contrib/localflavor/uk/forms.py
5@@ -2,7 +2,7 @@
6 UK-specific Form helpers
7 """
8 
9-from django.newforms.fields import RegexField
10+from django.newforms.fields import RegexField, Select
11 from django.utils.translation import ugettext
12 
13 class UKPostcodeField(RegexField):
14@@ -17,3 +17,20 @@ class UKPostcodeField(RegexField):
15             max_length=None, min_length=None,
16             error_message=ugettext(u'Enter a postcode. A space is required between the two postcode parts.'),
17             *args, **kwargs)
18+
19+class UKCountySelect(Select):
20+    """
21+    A Select widget that uses a list of UK Counties/Regions as its choices.
22+    """
23+    def __init__(self, attrs=None):
24+        from uk_regions import UK_REGION_CHOICES
25+        super(UKCountySelect, self).__init__(attrs, choices=UK_REGION_CHOICES)
26+       
27+
28+class UKNationSelect(Select):
29+    """
30+    A Select widget that uses a list of UK Nations as its choices.
31+    """
32+    def __init__(self, attrs=None):
33+        from uk_regions import UK_NATIONS_CHOICES
34+        super(UKNationSelect, self).__init__(attrs, choices=UK_NATIONS_CHOICES)
35\ No newline at end of file