summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-07-05 13:25:26 +0000
committerHonza Král <honza.kral@gmail.com>2009-07-05 13:25:26 +0000
commit69c8d4622ec1d9327e73b4138213a71ae48e301a (patch)
tree80ef3598ee72c95824f1ee4a731855bcd53dfb93
parentd628498c58aab0c4deafe6b9d08e6220ee093fc5 (diff)
[soc2009/model-validation] module validators already imported, use it.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11181 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/localflavor/ar/forms.py3
-rw-r--r--django/contrib/localflavor/au/forms.py3
-rw-r--r--django/contrib/localflavor/br/forms.py3
-rw-r--r--django/contrib/localflavor/ca/forms.py3
-rw-r--r--django/contrib/localflavor/ch/forms.py3
-rw-r--r--django/contrib/localflavor/cl/forms.py3
-rw-r--r--django/contrib/localflavor/cz/forms.py3
-rw-r--r--django/contrib/localflavor/de/forms.py3
-rw-r--r--django/contrib/localflavor/es/forms.py3
-rw-r--r--django/contrib/localflavor/fi/forms.py3
-rw-r--r--django/contrib/localflavor/fr/forms.py3
-rw-r--r--django/contrib/localflavor/in_/forms.py3
-rw-r--r--django/contrib/localflavor/is_/forms.py3
-rw-r--r--django/contrib/localflavor/it/forms.py3
-rw-r--r--django/contrib/localflavor/nl/forms.py3
-rw-r--r--django/contrib/localflavor/no/forms.py3
-rw-r--r--django/contrib/localflavor/pe/forms.py3
-rw-r--r--django/contrib/localflavor/ro/forms.py2
-rw-r--r--django/contrib/localflavor/us/forms.py3
-rw-r--r--django/contrib/localflavor/za/forms.py3
-rw-r--r--django/forms/fields.py37
-rw-r--r--django/forms/models.py3
22 files changed, 59 insertions, 40 deletions
diff --git a/django/contrib/localflavor/ar/forms.py b/django/contrib/localflavor/ar/forms.py
index 8e8e1af387..53721a17b6 100644
--- a/django/contrib/localflavor/ar/forms.py
+++ b/django/contrib/localflavor/ar/forms.py
@@ -4,7 +4,8 @@ AR-specific Form helpers.
"""
from django.forms import ValidationError
-from django.forms.fields import RegexField, CharField, Select, EMPTY_VALUES
+from django.core.validators import EMPTY_VALUES
+from django.forms.fields import RegexField, CharField, Select
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
diff --git a/django/contrib/localflavor/au/forms.py b/django/contrib/localflavor/au/forms.py
index 4e8a204283..87e04387f5 100644
--- a/django/contrib/localflavor/au/forms.py
+++ b/django/contrib/localflavor/au/forms.py
@@ -2,8 +2,9 @@
Australian-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
diff --git a/django/contrib/localflavor/br/forms.py b/django/contrib/localflavor/br/forms.py
index 6d0a0384c6..9f482cd01f 100644
--- a/django/contrib/localflavor/br/forms.py
+++ b/django/contrib/localflavor/br/forms.py
@@ -3,8 +3,9 @@
BR-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, CharField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, CharField, Select
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
diff --git a/django/contrib/localflavor/ca/forms.py b/django/contrib/localflavor/ca/forms.py
index 9544268cbe..dbf3d74bee 100644
--- a/django/contrib/localflavor/ca/forms.py
+++ b/django/contrib/localflavor/ca/forms.py
@@ -2,8 +2,9 @@
Canada-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
diff --git a/django/contrib/localflavor/ch/forms.py b/django/contrib/localflavor/ch/forms.py
index bd92fcae98..eb1ae68844 100644
--- a/django/contrib/localflavor/ch/forms.py
+++ b/django/contrib/localflavor/ch/forms.py
@@ -2,8 +2,9 @@
Swiss-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
diff --git a/django/contrib/localflavor/cl/forms.py b/django/contrib/localflavor/cl/forms.py
index 61b3ab7aac..48219e88af 100644
--- a/django/contrib/localflavor/cl/forms.py
+++ b/django/contrib/localflavor/cl/forms.py
@@ -2,8 +2,9 @@
Chile specific form helpers.
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import RegexField, Select, EMPTY_VALUES
+from django.forms.fields import RegexField, Select
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode
diff --git a/django/contrib/localflavor/cz/forms.py b/django/contrib/localflavor/cz/forms.py
index 6c7a5bf5dd..e980569c70 100644
--- a/django/contrib/localflavor/cz/forms.py
+++ b/django/contrib/localflavor/cz/forms.py
@@ -2,8 +2,9 @@
Czech-specific form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Select, RegexField, Field, EMPTY_VALUES
+from django.forms.fields import Select, RegexField, Field
from django.utils.translation import ugettext_lazy as _
import re
diff --git a/django/contrib/localflavor/de/forms.py b/django/contrib/localflavor/de/forms.py
index 7a1b7c03c8..a785a7194e 100644
--- a/django/contrib/localflavor/de/forms.py
+++ b/django/contrib/localflavor/de/forms.py
@@ -2,8 +2,9 @@
DE-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select
from django.utils.translation import ugettext_lazy as _
import re
diff --git a/django/contrib/localflavor/es/forms.py b/django/contrib/localflavor/es/forms.py
index a033f3e46b..8c4a19e614 100644
--- a/django/contrib/localflavor/es/forms.py
+++ b/django/contrib/localflavor/es/forms.py
@@ -3,8 +3,9 @@
Spanish-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import RegexField, Select, EMPTY_VALUES
+from django.forms.fields import RegexField, Select
from django.utils.translation import ugettext_lazy as _
import re
diff --git a/django/contrib/localflavor/fi/forms.py b/django/contrib/localflavor/fi/forms.py
index 2b82a796fe..9c163c9143 100644
--- a/django/contrib/localflavor/fi/forms.py
+++ b/django/contrib/localflavor/fi/forms.py
@@ -3,8 +3,9 @@ FI-specific Form helpers
"""
import re
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select
from django.utils.translation import ugettext_lazy as _
class FIZipCodeField(RegexField):
diff --git a/django/contrib/localflavor/fr/forms.py b/django/contrib/localflavor/fr/forms.py
index 8d9d9d7771..7d782b609b 100644
--- a/django/contrib/localflavor/fr/forms.py
+++ b/django/contrib/localflavor/fr/forms.py
@@ -2,8 +2,9 @@
FR-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
diff --git a/django/contrib/localflavor/in_/forms.py b/django/contrib/localflavor/in_/forms.py
index 270b0a09b1..0597623400 100644
--- a/django/contrib/localflavor/in_/forms.py
+++ b/django/contrib/localflavor/in_/forms.py
@@ -2,8 +2,9 @@
India-specific Form helpers.
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select
from django.utils.encoding import smart_unicode
from django.utils.translation import gettext
import re
diff --git a/django/contrib/localflavor/is_/forms.py b/django/contrib/localflavor/is_/forms.py
index cab6eb18c0..abf858df2b 100644
--- a/django/contrib/localflavor/is_/forms.py
+++ b/django/contrib/localflavor/is_/forms.py
@@ -2,8 +2,9 @@
Iceland specific form helpers.
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import RegexField, EMPTY_VALUES
+from django.forms.fields import RegexField
from django.forms.widgets import Select
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode
diff --git a/django/contrib/localflavor/it/forms.py b/django/contrib/localflavor/it/forms.py
index d2d651955a..baa56a21ba 100644
--- a/django/contrib/localflavor/it/forms.py
+++ b/django/contrib/localflavor/it/forms.py
@@ -2,8 +2,9 @@
IT-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode
from django.contrib.localflavor.it.util import ssn_check_digit, vat_number_check_digit
diff --git a/django/contrib/localflavor/nl/forms.py b/django/contrib/localflavor/nl/forms.py
index 6dc5319eb7..997c28f609 100644
--- a/django/contrib/localflavor/nl/forms.py
+++ b/django/contrib/localflavor/nl/forms.py
@@ -4,8 +4,9 @@ NL-specific Form helpers
import re
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, Select, EMPTY_VALUES
+from django.forms.fields import Field, Select
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode
diff --git a/django/contrib/localflavor/no/forms.py b/django/contrib/localflavor/no/forms.py
index 0fe55adf7e..61a269c0fe 100644
--- a/django/contrib/localflavor/no/forms.py
+++ b/django/contrib/localflavor/no/forms.py
@@ -3,8 +3,9 @@ Norwegian-specific Form helpers
"""
import re, datetime
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select
from django.utils.translation import ugettext_lazy as _
class NOZipCodeField(RegexField):
diff --git a/django/contrib/localflavor/pe/forms.py b/django/contrib/localflavor/pe/forms.py
index d83a2225be..7a4ac9e8d9 100644
--- a/django/contrib/localflavor/pe/forms.py
+++ b/django/contrib/localflavor/pe/forms.py
@@ -3,8 +3,9 @@
PE-specific Form helpers.
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import RegexField, CharField, Select, EMPTY_VALUES
+from django.forms.fields import RegexField, CharField, Select
from django.utils.translation import ugettext_lazy as _
class PERegionSelect(Select):
diff --git a/django/contrib/localflavor/ro/forms.py b/django/contrib/localflavor/ro/forms.py
index ca51d91839..dd86fce9f2 100644
--- a/django/contrib/localflavor/ro/forms.py
+++ b/django/contrib/localflavor/ro/forms.py
@@ -5,8 +5,8 @@ Romanian specific form helpers.
import re
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError, Field, RegexField, Select
-from django.forms.fields import EMPTY_VALUES
from django.utils.translation import ugettext_lazy as _
class ROCIFField(RegexField):
diff --git a/django/contrib/localflavor/us/forms.py b/django/contrib/localflavor/us/forms.py
index a744edce74..7879e323f6 100644
--- a/django/contrib/localflavor/us/forms.py
+++ b/django/contrib/localflavor/us/forms.py
@@ -2,8 +2,9 @@
USA-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
diff --git a/django/contrib/localflavor/za/forms.py b/django/contrib/localflavor/za/forms.py
index 7b7b714398..9a54f1ecb2 100644
--- a/django/contrib/localflavor/za/forms.py
+++ b/django/contrib/localflavor/za/forms.py
@@ -2,8 +2,9 @@
South Africa-specific Form helpers
"""
+from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, EMPTY_VALUES
+from django.forms.fields import Field, RegexField
from django.utils.checksums import luhn
from django.utils.translation import gettext as _
import re
diff --git a/django/forms/fields.py b/django/forms/fields.py
index ee0b387b95..ae91dea70f 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -25,7 +25,6 @@ except NameError:
from django.core.exceptions import ValidationError
from django.core import validators
-from django.core.validators import EMPTY_VALUES
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode, smart_str
@@ -117,7 +116,7 @@ class Field(object):
return value
def validate(self, value):
- if value in EMPTY_VALUES and self.required:
+ if value in validators.EMPTY_VALUES and self.required:
raise ValidationError(self.error_messages['required'])
def run_validators(self, value):
@@ -176,14 +175,14 @@ class CharField(Field):
def to_python(self, value):
"Returns a Unicode object."
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
return u''
return smart_unicode(value)
def validate(self, value):
"Validates max_length and min_length."
super(CharField, self).validate(value)
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
# non-required field, no need for further validation
return
value_length = len(value)
@@ -214,7 +213,7 @@ class IntegerField(Field):
of int(). Returns None for empty values.
"""
value = super(IntegerField, self).to_python(value)
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
return None
try:
@@ -225,7 +224,7 @@ class IntegerField(Field):
def validate(self, value):
super(IntegerField, self).validate(value)
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
return
if self.max_value is not None and value > self.max_value:
raise ValidationError(self.error_messages['max_value'] % self.max_value)
@@ -245,7 +244,7 @@ class FloatField(IntegerField):
of float(). Returns None for empty values.
"""
value = super(IntegerField, self).to_python(value)
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
return None
try:
@@ -276,7 +275,7 @@ class DecimalField(Field):
than max_digits in the number, and no more than decimal_places digits
after the decimal point.
"""
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
return None
value = smart_str(value).strip()
try:
@@ -287,7 +286,7 @@ class DecimalField(Field):
def validate(self, value):
super(DecimalField, self).validate(value)
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
return
sign, digittuple, exponent = value.as_tuple()
decimals = abs(exponent)
@@ -336,7 +335,7 @@ class DateField(Field):
Validates that the input can be converted to a date. Returns a Python
datetime.date object.
"""
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
return None
if isinstance(value, datetime.datetime):
return value.date()
@@ -369,7 +368,7 @@ class TimeField(Field):
Validates that the input can be converted to a time. Returns a Python
datetime.time object.
"""
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
return None
if isinstance(value, datetime.time):
return value
@@ -407,7 +406,7 @@ class DateTimeField(Field):
Validates that the input can be converted to a datetime. Returns a
Python datetime.datetime object.
"""
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
return None
if isinstance(value, datetime.datetime):
return value
@@ -482,7 +481,7 @@ class FileField(Field):
super(FileField, self).__init__(*args, **kwargs)
def to_python(self, data):
- if data in EMPTY_VALUES:
+ if data in validators.EMPTY_VALUES:
return None
# UploadedFile objects should have name and size attributes.
@@ -677,7 +676,7 @@ class ChoiceField(Field):
def to_python(self, value):
"Returns a Unicode object."
- if value in EMPTY_VALUES:
+ if value in validators.EMPTY_VALUES:
return u''
return smart_unicode(value)
@@ -715,7 +714,7 @@ class TypedChoiceField(ChoiceField):
"""
value = super(TypedChoiceField, self).to_python(value)
super(TypedChoiceField, self).validate(value)
- if value == self.empty_value or value in EMPTY_VALUES:
+ if value == self.empty_value or value in validators.EMPTY_VALUES:
return self.empty_value
try:
value = self.coerce(value)
@@ -820,7 +819,7 @@ class MultiValueField(Field):
clean_data = []
errors = ErrorList()
if not value or isinstance(value, (list, tuple)):
- if not value or not [v for v in value if v not in EMPTY_VALUES]:
+ if not value or not [v for v in value if v not in validators.EMPTY_VALUES]:
if self.required:
raise ValidationError(self.error_messages['required'])
else:
@@ -832,7 +831,7 @@ class MultiValueField(Field):
field_value = value[i]
except IndexError:
field_value = None
- if self.required and field_value in EMPTY_VALUES:
+ if self.required and field_value in validators.EMPTY_VALUES:
raise ValidationError(self.error_messages['required'])
try:
clean_data.append(field.clean(field_value))
@@ -915,9 +914,9 @@ class SplitDateTimeField(MultiValueField):
if data_list:
# Raise a validation error if time or date is empty
# (possible if SplitDateTimeField has required=False).
- if data_list[0] in EMPTY_VALUES:
+ if data_list[0] in validators.EMPTY_VALUES:
raise ValidationError(self.error_messages['invalid_date'])
- if data_list[1] in EMPTY_VALUES:
+ if data_list[1] in validators.EMPTY_VALUES:
raise ValidationError(self.error_messages['invalid_time'])
return datetime.datetime.combine(*data_list)
return None
diff --git a/django/forms/models.py b/django/forms/models.py
index d48f33a606..b3d7c28155 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -9,9 +9,10 @@ from django.utils.text import get_text_list, capfirst
from django.utils.translation import ugettext_lazy as _, ugettext
from django.core.exceptions import ValidationError, NON_FIELD_ERRORS
+from django.core.validators import EMPTY_VALUES
from util import ErrorList
from forms import BaseForm, get_declared_fields, NON_FIELD_ERRORS
-from fields import Field, ChoiceField, IntegerField, EMPTY_VALUES
+from fields import Field, ChoiceField, IntegerField
from widgets import Select, SelectMultiple, HiddenInput, MultipleHiddenInput
from widgets import media_property
from formsets import BaseFormSet, formset_factory, DELETION_FIELD_NAME