Django

Code

Ticket #5523: ukcountieslocalflavor-5523.diff

File ukcountieslocalflavor-5523.diff, 1.3 kB (added by DavidReynolds, 1 year ago)

adding in the form widgets as suggested.

  • a/django/contrib/localflavor/uk/forms.py

    old new  
    22UK-specific Form helpers 
    33""" 
    44 
    5 from django.newforms.fields import RegexField 
     5from django.newforms.fields import RegexField, Select 
    66from django.utils.translation import ugettext 
    77 
    88class UKPostcodeField(RegexField): 
     
    1717            max_length=None, min_length=None, 
    1818            error_message=ugettext(u'Enter a postcode. A space is required between the two postcode parts.'), 
    1919            *args, **kwargs) 
     20 
     21class 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 
     30class UKNationSelect(Select): 
     31    """ 
     32    A Select widget that uses a list of UK Nations as its choices. 
     33    """ 
     34    def __init__(self, attrs=None): 
     35        from uk_regions import UK_NATIONS_CHOICES 
     36        super(UKNationSelect, self).__init__(attrs, choices=UK_NATIONS_CHOICES)