[Mpuls-commits] r1404 - wasko/branches/2.0/mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Feb 9 16:16:32 CET 2010


Author: torsten
Date: 2010-02-09 16:16:32 +0100 (Tue, 09 Feb 2010)
New Revision: 1404

Modified:
   wasko/branches/2.0/mpulsweb/lib/validators.py
Log:
* mpulsweb/lib/validators.py (MaxMinInt),(EditSettingsForm): New moved from
  waskaweb.valiadtors



Modified: wasko/branches/2.0/mpulsweb/lib/validators.py
===================================================================
--- wasko/branches/2.0/mpulsweb/lib/validators.py	2010-02-09 15:15:35 UTC (rev 1403)
+++ wasko/branches/2.0/mpulsweb/lib/validators.py	2010-02-09 15:16:32 UTC (rev 1404)
@@ -94,7 +94,58 @@
         except StandardError, err:
             print "Fehler beim Validieren des Gruppennamens: %s" % err
 
+class MaxMinInt(formencode.validators.FancyValidator):
 
+    """
+    Convert a value to an integer.
+
+    Example::
+
+        >>> Int.to_python('10')
+        10
+        >>> Int.to_python('ten')
+        Traceback (most recent call last):
+            ...
+        Invalid: Please enter an integer value
+    """
+
+    messages = {
+        'integer': u"Bitte geben Sie einen Ganzzahlenwert ein.",
+        'tooLow': u"Bitte geben Sie einen Wert größer oder gleich  %(min)i ein.",
+        'tooHigh': u"Bitte geben Sie einen Wert kleiner oder gleich %(max)i ein."
+        }
+
+    min = None
+    max = None
+
+    def __initargs__(self, args):
+        if self.min != None:
+            self.min = int(self.min)
+        if self.max != None:
+            self.max = int(self.max)
+
+
+    def _to_python(self, value, state):
+        try:
+            return int(value)
+        except (ValueError, TypeError):
+            raise formencode.Invalid(self.message('integer', state),
+                          value, state)
+
+    def validate_python(self, value, state):
+        if self.min != None and value < self.min:
+            msg = self.message("tooLow", state, min=self.min)
+            raise formencode.Invalid(msg, value, state)
+        if self.max != None and value > self.max:
+            msg = self.message("tooHigh", state, max=self.max)
+            raise formencode.Invalid(msg, value, state)
+
+    _from_python = _to_python
+
+class EditSettingsForm(BaseFormValidator):
+    anon_transfer = formencode.validators.String(if_missing='off')
+    max_speicherdauer = MaxMinInt(min=7, max=180, not_empty=True)
+
 class NewPasswordForm(BaseFormValidator):
     passwd = SecurePassword()  
     passwd2 = formencode.validators.String() 



More information about the Mpuls-commits mailing list