summaryrefslogtreecommitdiffstats
path: root/funcweb/funcweb/widget_validation.py
diff options
context:
space:
mode:
authormakkalot <makkalot@gmail.com>2008-06-21 13:18:42 +0300
committermakkalot <makkalot@gmail.com>2008-06-21 13:18:42 +0300
commit4706ba8c79bfae2feb48fc7fd8b9bb7770077ae4 (patch)
treec60e9380d2c2c15c9f93b91ae5807db2c9ce260f /funcweb/funcweb/widget_validation.py
parentde503d14a2239fd38f377ae7bf613e553aa2fd8f (diff)
downloadthird_party-func-4706ba8c79bfae2feb48fc7fd8b9bb7770077ae4.tar.gz
third_party-func-4706ba8c79bfae2feb48fc7fd8b9bb7770077ae4.tar.xz
third_party-func-4706ba8c79bfae2feb48fc7fd8b9bb7770077ae4.zip
adding custom validator for hashes
Diffstat (limited to 'funcweb/funcweb/widget_validation.py')
-rw-r--r--funcweb/funcweb/widget_validation.py43
1 files changed, 40 insertions, 3 deletions
diff --git a/funcweb/funcweb/widget_validation.py b/funcweb/funcweb/widget_validation.py
index 964a159..61d6254 100644
--- a/funcweb/funcweb/widget_validation.py
+++ b/funcweb/funcweb/widget_validation.py
@@ -254,15 +254,52 @@ class MinionListValidator(validators.FancyValidator):
def validate_python(self,value,state):
import re
if self.regex_string:
- compiled_regex = re.compile(self.regex_string)
+ try:
+ compiled_regex = re.compile(self.regex_string)
+ except Exception,e:
+ raise validators.Invalid('The passed regex_string is not a valid expression'%self.regex_string,value,state)
+
for list_value in value:
- if not re.match(compiled_regex,list_value):
+ if not re.match(compiled_regex,str(list_value)):
raise validators.Invalid('The %s doesnt match to the regex expression that was supplied'%list_value,value,state)
#there is no else for now :)
class MinionHashValidator(validators.FancyValidator):
- pass
+
+ regex_string = None
+
+ def _to_python(self,value,state):
+ """
+ Will check just the type here and return
+ value to be validated in validate_python
+ """
+ #will add more beautiful validation here after
+ #integrate the complex widgets for lists and dicts
+ if self.not_empty:
+ if len(value)==0:
+ raise validators.Invalid('Empty hash passed when not_empty is set',value,state)
+
+ #check the type firstly
+ tmp = {}
+ if type(tmp) != type(value):
+ raise validators.Invalid('The value passed to MinionHashValidator should be a dict object',value,state)
+
+ #print value
+ return value
+
+ def validate_python(self,value,state):
+ #print value
+ import re
+ if self.regex_string:
+ try:
+ compiled_regex = re.compile(self.regex_string)
+ except Exception,e:
+ raise validators.Invalid('The passed regex_string is not a valid expression'%self.regex_string,value,state)
+ for dict_value in value.itervalues():
+ if not re.match(compiled_regex,str(dict_value)):
+ raise validators.Invalid('The %s doesnt match to the regex expression that was supplied'%dict_value,value,state)
+
if __name__ == "__main__":