Permalink
Browse files

IsRequired rule breaks on anything other than string.

  • Loading branch information...
Wilhelm Murdoch
Wilhelm Murdoch committed Apr 17, 2012
1 parent 145d318 commit c0a5b45c00499a1f156b48a02b34f7832aa3820a
Showing with 22 additions and 5 deletions.
  1. +22 −5 validator/rules.py
View
@@ -122,13 +122,30 @@ def __init__(self, error = None):
-class IsRequired(Regex):
- """ Regex convenience derivative class used to determine if given field is empty. """
+class IsRequired(Rule):
+ """ Used to determine if given field is empty. """
def __init__(self, error = None):
- super(IsRequired, self).__init__(r'^.{1,}$', error)
- if not error:
- self.error = 'This field requires a value.'
+ """ Constructor that instantiates a class instance and properties.
+
+ Keyword arguments:
+ error str -- A user-defined error messaged for a failed rule. (optional)
+ """
+
+ super(IsRequired, self).__init__(error)
+
+ def run(self, field_value):
+ """ Determines if field_value value is empty.
+
+ Keyword arguments:
+ field_value str -- the value of the associated field to compare
+ """
+
+ if not field_value:
+ if not error:
+ self.error = 'This field requires a value.'
+ return False
+ return True

0 comments on commit c0a5b45

Please sign in to comment.