entities/adapters.py
changeset 10301 729f36a1bcfa
parent 10262 5c2a4a0a8dbd
parent 10280 2cdab5e33542
child 10446 1e6655cff5ab
equal deleted inserted replaced
10276:ffb269e60348 10301:729f36a1bcfa
    18 """some basic entity adapter implementations, for interfaces used in the
    18 """some basic entity adapter implementations, for interfaces used in the
    19 framework itself.
    19 framework itself.
    20 """
    20 """
    21 
    21 
    22 __docformat__ = "restructuredtext en"
    22 __docformat__ = "restructuredtext en"
       
    23 _ = unicode
    23 
    24 
    24 from itertools import chain
    25 from itertools import chain
    25 from warnings import warn
    26 from warnings import warn
    26 
    27 
    27 from logilab.mtconverter import TransformError
    28 from logilab.mtconverter import TransformError
   359 
   360 
   360 class IUserFriendlyUniqueTogether(IUserFriendlyError):
   361 class IUserFriendlyUniqueTogether(IUserFriendlyError):
   361     __select__ = match_exception(UniqueTogetherError)
   362     __select__ = match_exception(UniqueTogetherError)
   362 
   363 
   363     def raise_user_exception(self):
   364     def raise_user_exception(self):
   364         _ = self._cw._
       
   365         rtypes = self.exc.rtypes
   365         rtypes = self.exc.rtypes
   366         rtypes_msg = {}
   366         errors = {}
       
   367         msgargs = {}
       
   368         i18nvalues = []
   367         for rtype in rtypes:
   369         for rtype in rtypes:
   368             rtypes_msg[rtype] = _('%s is part of violated unicity constraint') % rtype
   370             errors[rtype] = _('%(KEY-rtype)s is part of violated unicity constraint')
   369         globalmsg = _('some relations violate a unicity constraint')
   371             msgargs[rtype + '-rtype'] = rtype
   370         rtypes_msg['unicity constraint'] = globalmsg
   372             i18nvalues.append(rtype + '-rtype')
   371         raise ValidationError(self.entity.eid, rtypes_msg)
   373         errors[''] = _('some relations violate a unicity constraint')
       
   374         raise ValidationError(self.entity.eid, errors, msgargs=msgargs, i18nvalues=i18nvalues)