Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[soc2009/model-validation] Cleaned up some comments and whitespace.

  • Loading branch information...
commit c2a2b51ac3009739813a7e6ba22f3c7053a30da2 1 parent 201d171
@jkocherhans jkocherhans authored
View
1  django/core/exceptions.py
@@ -44,6 +44,7 @@ def __init__(self, message, code=None, params=None):
"""
if isinstance(message, dict):
self.message_dict = message
+ # Reduce each list of messages into a single list.
message = reduce(operator.add, message.values())
if isinstance(message, list):
View
3  django/db/models/base.py
@@ -819,8 +819,9 @@ def clean(self, exclude=[]):
error_list.append(message)
else:
error_list.extend(e.messages)
+ # Form.clean() is run even if other validation fails, so do the
+ # same with Model.validate() for consistency.
try:
- # TODO: run this only if not errors??
self.validate()
except ValidationError, e:
if hasattr(e, 'message_dict'):
View
17 django/db/models/fields/__init__.py
@@ -149,7 +149,6 @@ def __setstate__(self, obj_dict):
for k in translated_keys:
self.error_messages[k] = _(self.error_messages[k])
-
def __cmp__(self, other):
# This is needed because bisect does not take a comparison function.
return cmp(self.creation_counter, other.creation_counter)
@@ -177,8 +176,8 @@ def run_validators(self, value):
errors = []
for v in self.validators:
- # don't run complex validators since they need obj
- # and must therefore be run on the model level
+ # Don't run complex validators since they need the model instance
+ # and must therefore be run on the model level.
if not isinstance(v, validators.ComplexValidator):
try:
v(value)
@@ -192,14 +191,14 @@ def run_validators(self, value):
errors.extend(e.messages)
if errors:
raise exceptions.ValidationError(errors)
-
+
def validate(self, value, model_instance):
"""
Validates value and throws ValidationError. Subclasses should override
this to provide validation logic.
"""
if not self.editable:
- # skip validation for non-editable fields
+ # Skip validation for non-editable fields.
return
if self._choices and value:
if not value in dict(self.choices):
@@ -208,15 +207,12 @@ def validate(self, value, model_instance):
if value is None and not self.null:
raise exceptions.ValidationError(self.error_messages['null'])
- # cannot do if not value because of 0 passed to integer fields
if not self.blank and value in validators.EMPTY_VALUES:
raise exceptions.ValidationError(self.error_messages['blank'])
-
-
def clean(self, value, model_instance):
"""
- Convert the value's type and wun validation. Validation errors from to_python
+ Convert the value's type and run validation. Validation errors from to_python
and validate are propagated. The correct value is returned if no error is
raised.
"""
@@ -493,7 +489,7 @@ def to_python(self, value):
return int(value)
except (TypeError, ValueError):
raise exceptions.ValidationError(self.error_messages['invalid'])
-
+
def validate(self, value, model_instance):
pass
@@ -1112,3 +1108,4 @@ class XMLField(TextField):
def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs):
self.schema_path = schema_path
Field.__init__(self, verbose_name, name, **kwargs)
+
View
6 django/forms/forms.py
@@ -284,14 +284,14 @@ def full_clean(self):
if name in self.cleaned_data:
del self.cleaned_data[name]
- # run complex validators after the fields have been cleaned since they
- # need access to all_values
+ # Run complex validators after the fields have been cleaned since they
+ # need access to all_values.
for name, field in self.fields.items():
if not name in self.cleaned_data:
continue
failed = False
for v in field.validators:
- # skip noncomplex validators, they have already been run on the Field
+ # Skip noncomplex validators, they have already been run on the field.
if not isinstance(v, ComplexValidator):
continue
try:
View
4 django/forms/util.py
@@ -2,8 +2,8 @@
from django.utils.encoding import StrAndUnicode, force_unicode
from django.utils.safestring import mark_safe
-# import ValidationError so that it can be imported from this
-# module to maintain backwards compatibility
+# Import ValidationError so that it can be imported from this
+# module to maintain backwards compatibility.
from django.core.exceptions import ValidationError
def flatatt(attrs):
View
4 tests/modeltests/validation/test_unique.py
@@ -39,7 +39,7 @@ def tearDown(self):
super(PerformUniqueChecksTest, self).tearDown()
def test_primary_key_unique_check_performed_when_adding(self):
- "Check#12132"
+ """Regression test for #12132"""
l = len(connection.queries)
mtv = ModelToValidate(number=10, name='Some Name')
setattr(mtv, '_adding', True)
@@ -47,7 +47,7 @@ def test_primary_key_unique_check_performed_when_adding(self):
self.assertEqual(l+1, len(connection.queries))
def test_primary_key_unique_check_not_performed_when_not_adding(self):
- "Check#12132"
+ """Regression test for #12132"""
l = len(connection.queries)
mtv = ModelToValidate(number=10, name='Some Name')
mtv.clean()
Please sign in to comment.
Something went wrong with that request. Please try again.