From 95227452ba4fcbe1f10eed0cfa1e33e33ddd764a Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Thu, 30 Mar 2017 14:41:32 -0300 Subject: [PATCH] Substitui tela amarela por mensagem de erro ao remover campo referenciado. --- sapl/crud/base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sapl/crud/base.py b/sapl/crud/base.py index b70e7a54a..f33d610d5 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -840,6 +840,22 @@ class CrudDeleteView(PermissionRequiredContainerCrudMixin, def get_success_url(self): return self.list_url + def delete(self, request, *args, **kwargs): + try: + super(CrudDeleteView, self).delete(request, args, kwargs) + except models.ProtectedError as err: + error_msg = 'Registro não pode ser removido, pois\ + é referenciado por outros registros:
\ + ' + + messages.add_message(request, + messages.ERROR, + error_msg) + return self.render_to_response(self.get_context_data()) + class Crud: BaseMixin = CrudBaseMixin