Commit fe56f1c7 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[i18n] properly translate error messages related to violated unicity constraint.

Closes #5100373
parent d7479a5ac553
......@@ -23,7 +23,7 @@ from warnings import warn
from logilab.common.decorators import cachedproperty
from yams import ValidationError as ValidationError
from yams import ValidationError
# abstract exceptions #########################################################
......
......@@ -20,6 +20,7 @@ framework itself.
"""
__docformat__ = "restructuredtext en"
_ = unicode
from itertools import chain
from warnings import warn
......@@ -359,11 +360,13 @@ class IUserFriendlyUniqueTogether(IUserFriendlyError):
__select__ = match_exception(UniqueTogetherError)
def raise_user_exception(self):
_ = self._cw._
rtypes = self.exc.rtypes
rtypes_msg = {}
errors = {}
msgargs = {}
i18nvalues = []
for rtype in rtypes:
rtypes_msg[rtype] = _('%s is part of violated unicity constraint') % rtype
globalmsg = _('some relations violate a unicity constraint')
rtypes_msg['unicity constraint'] = globalmsg
raise ValidationError(self.entity.eid, rtypes_msg)
errors[rtype] = _('%(KEY-rtype)s is part of violated unicity constraint')
msgargs[rtype + '-rtype'] = rtype
i18nvalues.append(rtype + '-rtype')
errors[''] = _('some relations violate a unicity constraint')
raise ValidationError(self.entity.eid, errors, msgargs=msgargs, i18nvalues=i18nvalues)
......@@ -52,9 +52,9 @@ class WorkflowBuildingTC(CubicWebTC):
shell.commit()
with self.assertRaises(ValidationError) as cm:
wf.add_state(u'foo')
self.assertEqual({'name': u'name is part of violated unicity constraint',
'state_of': u'state_of is part of violated unicity constraint',
'unicity constraint': u'some relations violate a unicity constraint'},
self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
'state_of': u'%(KEY-rtype)s is part of violated unicity constraint',
'': u'some relations violate a unicity constraint'},
cm.exception.errors)
shell.rollback()
# no pb if not in the same workflow
......@@ -67,9 +67,9 @@ class WorkflowBuildingTC(CubicWebTC):
with self.assertRaises(ValidationError) as cm:
bar.cw_set(name=u'foo')
shell.rollback()
self.assertEqual({'name': u'name is part of violated unicity constraint',
'state_of': u'state_of is part of violated unicity constraint',
'unicity constraint': u'some relations violate a unicity constraint'},
self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
'state_of': u'%(KEY-rtype)s is part of violated unicity constraint',
'': u'some relations violate a unicity constraint'},
cm.exception.errors)
def test_duplicated_transition(self):
......@@ -80,9 +80,9 @@ class WorkflowBuildingTC(CubicWebTC):
wf.add_transition(u'baz', (foo,), bar, ('managers',))
with self.assertRaises(ValidationError) as cm:
wf.add_transition(u'baz', (bar,), foo)
self.assertEqual({'name': u'name is part of violated unicity constraint',
'transition_of': u'transition_of is part of violated unicity constraint',
'unicity constraint': u'some relations violate a unicity constraint'},
self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
'transition_of': u'%(KEY-rtype)s is part of violated unicity constraint',
'': u'some relations violate a unicity constraint'},
cm.exception.errors)
shell.rollback()
# no pb if not in the same workflow
......@@ -97,9 +97,9 @@ class WorkflowBuildingTC(CubicWebTC):
with self.assertRaises(ValidationError) as cm:
biz.cw_set(name=u'baz')
shell.rollback()
self.assertEqual({'name': u'name is part of violated unicity constraint',
'transition_of': u'transition_of is part of violated unicity constraint',
'unicity constraint': u'some relations violate a unicity constraint'},
self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
'transition_of': u'%(KEY-rtype)s is part of violated unicity constraint',
'': u'some relations violate a unicity constraint'},
cm.exception.errors)
......
......@@ -53,6 +53,10 @@ msgstr ""
msgid "%(KEY-cstr)s constraint failed for value %(KEY-value)r"
msgstr ""
#, python-format
msgid "%(KEY-rtype)s is part of violated unicity constraint"
msgstr ""
#, python-format
msgid "%(KEY-value)r doesn't match the %(KEY-regexp)r regular expression"
msgstr ""
......@@ -113,10 +117,6 @@ msgstr ""
msgid "%s error report"
msgstr "%s Fehlerbericht"
#, python-format
msgid "%s is part of violated unicity constraint"
msgstr ""
#, python-format
msgid "%s software version of the database"
msgstr "Software-Version der Datenbank %s"
......
......@@ -45,6 +45,10 @@ msgstr ""
msgid "%(KEY-cstr)s constraint failed for value %(KEY-value)r"
msgstr ""
#, python-format
msgid "%(KEY-rtype)s is part of violated unicity constraint"
msgstr ""
#, python-format
msgid "%(KEY-value)r doesn't match the %(KEY-regexp)r regular expression"
msgstr ""
......@@ -105,10 +109,6 @@ msgstr ""
msgid "%s error report"
msgstr ""
#, python-format
msgid "%s is part of violated unicity constraint"
msgstr ""
#, python-format
msgid "%s software version of the database"
msgstr ""
......
......@@ -59,6 +59,10 @@ msgstr ""
msgid "%(KEY-cstr)s constraint failed for value %(KEY-value)r"
msgstr "%(KEY-cstr)s restricción errónea para el valor %(KEY-value)r"
#, python-format
msgid "%(KEY-rtype)s is part of violated unicity constraint"
msgstr "%(KEY-rtype)s pertenece a una restricción de unidad no respectada"
#, python-format
msgid "%(KEY-value)r doesn't match the %(KEY-regexp)r regular expression"
msgstr "%(KEY-value)r no corresponde a la expresión regular %(KEY-regexp)r"
......@@ -119,10 +123,6 @@ msgstr "%s podría ser mantenido"
msgid "%s error report"
msgstr "%s reporte de errores"
#, python-format
msgid "%s is part of violated unicity constraint"
msgstr "%s pertenece a una restricción de unidad no respectada"
#, python-format
msgid "%s software version of the database"
msgstr "versión sistema de la base para %s"
......
......@@ -53,6 +53,10 @@ msgstr ""
msgid "%(KEY-cstr)s constraint failed for value %(KEY-value)r"
msgstr "la valeur %(KEY-value)r ne satisfait pas la contrainte %(KEY-cstr)s"
#, python-format
msgid "%(KEY-rtype)s is part of violated unicity constraint"
msgstr "%(KEY-rtype)s appartient à une contrainte d'unicité transgressée"
#, python-format
msgid "%(KEY-value)r doesn't match the %(KEY-regexp)r regular expression"
msgstr ""
......@@ -114,10 +118,6 @@ msgstr "%s pourrait être supporté"
msgid "%s error report"
msgstr "%s rapport d'erreur"
#, python-format
msgid "%s is part of violated unicity constraint"
msgstr "%s appartient à une contrainte d'unicité transgressée"
#, python-format
msgid "%s software version of the database"
msgstr "version logicielle de la base pour %s"
......
......@@ -52,10 +52,10 @@ class RepositoryTC(CubicWebTC):
with self.assertRaises(ValidationError) as wraperr:
cnx.execute('INSERT Societe S: S nom "Logilab", S type "SSLL", S cp "75013"')
self.assertEqual(
{'cp': u'cp is part of violated unicity constraint',
'nom': u'nom is part of violated unicity constraint',
'type': u'type is part of violated unicity constraint',
'unicity constraint': u'some relations violate a unicity constraint'},
{'cp': u'%(KEY-rtype)s is part of violated unicity constraint',
'nom': u'%(KEY-rtype)s is part of violated unicity constraint',
'type': u'%(KEY-rtype)s is part of violated unicity constraint',
'': u'some relations violate a unicity constraint'},
wraperr.exception.args[1])
def test_unique_together_schema(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment