From be8938f0d83911f33f9e439fea925a7f32ab5c96 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Thu, 1 Dec 2011 20:21:00 +0000 Subject: [PATCH] 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 --- django/contrib/localflavor/ca/forms.py | 5 ++++- django/contrib/localflavor/id/forms.py | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/django/contrib/localflavor/ca/forms.py b/django/contrib/localflavor/ca/forms.py index a84a6d9557..37f966eb64 100644 --- a/django/contrib/localflavor/ca/forms.py +++ b/django/contrib/localflavor/ca/forms.py @@ -6,7 +6,6 @@ from __future__ import absolute_import import re -from django.contrib.localflavor.ca.ca_provinces import PROVINCE_CHOICES, PROVINCES_NORMALIZED from django.core.validators import EMPTY_VALUES from django.forms import ValidationError from django.forms.fields import Field, CharField, Select @@ -79,6 +78,8 @@ class CAProvinceField(Field): except AttributeError: pass else: + # Load data in memory only when it is required, see also #17275 + from django.contrib.localflavor.ca.ca_provinces import PROVINCES_NORMALIZED try: return PROVINCES_NORMALIZED[value.strip().lower()].decode('ascii') except KeyError: @@ -91,6 +92,8 @@ class CAProvinceSelect(Select): territories as its choices. """ 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) class CASocialInsuranceNumberField(Field): diff --git a/django/contrib/localflavor/id/forms.py b/django/contrib/localflavor/id/forms.py index e2419f3b1c..9439dba594 100644 --- a/django/contrib/localflavor/id/forms.py +++ b/django/contrib/localflavor/id/forms.py @@ -8,7 +8,6 @@ import re import time 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.fields import Field, Select from django.utils.translation import ugettext_lazy as _ @@ -58,6 +57,8 @@ class IDProvinceSelect(Select): """ 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) @@ -93,6 +94,8 @@ class IDLicensePlatePrefixSelect(Select): """ 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, choices=LICENSE_PLATE_PREFIX_CHOICES) @@ -110,6 +113,8 @@ class IDLicensePlateField(Field): } 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) if value in EMPTY_VALUES: return u''