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''