From 19ec78289b710bfa68642780843251539f0c79c4 Mon Sep 17 00:00:00 2001 From: francesco Date: Tue, 20 Jan 2026 13:12:36 +0100 Subject: [PATCH] Update cemento.py --- cemento.py | 54 ++++++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/cemento.py b/cemento.py index 391bcb9..1f746a4 100644 --- a/cemento.py +++ b/cemento.py @@ -47,41 +47,37 @@ def calcola(d): def index(): res = None msg_stampa = None - # Gestione stampa interna per non cambiare pagina if request.method == 'POST': + res = calcola(request.form) if 'btn_stampa' in request.form: - res = calcola(request.form) - msg_stampa = stampa_logica(request.form) - else: - res = calcola(request.form) + msg_stampa = stampa_pdf_docker(request.form) return render_template('index.html', res=res, form=request.form, msg_stampa=msg_stampa) -def stampa_logica(f): - """Logica dettagliata per il PDF in formato PostScript""" +def stampa_pdf_docker(f): try: + # Contenuto PostScript con tutti i dettagli richiesti ps_content = f"""%!PS /Helvetica-Bold findfont 18 scalefont setfont 100 750 moveto (REPORT TECNICO CALCOLO CEMENTO) show /Helvetica findfont 12 scalefont setfont -100 720 moveto (Volume Totale: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg) show -100 700 moveto (Acqua Totale: {f.get('res_aq')} L) show -100 670 moveto (DETTAGLIO ACQUISTI:) show -120 650 moveto (- Cemento: {f.get('res_s_cem')} sacchetti) show -120 635 moveto (- Sabbia: {f.get('res_s_sab')} sacchetti) show -120 620 moveto (- Ghiaia: {f.get('res_s_ghi')} sacchetti) show -100 595 moveto (COSTO COMPLESSIVO: {f.get('res_costo_t')} Euro) show -100 565 moveto (DOSAGGIO PER SINGOLO CARICO ({f.get('res_nc')} carichi):) show -120 545 moveto (- Cemento: {f.get('res_bc_cem')} sacch.) show -120 530 moveto (- Sabbia: {f.get('res_bc_sab')} sacch.) show -120 515 moveto (- Ghiaia: {f.get('res_bc_ghi')} sacch.) show -120 500 moveto (- Acqua: {f.get('res_bc_aq')} L) show -100 460 moveto (Data: 20/01/2026) show +100 720 moveto (Volume Totale: {f.get('res_vol')} m3 | Peso Totale: {f.get('res_peso')} Kg) show +100 700 moveto (Acqua Totale: {f.get('res_aq')} L | Costo Totale: {f.get('res_costo_t')} Euro) show +100 670 moveto (DETTAGLIO ACQUISTI (Sacchetti):) show +120 655 moveto (- Cemento: {f.get('res_s_cem')} pezzi) show +120 640 moveto (- Sabbia: {f.get('res_s_sab')} pezzi) show +120 625 moveto (- Ghiaia: {f.get('res_s_ghi')} pezzi) show +100 595 moveto (DOSAGGIO PER SINGOLO CARICO ({f.get('res_nc')} carichi):) show +120 580 moveto (- Cemento: {f.get('res_bc_cem')} sacch.) show +120 565 moveto (- Sabbia: {f.get('res_bc_sab')} sacch.) show +120 550 moveto (- Ghiaia: {f.get('res_bc_ghi')} sacch.) show +120 535 moveto (- Acqua: {f.get('res_bc_aq')} L) show +100 490 moveto (Data Generazione: 20/01/2026) show showpage""" comando = ["docker", "exec", "-i", "cups-pdf-server", "lp", "-d", "Virtual_PDF"] subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True) return "OK - PDF generato correttamente!" except Exception as e: - return f"Errore: {str(e)}" + return f"Errore Stampa: {str(e)}" @app.route('/download', methods=['POST']) def download(): @@ -89,23 +85,9 @@ def download(): report = f"""------------------------------------------- REPORT TECNICO CALCOLO CEMENTO ------------------------------------------- -PARAMETRI DI INPUT: -- Dimensioni: {f.get('a')} {f.get('ua')} x {f.get('l')} {f.get('ul')} x {f.get('p')} {f.get('up')} -- Betoniera da {f.get('v_bet')} L - RISULTATI: - Volume: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg -- Acqua: {f.get('res_aq')} L | Tot. Sacchetti: {f.get('res_tot_s')} -- COSTO: {f.get('res_costo_t')} EUR - -DETTAGLIO: -- Cemento: {f.get('res_s_cem')} sacch. -- Sabbia: {f.get('res_s_sab')} sacch. -- Ghiaia: {f.get('res_s_ghi')} sacch. - -CARICO ({f.get('res_nc')} volte): -- Cemento: {f.get('res_bc_cem')} | Sabbia: {f.get('res_bc_sab')} -- Ghiaia: {f.get('res_bc_ghi')} | Acqua: {f.get('res_bc_aq')} +- Acqua: {f.get('res_aq')} L | Costo: {f.get('res_costo_t')} EUR -------------------------------------------""" return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report.txt"})