From 7ba555890a79588f291e86850b34ee31a422cfbc Mon Sep 17 00:00:00 2001 From: francesco Date: Tue, 20 Jan 2026 13:14:51 +0100 Subject: [PATCH] Update cemento.py --- cemento.py | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/cemento.py b/cemento.py index 1f746a4..cb1d7b5 100644 --- a/cemento.py +++ b/cemento.py @@ -49,46 +49,42 @@ def index(): msg_stampa = None if request.method == 'POST': res = calcola(request.form) + # Se รจ stato premuto il tasto stampa, esegui la logica Docker if 'btn_stampa' in request.form: - msg_stampa = stampa_pdf_docker(request.form) + msg_stampa = esegui_stampa_cups(request.form) return render_template('index.html', res=res, form=request.form, msg_stampa=msg_stampa) -def stampa_pdf_docker(f): +def esegui_stampa_cups(f): try: - # Contenuto PostScript con tutti i dettagli richiesti + # PostScript arricchito con tutti i dati 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 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 +100 720 moveto (Volume Totale: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg) show +100 700 moveto (Costo Complessivo: {f.get('res_costo_t')} Euro) show +100 670 moveto (ACQUISTI:) show +120 655 moveto (- Cemento: {f.get('res_s_cem')} sacch.) show +120 640 moveto (- Sabbia: {f.get('res_s_sab')} sacch.) show +120 625 moveto (- Ghiaia: {f.get('res_s_ghi')} sacch.) show +120 610 moveto (- Acqua: {f.get('res_aq')} L) show +100 580 moveto (CARICO BETONIERA ({f.get('res_nc')} carichi):) show +120 565 moveto (- Cemento: {f.get('res_bc_cem')} pezzi) show +120 550 moveto (- Sabbia: {f.get('res_bc_sab')} pezzi) show +120 535 moveto (- Ghiaia: {f.get('res_bc_ghi')} pezzi) show +120 520 moveto (- Acqua: {f.get('res_bc_aq')} L) show +100 480 moveto (Data: 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 Stampa: {str(e)}" + return f"Errore: {str(e)}" @app.route('/download', methods=['POST']) def download(): f = request.form - report = f"""------------------------------------------- - REPORT TECNICO CALCOLO CEMENTO -------------------------------------------- -RISULTATI: -- Volume: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg -- Acqua: {f.get('res_aq')} L | Costo: {f.get('res_costo_t')} EUR --------------------------------------------""" + report = f"REPORT TECNICO\nVolume: {f.get('res_vol')} m3\nCosto: {f.get('res_costo_t')} EUR" return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report.txt"}) if __name__ == '__main__':