1 # copyright 2010-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2010-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
360 |
360 |
361 class IUserFriendlyUniqueTogether(IUserFriendlyError): |
361 class IUserFriendlyUniqueTogether(IUserFriendlyError): |
362 __select__ = match_exception(UniqueTogetherError) |
362 __select__ = match_exception(UniqueTogetherError) |
363 |
363 |
364 def raise_user_exception(self): |
364 def raise_user_exception(self): |
365 etype, rtypes = self.exc.args |
|
366 # Because of index name size limits (e.g: postgres around 64, |
|
367 # sqlserver around 128), we cannot be sure of what we got, |
|
368 # especially for the rtypes part. |
|
369 # Hence we will try to validate them, and handle invalid ones |
|
370 # in the most user-friendly manner ... |
|
371 _ = self._cw._ |
365 _ = self._cw._ |
372 schema = self.entity._cw.vreg.schema |
366 rtypes = self.exc.rtypes |
373 rtypes_msg = {} |
367 rtypes_msg = {} |
374 for rtype in rtypes: |
368 for rtype in rtypes: |
375 if rtype in schema: |
369 rtypes_msg[rtype] = _('%s is part of violated unicity constraint') % rtype |
376 rtypes_msg[rtype] = _('%s is part of violated unicity constraint') % rtype |
370 globalmsg = _('some relations violate a unicity constraint') |
377 globalmsg = _('some relations %sviolate a unicity constraint') |
|
378 if len(rtypes) != len(rtypes_msg): # we got mangled/missing rtypes |
|
379 globalmsg = globalmsg % _('(not all shown here) ') |
|
380 else: |
|
381 globalmsg = globalmsg % '' |
|
382 rtypes_msg['unicity constraint'] = globalmsg |
371 rtypes_msg['unicity constraint'] = globalmsg |
383 raise ValidationError(self.entity.eid, rtypes_msg) |
372 raise ValidationError(self.entity.eid, rtypes_msg) |
384 |
373 |
385 # deprecated ################################################################### |
374 # deprecated ################################################################### |
386 |
375 |