From cf2f461b3fbf1bf060022b7594875e4fae8e72b1 Mon Sep 17 00:00:00 2001 From: ulyssesBML Date: Tue, 7 Jul 2020 13:07:08 -0300 Subject: [PATCH] =?UTF-8?q?HOT-FIX=20-=20Subindo=20script=20para=20criar?= =?UTF-8?q?=20hash=20de=20recebimento=20de=20proposi=C3=A7=C3=A3o=20sem=20?= =?UTF-8?q?recibo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/views.py | 4 ++-- scripts/gerar_hash_proposicoes.py | 35 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 scripts/gerar_hash_proposicoes.py diff --git a/sapl/base/views.py b/sapl/base/views.py index 56e8879e1..6a29eb5d1 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -2084,17 +2084,17 @@ class AppConfigCrud(CrudAux): return super().form_valid(form) def gerar_hash(self, inst): - inst.save() if inst.texto_original: try: inst.hash_code = gerar_hash_arquivo( inst.texto_original.path, str(inst.pk)) + inst.save() except IOError: raise ValidationError("Existem proposicoes com arquivos inexistentes.") elif inst.texto_articulado.exists(): ta = inst.texto_articulado.first() inst.hash_code = 'P' + ta.hash() + SEPARADOR_HASH_PROPOSICAO + str(inst.pk) - inst.save() + inst.save() class CreateView(CrudAux.CreateView): diff --git a/scripts/gerar_hash_proposicoes.py b/scripts/gerar_hash_proposicoes.py new file mode 100644 index 000000000..0591ec60f --- /dev/null +++ b/scripts/gerar_hash_proposicoes.py @@ -0,0 +1,35 @@ +# Gerar hash de proposições para recebimento sem recibo +from sapl.materia.models import Proposicao +from sapl.utils import gerar_hash_arquivo, SEPARADOR_HASH_PROPOSICAO +from datetime import datetime + +def gerar_hash(proposicao): + if proposicao.texto_original: + try: + proposicao.hash_code = gerar_hash_arquivo( + proposicao.texto_original.path, str(proposicao.pk)) + except IOError: + raise Exception("Existem proposicoes com arquivos inexistentes.") + elif proposicao.texto_articulado.exists(): + ta = proposicao.texto_articulado.first() + proposicao.hash_code = 'P' + ta.hash() + SEPARADOR_HASH_PROPOSICAO + str(proposicao.pk) + print(proposicao.hash_code) + proposicao.save() + + +def gerar_hash_proposicoes(): + di = datetime.now() + print(di) + props = Proposicao.objects.filter(hash_code='').exclude(data_envio__isnull=True) + print("Total de proposicoes: %s" % props.count()) + for prop in props: + try: + print(".",end="") + gerar_hash(prop) + except Exception as e: + print('Erro para proposicao', prop) + print(e) + + elapsed = datetime.now() - di + print("\n {}s".format(elapsed.seconds)) +