entities/adapters.py
changeset 10280 2cdab5e33542
parent 9918 228c3571e222
child 10301 729f36a1bcfa
equal deleted inserted replaced
10279:d7479a5ac553 10280:2cdab5e33542
    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
   357 
   358 
   358 class IUserFriendlyUniqueTogether(IUserFriendlyError):
   359 class IUserFriendlyUniqueTogether(IUserFriendlyError):
   359     __select__ = match_exception(UniqueTogetherError)
   360     __select__ = match_exception(UniqueTogetherError)
   360 
   361 
   361     def raise_user_exception(self):
   362     def raise_user_exception(self):
   362         _ = self._cw._
       
   363         rtypes = self.exc.rtypes
   363         rtypes = self.exc.rtypes
   364         rtypes_msg = {}
   364         errors = {}
       
   365         msgargs = {}
       
   366         i18nvalues = []
   365         for rtype in rtypes:
   367         for rtype in rtypes:
   366             rtypes_msg[rtype] = _('%s is part of violated unicity constraint') % rtype
   368             errors[rtype] = _('%(KEY-rtype)s is part of violated unicity constraint')
   367         globalmsg = _('some relations violate a unicity constraint')
   369             msgargs[rtype + '-rtype'] = rtype
   368         rtypes_msg['unicity constraint'] = globalmsg
   370             i18nvalues.append(rtype + '-rtype')
   369         raise ValidationError(self.entity.eid, rtypes_msg)
   371         errors[''] = _('some relations violate a unicity constraint')
       
   372         raise ValidationError(self.entity.eid, errors, msgargs=msgargs, i18nvalues=i18nvalues)