|
|
@@ -15,6 +15,7 @@ from random import randint
|
|
|
import csv
|
|
|
import time
|
|
|
import datetime
|
|
|
+import zipfile
|
|
|
|
|
|
#pip install python-codicefiscale
|
|
|
from codicefiscale import codicefiscale
|
|
|
@@ -92,7 +93,7 @@ def upload_file(uploaded_file,utente,originale=False):
|
|
|
print(os.path.join(fl_path,utente.azienda.partitaiva),"esistente")
|
|
|
try:
|
|
|
os.mkdir(os.path.join(fl_path,utente.azienda.partitaiva,utente.codicefiscale))
|
|
|
- except FileExistsError as fee:
|
|
|
+ except fileexistserror as fee:
|
|
|
print(os.path.join(fl_path,utente.azienda.partitaiva,utente.codicefiscale),"esistente")
|
|
|
|
|
|
with open(os.path.join(fl_path,utente.azienda.partitaiva,utente.codicefiscale,nomefile),'wb+') as d:
|
|
|
@@ -262,3 +263,25 @@ def save_and_load_file_indice(request,fileindice,azienda=None,sede=None):
|
|
|
|
|
|
utente.pin = str(randint(100000,999999))
|
|
|
utente.save()
|
|
|
+
|
|
|
+def PrepareZipFile(listafile=[]):
|
|
|
+ zip_path = os.path.join(settings.BASE_DIR,getConfig('DocZipFile'))
|
|
|
+ print("zip_path:",zip_path)
|
|
|
+
|
|
|
+ # verifica l'esistenza della directory
|
|
|
+ try:
|
|
|
+ os.mkdir(zip_path)
|
|
|
+ except FileExistsError as fee:
|
|
|
+ print(zip_path,"esistente")
|
|
|
+ filename = ''.join((str(time.time()),'.zip'))
|
|
|
+
|
|
|
+ with zipfile.ZipFile(os.path.join(zip_path,filename),'w') as zip:
|
|
|
+ for lf in listafile:
|
|
|
+ d = Documento.objects.get(pk=lf)
|
|
|
+ file2zip = os.path.join(settings.BASE_DIR,getConfig('DocPath'),d.utente.azienda.partitaiva,d.utente.codicefiscale,d.storage)
|
|
|
+ zip.write(file2zip,arcname=d.documento)
|
|
|
+ print('path completa',file2zip)
|
|
|
+ print('file completo',os.path.join(zip_path,filename))
|
|
|
+ return (zip_path,filename)
|
|
|
+
|
|
|
+
|