From c4492f0de8c185da45898865b5c8ca566f01f34f Mon Sep 17 00:00:00 2001 From: makkalot Date: Sat, 21 Jun 2008 10:38:33 +0300 Subject: adding a custom minion list validator will change in the future after choosing the best widget for it --- funcweb/funcweb/widget_validation.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'funcweb') 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 -- cgit