From 9269e9ac65c42e1d57d34c52755dba97a93f81a6 Mon Sep 17 00:00:00 2001 From: makkalot Date: Fri, 20 Jun 2008 11:51:20 +0300 Subject: Adding a new custom validator for our int field didnt use turbogears cause it doesnt accept min max thingy --- funcweb/funcweb/widget_validation.py | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'funcweb') diff --git a/funcweb/funcweb/widget_validation.py b/funcweb/funcweb/widget_validation.py index 6a1c010..10fd177 100644 --- a/funcweb/funcweb/widget_validation.py +++ b/funcweb/funcweb/widget_validation.py @@ -108,7 +108,52 @@ class WidgetSchemaFactory(object): return final_schema +######################################################################## +class MinionIntValidator(validators.FancyValidator): + """ + Confirms that the input/output is of the proper type. + + Uses the parameters: + + subclass: + The class or a tuple of classes; the item must be an instance + of the class or a subclass. + type: + A type or tuple of types (or classes); the item must be of + the exact class or type. Subclasses are not allowed. + + """ + #automatically will be assigned + min_int = None + max_int = None + + def validate_python(self,value,state): + """ + The actual validator + """ + try: + value = int(value) + except (ValueError, TypeError): + raise validators.Invalid('The field should be integer',value,state) + #firstly run the supers one + if self.min_int and int(self.min_int): + if value < int(self.min_int): + raise validators.Invalid('The integer you entered should be bigger that %d'%(self.min_int),value,state) + + if self.max_int and int(self.max_int): + if value > int(self.max_int): + raise validators.Invalid('The integer you entered exceeds the %d'%(self.max_int),value,state) + +################################################################## +class MinionFloatValidator(validators.FancyValidator): + pass + +class MinionListValidator(validators.FancyValidator): + pass + +class MinionHashValidator(validators.FancyValidator): + pass if __name__ == "__main__": -- cgit