Skip to content

Loading…

Add capability to check min or max values #8

Merged
merged 1 commit into from

2 participants

@nikitinsm

No description provided.

@doncatnip doncatnip merged commit 24e76ce into doncatnip:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 23, 2012
  1. @nikitinsm
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 0 deletions.
  1. +30 −0 src/kanone/validator/check.py
View
30 src/kanone/validator/check.py
@@ -178,3 +178,33 @@ def on_value(self, context, value):
return value
+
+@messages\
+ ( fail="Value must lower or equal to %(max)s"
+ )
+class Max( Validator ):
+
+ def setParameters( self, max ):
+ self.max = max
+
+ def on_value(self, context, value):
+ if value > self.max:
+ raise Invalid( value, self, max=self.max )
+
+ return value
+
+
+
+@messages\
+ ( fail="Value must greater or equal to %(min)s"
+ )
+class Min( Validator ):
+
+ def setParameters( self, min ):
+ self.min = min
+
+ def on_value(self, context, value):
+ if value < self.min:
+ raise Invalid( value, self, min=self.min )
+
+ return value
Something went wrong with that request. Please try again.