Fixed #17275 -- Moved some imports back from module level to class level to prevent the test suite from raising warnings.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17164 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Aymeric Augustin 2011-12-01 20:21:00 +00:00
parent 0d0f874d21
commit be8938f0d8
2 changed files with 10 additions and 2 deletions

View File

@ -6,7 +6,6 @@ from __future__ import absolute_import
import re import re
from django.contrib.localflavor.ca.ca_provinces import PROVINCE_CHOICES, PROVINCES_NORMALIZED
from django.core.validators import EMPTY_VALUES from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError from django.forms import ValidationError
from django.forms.fields import Field, CharField, Select from django.forms.fields import Field, CharField, Select
@ -79,6 +78,8 @@ class CAProvinceField(Field):
except AttributeError: except AttributeError:
pass pass
else: else:
# Load data in memory only when it is required, see also #17275
from django.contrib.localflavor.ca.ca_provinces import PROVINCES_NORMALIZED
try: try:
return PROVINCES_NORMALIZED[value.strip().lower()].decode('ascii') return PROVINCES_NORMALIZED[value.strip().lower()].decode('ascii')
except KeyError: except KeyError:
@ -91,6 +92,8 @@ class CAProvinceSelect(Select):
territories as its choices. territories as its choices.
""" """
def __init__(self, attrs=None): def __init__(self, attrs=None):
# Load data in memory only when it is required, see also #17275
from django.contrib.localflavor.ca.ca_provinces import PROVINCE_CHOICES
super(CAProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES) super(CAProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
class CASocialInsuranceNumberField(Field): class CASocialInsuranceNumberField(Field):

View File

@ -8,7 +8,6 @@ import re
import time import time
from django.core.validators import EMPTY_VALUES from django.core.validators import EMPTY_VALUES
from django.contrib.localflavor.id.id_choices import PROVINCE_CHOICES, LICENSE_PLATE_PREFIX_CHOICES
from django.forms import ValidationError from django.forms import ValidationError
from django.forms.fields import Field, Select from django.forms.fields import Field, Select
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -58,6 +57,8 @@ class IDProvinceSelect(Select):
""" """
def __init__(self, attrs=None): def __init__(self, attrs=None):
# Load data in memory only when it is required, see also #17275
from django.contrib.localflavor.id.id_choices import PROVINCE_CHOICES
super(IDProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES) super(IDProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
@ -93,6 +94,8 @@ class IDLicensePlatePrefixSelect(Select):
""" """
def __init__(self, attrs=None): def __init__(self, attrs=None):
# Load data in memory only when it is required, see also #17275
from django.contrib.localflavor.id.id_choices import LICENSE_PLATE_PREFIX_CHOICES
super(IDLicensePlatePrefixSelect, self).__init__(attrs, super(IDLicensePlatePrefixSelect, self).__init__(attrs,
choices=LICENSE_PLATE_PREFIX_CHOICES) choices=LICENSE_PLATE_PREFIX_CHOICES)
@ -110,6 +113,8 @@ class IDLicensePlateField(Field):
} }
def clean(self, value): def clean(self, value):
# Load data in memory only when it is required, see also #17275
from django.contrib.localflavor.id.id_choices import LICENSE_PLATE_PREFIX_CHOICES
super(IDLicensePlateField, self).clean(value) super(IDLicensePlateField, self).clean(value)
if value in EMPTY_VALUES: if value in EMPTY_VALUES:
return u'' return u''