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

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Mon Jun 11 11:25:21 CEST 2012


Author: bricks
Date: 2012-06-11 11:25:21 +0200 (Mon, 11 Jun 2012)
New Revision: 5977

Modified:
   base/trunk/mpulsweb/lib/validators.py
Log:
Don't use translated strings in class variables

Don't use translated strings (marked with _()) in class variables.
If a validator class is used in a non request bases object e.g. in
app_globals, case, ... it will fail because the pylons translation
object is not registered yet. By using a translated string in a
object method this is avoided.


Modified: base/trunk/mpulsweb/lib/validators.py
===================================================================
--- base/trunk/mpulsweb/lib/validators.py	2012-06-07 07:14:11 UTC (rev 5976)
+++ base/trunk/mpulsweb/lib/validators.py	2012-06-11 09:25:21 UTC (rev 5977)
@@ -11,7 +11,6 @@
      FileUploadKeeper, OneOf, Wrapper, Regex
 
 from mpulsweb.lib.translation import _
-
 from mpulsweb.lib.db import db
 from mpulsweb.lib.helpers import format_date
 from mpulsweb.lib.base import session
@@ -88,11 +87,6 @@
     validate_partial_form = True
     __unpackargs__ = ('*', 'field_names')
 
-    messages = {
-        'fileexists': _("Es existiert bereits eine Datei mit dem Namen"),
-        'notDict': _("Fields should be a dictionary"),
-        }
-
     def __init__(self, *args, **kw):
         super(FormValidator, self).__init__(*args, **kw)
         if len(self.field_names) < 2:
@@ -109,7 +103,7 @@
             ref = field_dict[self.field_names[0]]
         except TypeError:
             # Generally because field_dict isn't a dict
-            raise Invalid(self.message('notDict', state), field_dict, state)
+            raise Invalid(_("Fields should be a dictionary"), field_dict, state)
         except KeyError:
             ref = ''
 
@@ -152,7 +146,8 @@
                 result = cur.fetchall()
                 for r in result:
                     if int(r[0]) != id:
-                        errors['name'] = self.message('fileexists', state)
+                        errors['name'] = _("Es existiert bereits eine Datei mit"
+                                           "dem Namen")
             except Exception, e:
                 log.exception(e)
                 raise
@@ -179,11 +174,6 @@
     validate_partial_form = False # do not run is a prior test failed
     __unpackargs__ = ('*', 'field_names')
 
-    messages = {
-        'notbefore': _("Startdatum muss vor oder gleich dem Enddatum liegen"),
-        'notDict': _("Fields should be a dictionary"),
-        }
-
     def __init__(self, *args, **kw):
         super(FormValidator, self).__init__(*args, **kw)
         if len(self.field_names) < 2:
@@ -210,7 +200,7 @@
             ref = field_dict[self.field_names[0]]
         except TypeError:
             # Generally because field_dict isn't a dict
-            raise Invalid(self.message('notDict', state), field_dict, state)
+            raise Invalid(_("Fields should be a dictionary"), field_dict, state)
         except KeyError:
             ref = ''
         errors = {}
@@ -221,7 +211,8 @@
             if field == '':
                 field = ref
             if field and ref and field < ref:
-                errors[name] = self.message('notbefore', state)
+                errors[name] = _("Startdatum muss vor oder gleich dem "
+                                 "Enddatum liegen")
         if errors:
             error_list = errors.items()
             error_list.sort()
@@ -268,11 +259,6 @@
     __unpackargs__ = ('*', 'field_names')
     days = None
 
-    messages = {
-        'toomuchdays': _(u"The dates must be at most %(value)s Days apart."),
-        'notDict': _("Fields should be a dictionary"),
-        }
-
     def __init__(self, *args, **kw):
         super(FormValidator, self).__init__(*args, **kw)
         if len(self.field_names) < 2:
@@ -294,7 +280,7 @@
             end = field_dict[self.field_names[1]]
         except TypeError:
             # Generally because field_dict isn't a dict
-            raise Invalid(self.message('notDict', state), field_dict, state)
+            raise Invalid(_("Fields should be a dictionary"), field_dict, state)
         except KeyError:
             ref = ''
         errors = {}
@@ -303,10 +289,10 @@
         td = end - begin
         if self.days:
             if td.days > self.days:
-                errors[self.field_names[0]] = self.message('toomuchdays', state,
-                                                           value=self.days)
-                errors[self.field_names[1]] = self.message('toomuchdays', state,
-                                                           value=self.days)
+                errors[self.field_names[0]] = _(u"The dates must be at most "
+                                                "%s Days apart.") % self.days)
+                errors[self.field_names[1]] = _(u"The dates must be at most "
+                                                "%s Days apart.") % self.days)
         if errors:
             error_list = errors.items()
             error_list.sort()



More information about the Mpuls-commits mailing list