[sources] Stop translating validation error 3.25
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 12 Apr 2017 15:38:32 +0200
branch3.25
changeset 12149 649100470733
parent 12148 79160d54662e
child 12150 6260c88e0ff5
[sources] Stop translating validation error this should be done later in the web ui, where lang is properly set.
cubicweb/server/sources/__init__.py
cubicweb/server/sources/datafeed.py
cubicweb/server/sources/native.py
--- a/cubicweb/server/sources/__init__.py	Wed Apr 12 15:49:05 2017 +0200
+++ b/cubicweb/server/sources/__init__.py	Wed Apr 12 15:38:32 2017 +0200
@@ -29,7 +29,7 @@
 
 from yams.schema import role_name
 
-from cubicweb import ValidationError, set_log_methods, server
+from cubicweb import ValidationError, set_log_methods, server, _
 from cubicweb.server import SOURCE_TYPES
 
 
@@ -133,7 +133,7 @@
         pass
 
     @classmethod
-    def check_conf_dict(cls, eid, confdict, _=text_type, fail_if_unknown=True):
+    def check_conf_dict(cls, eid, confdict, fail_if_unknown=True):
         """check configuration of source entity. Return config dict properly
         typed with defaults set.
         """
@@ -143,14 +143,15 @@
             if value is configuration.REQUIRED:
                 if not fail_if_unknown:
                     continue
-                msg = _('specifying %s is mandatory' % optname)
-                raise ValidationError(eid, {role_name('config', 'subject'): msg})
+                msg = _('specifying %s is mandatory')
+                msgargs = optname
+                raise ValidationError(eid, {role_name('config', 'subject'): msg}, msgargs)
             elif value is not None:
                 # type check
                 try:
                     value = configuration._validate(value, optdict, optname)
                 except Exception as ex:
-                    msg = text_type(ex) # XXX internationalization
+                    msg = text_type(ex)
                     raise ValidationError(eid, {role_name('config', 'subject'): msg})
             processed[optname] = value
         # cw < 3.10 bw compat
@@ -161,8 +162,9 @@
         # check for unknown options
         if confdict and tuple(confdict) != ('adapter',):
             if fail_if_unknown:
-                msg = _('unknown options %s') % ', '.join(confdict)
-                raise ValidationError(eid, {role_name('config', 'subject'): msg})
+                msg = _('unknown options %s')
+                msgargs = ', '.join(confdict)
+                raise ValidationError(eid, {role_name('config', 'subject'): msg}, msgargs)
             else:
                 logger = getLogger('cubicweb.sources')
                 logger.warning('unknown options %s', ', '.join(confdict))
@@ -173,8 +175,7 @@
     @classmethod
     def check_config(cls, source_entity):
         """check configuration of source entity"""
-        return cls.check_conf_dict(source_entity.eid, source_entity.host_config,
-                                    _=source_entity._cw._)
+        return cls.check_conf_dict(source_entity.eid, source_entity.dictconfig)
 
     # source initialization / finalization #####################################
 
--- a/cubicweb/server/sources/datafeed.py	Wed Apr 12 15:49:05 2017 +0200
+++ b/cubicweb/server/sources/datafeed.py	Wed Apr 12 15:38:32 2017 +0200
@@ -34,7 +34,7 @@
 
 from logilab.common.deprecation import deprecated
 
-from cubicweb import ObjectNotFound, ValidationError, SourceException
+from cubicweb import ObjectNotFound, ValidationError, SourceException, _
 from cubicweb.server.sources import AbstractSource
 from cubicweb.appobject import AppObject
 
@@ -102,7 +102,6 @@
         """check configuration of source entity"""
         typed_config = super(DataFeedSource, self).check_config(source_entity)
         if typed_config['synchronization-interval'] < 60:
-            _ = source_entity._cw._
             msg = _('synchronization-interval must be greater than 1 minute')
             raise ValidationError(source_entity.eid, {'config': msg})
         return typed_config
--- a/cubicweb/server/sources/native.py	Wed Apr 12 15:49:05 2017 +0200
+++ b/cubicweb/server/sources/native.py	Wed Apr 12 15:38:32 2017 +0200
@@ -41,7 +41,7 @@
 
 from cubicweb import (UnknownEid, AuthenticationError, ValidationError, Binary,
                       UniqueTogetherError, UndoTransactionException, ViolatedConstraint)
-from cubicweb import transaction as tx, server, neg_role
+from cubicweb import transaction as tx, server, neg_role, _
 from cubicweb.utils import QueryCache
 from cubicweb.schema import VIRTUAL_RTYPES
 from cubicweb.cwconfig import CubicWebNoAppConfiguration
@@ -352,8 +352,8 @@
     def check_config(self, source_entity):
         """check configuration of source entity"""
         if source_entity.host_config:
-            msg = source_entity._cw._('the system source has its configuration '
-                                      'stored on the file-system')
+            msg = _('the system source has its configuration '
+                    'stored on the file-system')
             raise ValidationError(source_entity.eid, {role_name('config', 'subject'): msg})
 
     def add_authentifier(self, authentifier):