From d49ad30e1161d94d9c8ea23a974b468a55ab33e2 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Thu, 18 Oct 2018 10:42:24 -0300 Subject: [PATCH 1/2] Usa buffer inteiro p python-magic ao exportar do zope --- sapl/legacy/scripts/exporta_zope/exporta_zope.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sapl/legacy/scripts/exporta_zope/exporta_zope.py b/sapl/legacy/scripts/exporta_zope/exporta_zope.py index 682296f4b..bec8595cf 100755 --- a/sapl/legacy/scripts/exporta_zope/exporta_zope.py +++ b/sapl/legacy/scripts/exporta_zope/exporta_zope.py @@ -93,7 +93,7 @@ def br(obj): def guess_extension(fullname, buffer): # um corte de apenas 1024 impediu a detecção correta de .docx - mime = magic.from_buffer(buffer[:4096], mime=True) + mime = magic.from_buffer(buffer, mime=True) extensao = EXTENSOES.get(mime) if extensao is not None: return extensao From b23faf71f4ce4bcac9ffc16bb8f8e2b4a3348b16 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Wed, 28 Nov 2018 12:17:24 -0200 Subject: [PATCH 2/2] Reaponta docs para existentes em media --- sapl/legacy/migracao_documentos.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/sapl/legacy/migracao_documentos.py b/sapl/legacy/migracao_documentos.py index 2c9e00842..23c6f05f7 100644 --- a/sapl/legacy/migracao_documentos.py +++ b/sapl/legacy/migracao_documentos.py @@ -1,6 +1,6 @@ import os -import shutil import re +import shutil from glob import glob from os.path import join @@ -189,3 +189,27 @@ def migrar_documentos(repo): print('\n#### Encerrado ####\n\n' '{} documentos sobraram sem ser migrados!!!'.format( len(sobrando))) + + +def corrigir_documentos_para_existentes(repo): + + for model, campos_bases in DOCS.items(): + if model == Parlamentar: + continue + for campo, base_origem in campos_bases: + print('#### Corrigindo {} de {} ####'.format(campo, + model.__name__)) + upload_to = model._meta.get_field(campo).upload_to + for obj in model.objects.all(): + if getattr(obj, campo): + continue + dir_upload_to = os.path.join( + repo.working_dir, upload_to(obj, '')) + achados = glob(dir_upload_to + '*') + if achados: + assert len(achados) == 1, 'Mais de um doc achado' + [achado] = achados + destino = upload_to(obj, os.path.basename(achado)) + print('-- {}'.format(destino)) + setattr(obj, campo, destino) + obj.save()