diff options
author | makkalot <makkalot@gmail.com> | 2008-06-21 10:38:33 +0300 |
---|---|---|
committer | makkalot <makkalot@gmail.com> | 2008-06-21 10:38:33 +0300 |
commit | c4492f0de8c185da45898865b5c8ca566f01f34f (patch) | |
tree | 46254b777825f233942ef62567d8c00a6284ad73 /funcweb | |
parent | e6eff6a9e1e80a38c0a34db12b6d8b5dbf0c0182 (diff) | |
download | third_party-func-c4492f0de8c185da45898865b5c8ca566f01f34f.tar.gz third_party-func-c4492f0de8c185da45898865b5c8ca566f01f34f.tar.xz third_party-func-c4492f0de8c185da45898865b5c8ca566f01f34f.zip |
adding a custom minion list validator will change in the future after choosing the best widget for it
Diffstat (limited to 'funcweb')
-rw-r--r-- | funcweb/funcweb/widget_validation.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/funcweb/funcweb/widget_validation.py b/funcweb/funcweb/widget_validation.py index 9abf2fd..230c501 100644 --- a/funcweb/funcweb/widget_validation.py +++ b/funcweb/funcweb/widget_validation.py @@ -195,9 +195,39 @@ class MinionFloatValidator(MinionIntValidator): return float(value) - +################################################################# class MinionListValidator(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 list passed when not_empty is set',value,state) + + + tmp = [] + if type(tmp) != type(value): + value = list(value) + value = [list_value.strip() for list_value in value] + + return value + + def validate_python(self,value,state): + import re + if self.regex_string: + compiled_regex = re.compile(self.regex_string) + for list_value in value: + if not re.match(compiled_regex,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 |