Improve integrity error message

bzr revid: rga@rga-desktop-20100519131536-s82lok98qtrvu2ab
This commit is contained in:
rga 2010-05-19 18:45:36 +05:30
parent 321c9415ab
commit 8e08985eea
1 changed files with 10 additions and 1 deletions

View File

@ -65,7 +65,16 @@ class osv_pool(netsvc.Service):
for key in self._sql_error.keys():
if key in inst[0]:
self.abortResponse(1, 'Constraint Error', 'warning', self._sql_error[key])
self.abortResponse(1, 'Integrity Error', 'warning', inst[0])
if inst.pgcode == "23502":
context = inst.pgerror.split('"public".')[1]
table = context.split('"')[1]
model = table.replace("_",".")
if not self.obj_pool.get(model,False):
model = table
msg = 'You can not delete current record because it refered by ' + model
self.abortResponse(1, 'Integrity Error', 'warning', msg)
else:
self.abortResponse(1, 'Integrity Error', 'warning', inst[0])
except Exception, e:
self.logger.exception("Uncaught exception")
raise