[Mpuls-commits] r2832 - base/trunk/mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon May 31 12:05:17 CEST 2010


Author: torsten
Date: 2010-05-31 12:05:15 +0200 (Mon, 31 May 2010)
New Revision: 2832

Modified:
   base/trunk/mpulsweb/lib/validators.py
Log:
mpulsweb/lib/validators.py (DateOrder.validate_python): Fixed DateOrder validator.



Modified: base/trunk/mpulsweb/lib/validators.py
===================================================================
--- base/trunk/mpulsweb/lib/validators.py	2010-05-31 10:05:04 UTC (rev 2831)
+++ base/trunk/mpulsweb/lib/validators.py	2010-05-31 10:05:15 UTC (rev 2832)
@@ -14,8 +14,10 @@
 from pylons.i18n import _
 
 from mpulsweb.lib.db import db
+from mpulsweb.lib.helpers import format_date 
 
 
+
 log = logging.getLogger(__name__)
 
 
@@ -151,7 +153,7 @@
     """
 
     field_names = None
-    validate_partial_form = True
+    validate_partial_form = False # do not run is a prior test failed 
     __unpackargs__ = ('*', 'field_names')
 
     messages = {
@@ -170,6 +172,16 @@
                 return
         self.validate_python(field_dict, state)
 
+    def conv_dates(self, dict):
+        # Dates are already converted to datetime objects here. as we want
+        # german representation in error messages convert the values back to
+        # german format
+        for key, value in dict.iteritems():
+            if isinstance(value, datetime.date):
+                value = format_date(value) 
+                dict[key] = value
+        return dict
+
     def validate_python(self, field_dict, state):
         try:
             ref = field_dict[self.field_names[0]]
@@ -180,17 +192,19 @@
             ref = ''
         errors = {}
         for name in self.field_names[1:]:
-            log.debug(ref)
-            log.debug(field_dict.get(name, ''))
-            mydate = field_dict.get(name)
-            if mydate and mydate < ref:
+            field = field_dict.get(name)
+            # if date was given take ref date to fullfill requirement of the
+            # chained validator
+            if field == '':
+                field = ref
+            if field and field < ref:
                 errors[name] = self.message('notbefore', state)
         if errors:
             error_list = errors.items()
             error_list.sort()
             error_message = '<br>\n'.join(['%s: %s' % (name, value)
                                            for name, value in error_list])
-            raise formencode.Invalid(error_message, field_dict, state,
+            raise formencode.Invalid(error_message, self.conv_dates(field_dict), state,
                                      error_dict=errors)
 
 
@@ -506,7 +520,7 @@
 class CreateAppointmentForm(BaseFormValidator):
 
     start_date = MyDateConverter(not_empty=True, month_style='dd.mm.jjjj')
-    start_time = TimeConverter(not_empty=True, use_datetime=True)
+    start_time = TimeConverter(if_empty="00:00", use_datetime=True)
 
     end_date = MyDateConverter(month_style='dd.mm.jjjj')
     end_time = TimeConverter(use_datetime=True)



More information about the Mpuls-commits mailing list