فهرست منبع

rimosso il supporto a nginx e riutilizzato il modulo finalize di GD

mauro 1 ماه پیش
والد
کامیت
3b1084b2e8
5فایلهای تغییر یافته به همراه58 افزوده شده و 6 حذف شده
  1. 4 2
      bpconverter/settings.py
  2. 15 0
      frontpage/templates/documento.error.html
  3. 2 1
      frontpage/templates/frontpage.html
  4. 3 2
      frontpage/urls.py
  5. 34 1
      frontpage/views.py

+ 4 - 2
bpconverter/settings.py

@@ -131,5 +131,7 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
 
 FORCE_SCRIPT_NAME='/bpconverter'
 
-MEDIA_ROOT=os.path.join(BASE_DIR,'static/upload')
-STATICFILES_DIRS = [ os.path.join(BASE_DIR,'static/upload/out'), ]
+#MEDIA_ROOT=os.path.join(BASE_DIR,'static/upload')
+MEDIA_ROOT=os.path.join('static/upload')
+
+#TATICFILES_DIRS = [ os.path.join(BASE_DIR,'static/upload/out'), ]

+ 15 - 0
frontpage/templates/documento.error.html

@@ -0,0 +1,15 @@
+{% extends 'base.html' %}
+
+{% block top %}
+    <div class='form-outline mb-5 text-center btn-primary h3'>
+            BPC Download Module
+    </div>
+    <div class='form-outline mb-2'>
+      Spiacente, ma il documento non risulta ancora disponibile.
+    </div>
+
+{% endblock %}
+
+{% block body %}
+{% endblock %}
+

+ 2 - 1
frontpage/templates/frontpage.html

@@ -27,7 +27,8 @@
       </p>
       {% for k,f in listafiles.items %}
         <p>
-	<a href='https://altemica.net/bpconverter_static/upload/out/{{ k }}.pdf'>{{ k }}</a> pagine: {{ f.pagine }}
+	<button type='button' class='btn btn-primary btn-sm' onclick="window.open('{% url "Frontpage:finalize" k %}')">{{ k }} pagine: {{ f.pagine }}</button>
+	<!-- <a href='https://altemica.net/bpconverter_static/upload/out/{{ k }}.pdf'>{{ k }}</a> pagine: {{ f.pagine }} -->
 	</p>
       {% endfor %}
   {% endif %}

+ 3 - 2
frontpage/urls.py

@@ -1,8 +1,9 @@
 from django.urls import path
 from . import views
 
-app_name='Frontpage'
+app_name="Frontpage"
 urlpatterns = [
-  path('',views.frontpage,name='frontpage'),
+  path("",views.frontpage,name="frontpage"),
+  path("finalize/<str:cf>/",views.finalize,name="finalize"),
   ]
 

+ 34 - 1
frontpage/views.py

@@ -1,5 +1,5 @@
 from django.shortcuts import render
-from django.http import HttpResponse
+from django.http import HttpResponse,FileResponse
 
 from .forms import *
 from django.views.decorators.csrf import csrf_exempt
@@ -8,6 +8,7 @@ from bpconverter.settings import MEDIA_ROOT
 import PyPDF2
 import re
 import glob
+import mimetypes
 
 def handle_uploaded_file(f):
     print(dir(f.chunks))
@@ -154,3 +155,35 @@ def frontpage(request):
 
   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
+