Anonymous avatar Anonymous committed 6617f5b

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

Comments (0)

Files changed (6)

django/core/exceptions.py

         """
         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):

django/db/models/base.py

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

django/db/models/fields/__init__.py

         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)
 
         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)
                         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):
         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.
         """
             return int(value)
         except (TypeError, ValueError):
             raise exceptions.ValidationError(self.error_messages['invalid'])
-        
+
     def validate(self, value, model_instance):
         pass
 
     def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs):
         self.schema_path = schema_path
         Field.__init__(self, verbose_name, name, **kwargs)
+

django/forms/forms.py

                 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:

django/forms/util.py

 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):

tests/modeltests/validation/test_unique.py

         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)
         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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.