|
|
@@ -14,6 +14,8 @@ from config.views import *
|
|
|
from .managefile import *
|
|
|
from att.views import *
|
|
|
|
|
|
+from datetime import datetime,timedelta
|
|
|
+
|
|
|
def welcome(request):
|
|
|
'''
|
|
|
punto di ingresso.
|
|
|
@@ -55,11 +57,36 @@ def welcome(request):
|
|
|
utenti = Utente.objects.filter(azienda = azienda)
|
|
|
data['utenti'] = utenti
|
|
|
|
|
|
+ eol = getConfig('DocEol')
|
|
|
+ data['eol'] = eol
|
|
|
+
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
if 'ritorna' in request.POST:
|
|
|
return HttpResponseRedirect(reverse("azienda:welcome"))
|
|
|
|
|
|
+ if 'DeleteOldDocuments' in request.POST:
|
|
|
+ print('Richiesta di eliminazione vecchi documenti')
|
|
|
+ dods = DeleteOldDocuments(request.POST)
|
|
|
+ if dods.is_valid():
|
|
|
+ print('request',request.POST)
|
|
|
+ print('dods',dods.cleaned_data)
|
|
|
+ print(request.POST['limite'])
|
|
|
+ print('effettuata scelta di cancellazione vecchi documenti')
|
|
|
+ # costuire una lista dei documenti più vecchi
|
|
|
+ limite = int(request.POST['limite'])
|
|
|
+ print('limite',limite)
|
|
|
+ d = datetime.now()
|
|
|
+ r = d - timedelta(days=limite)
|
|
|
+ print(r)
|
|
|
+ oldDocs = Documento.objects.filter(azienda=azienda)
|
|
|
+ oldDocs1 = oldDocs.filter(dataupload__lt=r)
|
|
|
+ print('lista documenti',len(oldDocs1))
|
|
|
+ for i in oldDocs1:
|
|
|
+ print('documento',i.documento)
|
|
|
+ delete_file(i)
|
|
|
+ i.delete()
|
|
|
+
|
|
|
if 'DeleteDocument' in request.POST:
|
|
|
print('Richiesta cancellazione Documento',request.POST)
|
|
|
documento = request.POST['DeleteDocument'] # perche' lo considera una lista e non un singolo valore?
|
|
|
@@ -67,7 +94,6 @@ def welcome(request):
|
|
|
try:
|
|
|
d = Documento.objects.get(pk=documento)
|
|
|
delete_file(d) #rimozione fisica del documento
|
|
|
- setLog(5,documento,admin)
|
|
|
d.delete()
|
|
|
except Documento.DoesNotExist as dne:
|
|
|
print('il documento non esiste')
|
|
|
@@ -149,8 +175,9 @@ def finalize_download(request,did,uid=None):
|
|
|
|
|
|
mime_type, _ = mimetypes.guess_type(fl_completa)
|
|
|
fl = fl_completa
|
|
|
- print('fl',fl,mime_type,'fn',documento.documento)
|
|
|
- response = FileResponse(open(fl,'rb'),content_type='application/pdf',filename="%s" % documento.documento,as_attachment=False)
|
|
|
- setLog(3,utente=utente,documento=documento,azienda=utente.azienda)
|
|
|
+ print('fl',fl,mime_type)
|
|
|
+ response = FileResponse(open(fl,'rb'),content_type='application/pdf',as_attachment=False)
|
|
|
+ #response['Content-Disposition'] = "attachment; filename=%s" % documento.documento
|
|
|
+ setNewLog(3,{'utente':utente,'documento':documento,'azienda':utente.azienda})
|
|
|
return response
|
|
|
|