Author: ianb
Date: 2008-05-14 09:35:56 -0600 (Wed, 14 May 2008)
New Revision: 3422

Modified:
   FormEncode/trunk/docs/news.txt
   FormEncode/trunk/formencode/validators.py
Log:
close SF bug 1834389, bad error when CC fields missing.  Also treat {} as 
not-empty for FormValidators

Modified: FormEncode/trunk/docs/news.txt
===================================================================
--- FormEncode/trunk/docs/news.txt      2008-05-13 23:02:17 UTC (rev 3421)
+++ FormEncode/trunk/docs/news.txt      2008-05-14 15:35:56 UTC (rev 3422)
@@ -21,6 +21,9 @@
 * The validators ``Int`` and ``Number`` both take min/max arguments
   (from Shannon Behrens).
 
+* Validators based on ``formencode.validators.FormValidator`` will not
+  treat ``{}`` as an empty (unvalidated) value.
+
 * Some adjustments to the URL validator.
 
 1.0.1

Modified: FormEncode/trunk/formencode/validators.py
===================================================================
--- FormEncode/trunk/formencode/validators.py   2008-05-13 23:02:17 UTC (rev 
3421)
+++ FormEncode/trunk/formencode/validators.py   2008-05-14 15:35:56 UTC (rev 
3422)
@@ -2474,6 +2474,9 @@
     validate_partial_python = None
     validate_partial_other = None
 
+    def is_empty(self, value):
+        return False
+
 class RequireIfMissing(FormValidator):
 
     """
@@ -2612,6 +2615,10 @@
         Traceback (most recent call last):
             ...
         Invalid: ccNumber: You did not enter a valid number of digits
+        >>> cc().to_python({})
+        Traceback (most recent call last):
+            ...
+        Invalid: The field ccType is missing
     """
 
     validate_partial_form = True
@@ -2624,6 +2631,7 @@
         'notANumber': _("Please enter only the number, no other characters"),
         'badLength': _("You did not enter a valid number of digits"),
         'invalidNumber': _("That number is not valid"),
+        'missing_key': _("The field %(key)s is missing"),
         }
 
     def validate_partial(self, field_dict, state):
@@ -2643,6 +2651,10 @@
                 field_dict, state, error_dict=errors)
         
     def _validateReturn(self, field_dict, state):
+        for field in self.cc_type_field, self.cc_number_field:
+            if field not in field_dict:
+                raise Invalid(
+                    self.message('missing_key', state, key=field), value, 
state)
         ccType = field_dict[self.cc_type_field].lower().strip()
         number = field_dict[self.cc_number_field].strip()
         number = number.replace(' ', '')


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs

Reply via email to