From 3c5a33805a0b23b8f64e93c833a1fc4613661f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Rodrigues?= Date: Wed, 9 Oct 2019 11:14:00 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20#2691=20-=20Exclus=C3=A3o=20de=20Arquivos?= =?UTF-8?q?=20(#3003)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix #2961 - AudienciaPublica * Fix #2961 - AnexoAudienciaPublica * Fix #2961 - Reuniao * Fix #2961 - DocumentoAcessorio * Fix #2961 - MateriaLegislativa * Fix #2961 - DocumentoAcessorio (sapl/materia) * Fix #2961 - Proposicao * Fix #2961 - NormaJuridica * Fix #2961 - AnexoNormaJuridica * Fix #2961 - DocumentoAdministrativo * Fix #2961 - DocumentoAcessorioAdministrativo * Fix #2961 - SessaoPlenaria * Fix #2961 - AbstractOrador * Fix #2961 - JustificativaAusencia --- sapl/audiencia/models.py | 30 +++++++++++++++++----------- sapl/comissoes/models.py | 31 +++++++++++++++++------------ sapl/materia/models.py | 30 ++++++++++++++++------------ sapl/norma/models.py | 21 +++++++++++++++----- sapl/protocoloadm/models.py | 20 +++++++++++-------- sapl/sessao/models.py | 39 +++++++++++++++++++++++++------------ 6 files changed, 111 insertions(+), 60 deletions(-) diff --git a/sapl/audiencia/models.py b/sapl/audiencia/models.py index 64d92e2c9..22a1accc9 100755 --- a/sapl/audiencia/models.py +++ b/sapl/audiencia/models.py @@ -119,17 +119,22 @@ class AudienciaPublica(models.Model): return self.nome def delete(self, using=None, keep_parents=False): - if self.upload_pauta: - self.upload_pauta.delete() + upload_pauta = self.upload_pauta + upload_ata = self.upload_ata + upload_anexo = self.upload_anexo - if self.upload_ata: - self.upload_ata.delete() + result = super().delete(using=using, keep_parents=keep_parents) - if self.upload_anexo: - self.upload_anexo.delete() + if upload_pauta: + upload_pauta.delete(save=False) - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + if upload_ata: + upload_ata.delete(save=False) + + if upload_anexo: + upload_anexo.delete(save=False) + + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): @@ -179,10 +184,13 @@ class AnexoAudienciaPublica(models.Model): return self.assunto def delete(self, using=None, keep_parents=False): - if self.arquivo: - self.arquivo.delete() + arquivo = self.arquivo + result = super().delete(using=using, keep_parents=keep_parents) + + if arquivo: + arquivo.delete(save=False) - return models.Model.delete(self, using=using, keep_parents=keep_parents) + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): if not self.pk and self.arquivo: diff --git a/sapl/comissoes/models.py b/sapl/comissoes/models.py index aabde6f73..bf876b5ef 100644 --- a/sapl/comissoes/models.py +++ b/sapl/comissoes/models.py @@ -264,17 +264,22 @@ class Reuniao(models.Model): return self.nome def delete(self, using=None, keep_parents=False): - if self.upload_pauta: - self.upload_pauta.delete() + upload_pauta = self.upload_pauta + upload_ata = self.upload_ata + upload_anexo = self.upload_anexo - if self.upload_ata: - self.upload_ata.delete() + result = super().delete(using=using, keep_parents=keep_parents) - if self.upload_anexo: - self.upload_anexo.delete() + if upload_pauta: + upload_pauta.delete(save=False) - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + if upload_ata: + upload_ata.delete(save=False) + + if upload_anexo: + upload_anexo.delete(save=False) + + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): @@ -339,11 +344,13 @@ class DocumentoAcessorio(models.Model): 'autor': self.autor} def delete(self, using=None, keep_parents=False): - if self.arquivo: - self.arquivo.delete() + arquivo = self.arquivo + result = super().delete(using=using, keep_parents=keep_parents) + + if arquivo: + arquivo.delete(save=False) - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): diff --git a/sapl/materia/models.py b/sapl/materia/models.py index 3fe070b81..f5425363a 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -338,16 +338,18 @@ class MateriaLegislativa(models.Model): return '' def delete(self, using=None, keep_parents=False): - if self.texto_original: - self.texto_original.delete() + texto_original = self.texto_original + result = super().delete(using=using, keep_parents=keep_parents) + + if texto_original: + texto_original.delete(save=False) for p in self.proposicao.all(): p.conteudo_gerado_related = None p.cancelado = True p.save() - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): @@ -566,15 +568,17 @@ class DocumentoAcessorio(models.Model): 'autor': self.autor} def delete(self, using=None, keep_parents=False): - if self.arquivo: - self.arquivo.delete() + arquivo = self.arquivo + result = super().delete(using=using, keep_parents=keep_parents) + + if arquivo: + arquivo.delete(save=False) for p in self.proposicao.all(): p.conteudo_gerado_related = None p.save() - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): @@ -910,11 +914,13 @@ class Proposicao(models.Model): )} def delete(self, using=None, keep_parents=False): - if self.texto_original: - self.texto_original.delete() + texto_original = self.texto_original + result = super().delete(using=using, keep_parents=keep_parents) + + if texto_original: + texto_original.delete(save=False) - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): diff --git a/sapl/norma/models.py b/sapl/norma/models.py index aa8873814..05f0bbc5a 100644 --- a/sapl/norma/models.py +++ b/sapl/norma/models.py @@ -190,11 +190,13 @@ class NormaJuridica(models.Model): 'data': defaultfilters.date(self.data, "d \d\e F \d\e Y")} def delete(self, using=None, keep_parents=False): - if self.texto_integral: - self.texto_integral.delete() + texto_integral = self.texto_integral + result = super().delete(using=using, keep_parents=keep_parents) - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + if texto_integral: + texto_integral.delete(save=False) + + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): @@ -388,4 +390,13 @@ class AnexoNormaJuridica(models.Model): return models.Model.save(self, force_insert=force_insert, force_update=force_update, using=using, - update_fields=update_fields) \ No newline at end of file + update_fields=update_fields) + + def delete(self, using=None, keep_parents=False): + anexo_arquivo = self.anexo_arquivo + result = super().delete(using=using, keep_parents=keep_parents) + + if anexo_arquivo: + anexo_arquivo.delete(save=False) + + return result diff --git a/sapl/protocoloadm/models.py b/sapl/protocoloadm/models.py index f45e263d4..e4fa79a55 100644 --- a/sapl/protocoloadm/models.py +++ b/sapl/protocoloadm/models.py @@ -196,11 +196,13 @@ class DocumentoAdministrativo(models.Model): } def delete(self, using=None, keep_parents=False): - if self.texto_integral: - self.texto_integral.delete() + texto_integral = self.texto_integral + result = super().delete(using=using, keep_parents=keep_parents) - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + if texto_integral: + texto_integral.delete(save=False) + + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): @@ -251,11 +253,13 @@ class DocumentoAcessorioAdministrativo(models.Model): return self.nome def delete(self, using=None, keep_parents=False): - if self.arquivo: - self.arquivo.delete() + arquivo = self.arquivo + result = super().delete(using=using, keep_parents=keep_parents) + + if arquivo: + arquivo.delete(save=False) - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index e630eb37f..2856a0602 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -262,17 +262,22 @@ class SessaoPlenaria(models.Model): """ def delete(self, using=None, keep_parents=False): - if self.upload_pauta: - self.upload_pauta.delete() + upload_pauta = self.upload_pauta + upload_ata = self.upload_ata + upload_anexo = self.upload_anexo + + result = super().delete(using=using, keep_parents=keep_parents) - if self.upload_ata: - self.upload_ata.delete() + if upload_pauta: + upload_pauta.delete(save=False) - if self.upload_anexo: - self.upload_anexo.delete() + if upload_ata: + upload_ata.delete(save=False) - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + if upload_anexo: + upload_anexo.delete(save=False) + + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None): @@ -445,6 +450,14 @@ class AbstractOrador(models.Model): # Oradores 'nome': self.parlamentar, 'numero': self.numero_ordem} + def delete(self, using=None, keep_parents=False): + upload_anexo = self.upload_anexo + result = super().delete(using=using, keep_parents=keep_parents) + + if upload_anexo: + upload_anexo.delete(save=False) + + return result @reversion.register() class Orador(AbstractOrador): # Oradores @@ -789,11 +802,13 @@ class JustificativaAusencia(models.Model): return 'Justificativa de AusĂȘncia' def delete(self, using=None, keep_parents=False): - if self.upload_anexo: - self.upload_anexo.delete() + upload_anexo = self.upload_anexo + result = super().delete(using=using, keep_parents=keep_parents) + + if upload_anexo: + upload_anexo.delete(save=False) - return models.Model.delete( - self, using=using, keep_parents=keep_parents) + return result def save(self, force_insert=False, force_update=False, using=None, update_fields=None):