summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormakkalot <makkalot@gmail.com>2008-06-20 11:51:20 +0300
committermakkalot <makkalot@gmail.com>2008-06-20 11:51:20 +0300
commit9269e9ac65c42e1d57d34c52755dba97a93f81a6 (patch)
treefd93730012e164fb108d7398750ce13e0a986a86
parent5556eb2c218931dcb6f8c5a004eb9b9902cc10e8 (diff)
downloadfunc-9269e9ac65c42e1d57d34c52755dba97a93f81a6.tar.gz
func-9269e9ac65c42e1d57d34c52755dba97a93f81a6.tar.xz
func-9269e9ac65c42e1d57d34c52755dba97a93f81a6.zip
Adding a new custom validator for our int field didnt use turbogears cause it doesnt accept min max thingy
-rw-r--r--funcweb/funcweb/widget_validation.py45
1 files changed, 45 insertions, 0 deletions
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__":