Browse Source

print activity logic adjusted

aguryev 3 years ago
parent
commit
22f90451e2

+ 10 - 2
antrag.py

@@ -2,7 +2,7 @@
 # Sample Antrag class definition
 #
 
-
+from flask import url_for
 from polzybackend.mediators import Antrag
 from pms.fast_offer import get_fast_offer, get_auto_brands
 from functools import reduce
@@ -100,10 +100,18 @@ class SampleAntrag(Antrag):
             premium['valueChosenOrEntered'] = 1347
             self.instance['status'] = 'Calculated'
             return self.get()
+        
         elif data['activity'] == 'Print':
             from AntragDrucken import AntragDrucken
             lPrint = AntragDrucken(antrag=self)
             lPrint.executeActivity()
-            return lPrint.getFolderAndPath()
+
+            return {
+                "link": url_for(
+                    'end-points.downloads',
+                    filename=lPrint.getFolderAndPath(),
+                    _external=True,
+                ),
+            }
 
         raise Exception(f'Logic for activity {data["activity"]} is not defined')

+ 5 - 0
app.py

@@ -2,6 +2,8 @@ from polzybackend import create_app
 import os
 from clauses import bp as clauses_bp
 from endpoints import bp as ep_bp
+from pathlib import Path
+
 
 
 class Config(object):
@@ -23,6 +25,9 @@ class Config(object):
     LOGO = os.path.join(MEDIA, 'logo')
     BADGES = os.path.join(MEDIA, 'badges')
 
+    PDF = str(Path(os.path.abspath(__file__)).parent.joinpath("pdfoutput"))
+
+
 
 
 app = create_app(Config)

+ 10 - 0
endpoints/routes.py

@@ -57,3 +57,13 @@ def badge_image(type, level=None):
         path_to_file,
         attachment_filename=filename,
     )
+
+
+@bp.route('/files/<string:filename>')
+def downloads(filename):
+    path_to_file = os.path.join(current_app.config['PDF'], filename)
+    #print(path_to_file)
+    return send_file(
+        path_to_file,
+        attachment_filename=filename,
+    )

BIN
pdfoutput/Automobile_20210120_204505958613.pdf


BIN
pdfoutput/Automobile_20210120_204914434991.pdf


BIN
pdfoutput/Automobile_20210120_210054796059.pdf


BIN
pdfoutput/Automobile_20210120_210210622262.pdf


BIN
pdfoutput/Automobile_20210120_210313107326.pdf


BIN
pdfoutput/Automobile_20210120_210435089040.pdf


+ 2 - 1
requirements.txt

@@ -1,2 +1,3 @@
 requests
-polzybackend
+polzybackend
+fpdf