Ticket #4092: 4092_6194_simple.diff

File 4092_6194_simple.diff, 20.3 KB (added by dougn, 17 years ago)

Simple patch which does not include a new base widget, but adds an empty_label to each localflavor Select widget

  • django/contrib/localflavor/us/forms.py

     
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
    77from django.utils.encoding import smart_unicode
    88from django.utils.translation import ugettext
     9from itertools import chain
    910import re
    1011
    1112phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$')
     
    9495    """
    9596    A Select widget that uses a list of U.S. states/territories as its choices.
    9697    """
    97     def __init__(self, attrs=None):
     98    def __init__(self, attrs=None, empty_label=u"---------"):
    9899        from us_states import STATE_CHOICES
    99         super(USStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
     100        select_choices = STATE_CHOICES
     101        if empty_label is not None:
     102            select_choices = chain(((u'', empty_label),), STATE_CHOICES)
     103        super(USStateSelect, self).__init__(attrs, choices=select_choices)
  • django/contrib/localflavor/de/forms.py

     
    55from django.newforms import ValidationError
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
    77from django.utils.translation import ugettext
     8from itertools import chain
    89import re
    910
    1011id_re = re.compile(r"^(?P<residence>\d{10})(?P<origin>\w{1,3})[-\ ]?(?P<birthday>\d{7})[-\ ]?(?P<validity>\d{7})[-\ ]?(?P<checksum>\d{1})$")
     
    2021    """
    2122    A Select widget that uses a list of DE states as its choices.
    2223    """
    23     def __init__(self, attrs=None):
     24    def __init__(self, attrs=None, empty_label=u"---------"):
    2425        from de_states import STATE_CHOICES
    25         super(DEStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
     26        select_choices = STATE_CHOICES
     27        if empty_label is not None:
     28            select_choices = chain(((u'', empty_label),), STATE_CHOICES)
     29        super(DEStateSelect, self).__init__(attrs, choices=select_choices)
    2630
    2731class DEIdentityCardNumberField(Field):
    2832    """
  • django/contrib/localflavor/ch/forms.py

     
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
    77from django.utils.encoding import smart_unicode
    88from django.utils.translation import ugettext
     9from itertools import chain
    910import re
    1011
    1112id_re = re.compile(r"^(?P<idnumber>\w{8})(?P<pos9>(\d{1}|<))(?P<checksum>\d{1})$")
     
    3940    """
    4041    A Select widget that uses a list of CH states as its choices.
    4142    """
    42     def __init__(self, attrs=None):
     43    def __init__(self, attrs=None, empty_label=u"---------"):
    4344        from ch_states import STATE_CHOICES # relative import
    44         super(CHStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
     45        select_choices = STATE_CHOICES
     46        if empty_label is not None:
     47            select_choices = chain(((u'', empty_label),), STATE_CHOICES)
     48        super(CHStateSelect, self).__init__(attrs, choices=select_choices)
    4549
    4650class CHIdentityCardNumberField(Field):
    4751    """
  • django/contrib/localflavor/fi/forms.py

     
    66from django.newforms import ValidationError
    77from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
    88from django.utils.translation import ugettext
     9from itertools import chain
    910
    1011class FIZipCodeField(RegexField):
    1112    def __init__(self, *args, **kwargs):
     
    1819    """
    1920    A Select widget that uses a list of Finnish municipalities as its choices.
    2021    """
    21     def __init__(self, attrs=None):
     22    def __init__(self, attrs=None, empty_label=u"---------"):
    2223        from fi_municipalities import MUNICIPALITY_CHOICES
    23         super(FIMunicipalitySelect, self).__init__(attrs, choices=MUNICIPALITY_CHOICES)
     24        select_choices = MUNICIPALITY_CHOICES
     25        if empty_label is not None:
     26            select_choices = chain(((u'', empty_label),), MUNICIPALITY_CHOICES)
     27        super(FIMunicipalitySelect, self).__init__(attrs, choices=select_choices)
    2428
    2529class FISocialSecurityNumber(Field):
    2630    def clean(self, value):
  • django/contrib/localflavor/cl/forms.py

     
    66from django.newforms.fields import RegexField, Select, EMPTY_VALUES
    77from django.utils.translation import ugettext
    88from django.utils.encoding import smart_unicode
     9from itertools import chain
    910
    1011
    1112class CLRegionSelect(Select):
     
    1314    A Select widget that uses a list of Chilean Regions (Regiones)
    1415    as its choices.
    1516    """
    16     def __init__(self, attrs=None):
     17    def __init__(self, attrs=None, empty_label=u"---------"):
    1718        from cl_regions import REGION_CHOICES
    18         super(CLRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
     19        select_choices = REGION_CHOICES
     20        if empty_label is not None:
     21            select_choices = chain(((u'', empty_label),), REGION_CHOICES)
     22        super(CLRegionSelect, self).__init__(attrs, choices=select_choices)
    1923
    2024class CLRutField(RegexField):
    2125    """
  • django/contrib/localflavor/ar/forms.py

     
    77from django.newforms.fields import RegexField, CharField, Select, EMPTY_VALUES
    88from django.utils.encoding import smart_unicode
    99from django.utils.translation import ugettext
     10from itertools import chain
    1011import re
    1112
    1213class ARProvinceSelect(Select):
     
    1415    A Select widget that uses a list of Argentinean provinces/autonomous cities
    1516    as its choices.
    1617    """
    17     def __init__(self, attrs=None):
     18    def __init__(self, attrs=None, empty_label=u"---------"):
    1819        from ar_provinces import PROVINCE_CHOICES
    19         super(ARProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
     20        select_choices = PROVINCE_CHOICES
     21        if empty_label is not None:
     22            select_choices = chain(((u'', empty_label),), PROVINCE_CHOICES)
     23        super(ARProvinceSelect, self).__init__(attrs, choices=select_choices)
    2024
    2125class ARPostalCodeField(RegexField):
    2226    """
  • django/contrib/localflavor/br/forms.py

     
    77from django.newforms.fields import Field, RegexField, CharField, Select, EMPTY_VALUES
    88from django.utils.encoding import smart_unicode
    99from django.utils.translation import ugettext as _
     10from itertools import chain
    1011import re
    1112
    1213try:
     
    3940    A Select widget that uses a list of Brazilian states/territories
    4041    as its choices.
    4142    """
    42     def __init__(self, attrs=None):
     43    def __init__(self, attrs=None, empty_label=u"---------"):
    4344        from br_states import STATE_CHOICES
    44         super(BRStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
     45        select_choices = STATE_CHOICES
     46        if empty_label is not None:
     47            select_choices = chain(((u'', empty_label),), STATE_CHOICES)
     48        super(BRStateSelect, self).__init__(attrs, choices=select_choices)
    4549
    4650class BRStateChoiceField(Field):
    4751    """
  • django/contrib/localflavor/in_/forms.py

     
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
    77from django.utils.encoding import smart_unicode
    88from django.utils.translation import gettext
     9from itertools import chain
    910import re
    1011
    1112
     
    4344    A Select widget that uses a list of Indian states/territories as its
    4445    choices.
    4546    """
    46     def __init__(self, attrs=None):
     47    def __init__(self, attrs=None, empty_label=u"---------"):
    4748        from in_states import STATE_CHOICES
    48         super(INStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
     49        select_choices = STATE_CHOICES
     50        if empty_label is not None:
     51            select_choices = chain(((u'', empty_label),), STATE_CHOICES)
     52        super(INStateSelect, self).__init__(attrs, choices=select_choices)
    4953
  • django/contrib/localflavor/au/forms.py

     
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
    77from django.newforms.util import smart_unicode
    88from django.utils.translation import ugettext
     9from itertools import chain
    910import re
    1011
    1112PHONE_DIGITS_RE = re.compile(r'^(\d{10})$')
     
    3839    A Select widget that uses a list of Australian states/territories as its
    3940    choices.
    4041    """
    41     def __init__(self, attrs=None):
     42    def __init__(self, attrs=None, empty_label=u"---------"):
    4243        from au_states import STATE_CHOICES
    43         super(AUStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
     44        select_choices = STATE_CHOICES
     45        if empty_label is not None:
     46            select_choices = chain(((u'', empty_label),), STATE_CHOICES)       
     47        super(AUStateSelect, self).__init__(attrs, choices=select_choices)
  • django/contrib/localflavor/fr/forms.py

     
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
    77from django.utils.encoding import smart_unicode
    88from django.utils.translation import ugettext
     9from itertools import chain
    910import re
    1011
    1112phone_digits_re = re.compile(r'^0\d(\s|\.)?(\d{2}(\s|\.)?){3}\d{2}$')
     
    3839    """
    3940    A Select widget that uses a list of FR departments as its choices.
    4041    """
    41     def __init__(self, attrs=None):
     42    def __init__(self, attrs=None, empty_label=u"---------"):
    4243        from fr_department import DEPARTMENT_ASCII_CHOICES
    43         super(FRDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_ASCII_CHOICES)
     44        select_choices = DEPARTMENT_ASCII_CHOICES
     45        if empty_label is not None:
     46            select_choices = chain(((u'', empty_label),), DEPARTMENT_ASCII_CHOICES)
     47        super(FRDepartmentSelect, self).__init__(attrs, choices=select_choices)
    4448
  • django/contrib/localflavor/nl/forms.py

     
    88from django.newforms.fields import Field, Select, EMPTY_VALUES
    99from django.utils.translation import ugettext as _
    1010from django.utils.encoding import smart_unicode
     11from itertools import chain
    1112
    1213pc_re = re.compile('^\d{4}[A-Z]{2}$')
    1314sofi_re = re.compile('^\d{9}$')
     
    3738    A Select widget that uses a list of provinces of the Netherlands as its
    3839    choices.
    3940    """
    40     def __init__(self, attrs=None):
     41    def __init__(self, attrs=None, empty_label=u"---------"):
    4142        from nl_provinces import PROVINCE_CHOICES
    42         super(NLProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
     43        select_choices = PROVINCE_CHOICES
     44        if empty_label is not None:
     45            select_choices = chain(((u'', empty_label),), PROVINCE_CHOICES)
     46        super(NLProvinceSelect, self).__init__(attrs, choices=select_choices)
    4347
    4448class NLPhoneNumberField(Field):
    4549    """
  • django/contrib/localflavor/jp/forms.py

     
    66from django.newforms import ValidationError
    77from django.utils.translation import ugettext
    88from django.newforms.fields import RegexField, Select
     9from itertools import chain
    910
    1011import re
    1112
     
    3334    """
    3435    A Select widget that uses a list of Japanese prefectures as its choices.
    3536    """
    36     def __init__(self, attrs=None):
     37    def __init__(self, attrs=None, empty_label=u"---------"):
    3738        from jp_prefectures import JP_PREFECTURES
    38         super(JPPrefectureSelect, self).__init__(attrs, choices=JP_PREFECTURES)
     39        select_choices = JP_PREFECTURES
     40        if empty_label is not None:
     41            select_choices = chain(((u'', empty_label),), JP_PREFECTURES)
     42        super(JPPrefectureSelect, self).__init__(attrs, choices=select_choices)
  • django/contrib/localflavor/is_/forms.py

     
    77from django.newforms.widgets import Select
    88from django.utils.translation import ugettext
    99from django.utils.encoding import smart_unicode
     10from itertools import chain
    1011
    1112class ISIdNumberField(RegexField):
    1213    """
     
    7273    """
    7374    A Select widget that uses a list of Icelandic postal codes as its choices.
    7475    """
    75     def __init__(self, attrs=None):
     76    def __init__(self, attrs=None, empty_label=u"---------"):
    7677        from is_postalcodes import IS_POSTALCODES
    77         super(ISPostalCodeSelect, self).__init__(attrs, choices=IS_POSTALCODES)
     78        select_choices = IS_POSTALCODES
     79        if empty_label is not None:
     80            select_choices = chain(((u'', empty_label),), IS_POSTALCODES)
     81        super(ISPostalCodeSelect, self).__init__(attrs, choices=select_choices)
    7882
  • django/contrib/localflavor/pl/forms.py

     
    55from django.newforms import ValidationError
    66from django.newforms.fields import Select, RegexField
    77from django.utils.translation import ugettext as _
     8from itertools import chain
    89
    910class PLVoivodeshipSelect(Select):
    1011    """
    1112    A select widget with list of Polish voivodeships (administrative provinces)
    1213    as choices.
    1314    """
    14     def __init__(self, attrs=None):
     15    def __init__(self, attrs=None, empty_label=u"---------"):
    1516        from pl_voivodeships import VOIVODESHIP_CHOICES
    16         super(PLVoivodeshipSelect, self).__init__(attrs, choices=VOIVODESHIP_CHOICES)
     17        select_choices = VOIVODESHIP_CHOICES
     18        if empty_label is not None:
     19            select_choices = chain(((u'', empty_label),), VOIVODESHIP_CHOICES)
     20        super(PLVoivodeshipSelect, self).__init__(attrs, choices=select_choices)
    1721
    1822class PLAdministrativeUnitSelect(Select):
    1923    """
    2024    A select widget with list of Polish administrative units as choices.
    2125    """
    22     def __init__(self, attrs=None):
     26    def __init__(self, attrs=None, empty_label=u"---------"):
    2327        from pl_administrativeunits import ADMINISTRATIVE_UNIT_CHOICES
    24         super(PLAdministrativeUnitSelect, self).__init__(attrs, choices=ADMINISTRATIVE_UNIT_CHOICES)
     28        select_choices = ADMINISTRATIVE_UNIT_CHOICES
     29        if empty_label is not None:
     30            select_choices = chain(((u'', empty_label),), ADMINISTRATIVE_UNIT_CHOICES)
     31        super(PLAdministrativeUnitSelect, self).__init__(attrs, choices=select_choices)
    2532
    2633class PLNationalIdentificationNumberField(RegexField):
    2734    """
  • django/contrib/localflavor/no/forms.py

     
    66from django.newforms import ValidationError
    77from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
    88from django.utils.translation import ugettext
     9from itertools import chain
    910
    1011class NOZipCodeField(RegexField):
    1112    def __init__(self, *args, **kwargs):
     
    1920    A Select widget that uses a list of Norwegian municipalities (fylker)
    2021    as its choices.
    2122    """
    22     def __init__(self, attrs=None):
     23    def __init__(self, attrs=None, empty_label=u"---------"):
    2324        from no_municipalities import MUNICIPALITY_CHOICES
    24         super(NOMunicipalitySelect, self).__init__(attrs, choices=MUNICIPALITY_CHOICES)
     25        select_choices = MUNICIPALITY_CHOICES
     26        if empty_label is not None:
     27            select_choices = chain(((u'', empty_label),), MUNICIPALITY_CHOICES)
     28        super(NOMunicipalitySelect, self).__init__(attrs, choices=select_choices)
    2529
    2630class NOSocialSecurityNumber(Field):
    2731    """
  • django/contrib/localflavor/it/forms.py

     
    77from django.utils.translation import ugettext
    88from django.utils.encoding import smart_unicode
    99from django.contrib.localflavor.it.util import ssn_check_digit, vat_number_check_digit
     10from itertools import chain
    1011import re
    1112
    1213class ITZipCodeField(RegexField):
     
    2021    """
    2122    A Select widget that uses a list of IT regions as its choices.
    2223    """
    23     def __init__(self, attrs=None):
     24    def __init__(self, attrs=None, empty_label=u"---------"):
    2425        from it_region import REGION_CHOICES
    25         super(ITRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
     26        select_choices = REGION_CHOICES
     27        if empty_label is not None:
     28            select_choices = chain(((u'', empty_label),), REGION_CHOICES)
     29        super(ITRegionSelect, self).__init__(attrs, choices=select_choices)
    2630
    2731class ITProvinceSelect(Select):
    2832    """
    2933    A Select widget that uses a list of IT regions as its choices.
    3034    """
    31     def __init__(self, attrs=None):
     35    def __init__(self, attrs=None, empty_label=u"---------"):
    3236        from it_province import PROVINCE_CHOICES
    33         super(ITProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
     37        select_choices = PROVINCE_CHOICES
     38        if empty_label is not None:
     39            select_choices = chain(((u'', empty_label),), PROVINCE_CHOICES)
     40        super(ITProvinceSelect, self).__init__(attrs, choices=select_choices)
    3441
    3542class ITSocialSecurityNumberField(RegexField):
    3643    """
  • django/contrib/localflavor/sk/forms.py

     
    44
    55from django.newforms.fields import Select, RegexField
    66from django.utils.translation import ugettext
     7from itertools import chain
    78
    89class SKRegionSelect(Select):
    910    """
    1011    A select widget widget with list of Slovak regions as choices.
    1112    """
    12     def __init__(self, attrs=None):
     13    def __init__(self, attrs=None, empty_label=u"---------"):
    1314        from sk_regions import REGION_CHOICES
    14         super(SKRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
     15        select_choices = REGION_CHOICES
     16        if empty_label is not None:
     17            select_choices = chain(((u'', empty_label),), REGION_CHOICES)
     18        super(SKRegionSelect, self).__init__(attrs, choices=select_choices)
    1519
    1620class SKDistrictSelect(Select):
    1721    """
    1822    A select widget with list of Slovak districts as choices.
    1923    """
    20     def __init__(self, attrs=None):
     24    def __init__(self, attrs=None, empty_label=u"---------"):
    2125        from sk_districts import DISTRICT_CHOICES
    22         super(SKDistrictSelect, self).__init__(attrs, choices=DISTRICT_CHOICES)
     26        select_choices = DISTRICT_CHOICES
     27        if empty_label is not None:
     28            select_choices = chain(((u'', empty_label),), DISTRICT_CHOICES)
     29        super(SKDistrictSelect, self).__init__(attrs, choices=select_choices)
    2330
    2431class SKPostalCodeField(RegexField):
    2532    """
Back to Top