|
@@ -1,5 +1,5 @@
|
|
|
from django.shortcuts import render
|
|
from django.shortcuts import render
|
|
|
-from django.http import HttpResponse
|
|
|
|
|
|
|
+from django.http import HttpResponse,FileResponse
|
|
|
|
|
|
|
|
from .forms import *
|
|
from .forms import *
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
@@ -8,6 +8,7 @@ from bpconverter.settings import MEDIA_ROOT
|
|
|
import PyPDF2
|
|
import PyPDF2
|
|
|
import re
|
|
import re
|
|
|
import glob
|
|
import glob
|
|
|
|
|
+import mimetypes
|
|
|
|
|
|
|
|
def handle_uploaded_file(f):
|
|
def handle_uploaded_file(f):
|
|
|
print(dir(f.chunks))
|
|
print(dir(f.chunks))
|
|
@@ -154,3 +155,35 @@ def frontpage(request):
|
|
|
|
|
|
|
|
return render(request,'frontpage.html',data)
|
|
return render(request,'frontpage.html',data)
|
|
|
|
|
|
|
|
|
|
+def finalize(request,cf=None):
|
|
|
|
|
+
|
|
|
|
|
+ if not cf:
|
|
|
|
|
+ return render("download.error.html")
|
|
|
|
|
+
|
|
|
|
|
+ fl_completa = os.path.join(MEDIA_ROOT,'out',"{}.pdf".format(cf))
|
|
|
|
|
+
|
|
|
|
|
+ print('path completa',fl_completa)
|
|
|
|
|
+
|
|
|
|
|
+ if os.path.isfile(fl_completa):
|
|
|
|
|
+ try:
|
|
|
|
|
+ fl = open(fl_completa, 'rb')
|
|
|
|
|
+ except Exception as er:
|
|
|
|
|
+ print('errore',er)
|
|
|
|
|
+ data=dict()
|
|
|
|
|
+ data['errore']="File non esistente o non ancora disponibile"
|
|
|
|
|
+ return render(request,'documento.error.html',data)
|
|
|
|
|
+ else:
|
|
|
|
|
+ print('il file non esiste in document,download')
|
|
|
|
|
+ data=dict()
|
|
|
|
|
+ data['errore']='File non esistente o non ancora disponibile'
|
|
|
|
|
+ return render(request,'documento.error.html',data)
|
|
|
|
|
+
|
|
|
|
|
+ mime_type, _ = mimetypes.guess_type(fl_completa)
|
|
|
|
|
+ fl = fl_completa
|
|
|
|
|
+ print('fl',fl,mime_type) # deve essere un file pdf
|
|
|
|
|
+ #response = HttpResponse(open(fl,'rb'))
|
|
|
|
|
+ response = FileResponse(open(fl,'rb'), content_type='application/pdf')
|
|
|
|
|
+ response['Content-Disposition'] = "inline; filename=%s" % "{}.pdf".format(cf)
|
|
|
|
|
+
|
|
|
|
|
+ return response
|
|
|
|
|
+
|