Update cemento.py
This commit is contained in:
70
cemento.py
70
cemento.py
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Flask, render_template, request, Response
|
||||
import math
|
||||
import subprocess # Necessario per la stampa
|
||||
import subprocess
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -46,46 +46,68 @@ def calcola(d):
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
res = None
|
||||
if request.method == 'POST': res = calcola(request.form)
|
||||
return render_template('index.html', res=res, form=request.form)
|
||||
msg_stampa = None
|
||||
# Gestione stampa interna per non cambiare pagina
|
||||
if request.method == 'POST':
|
||||
if 'btn_stampa' in request.form:
|
||||
res = calcola(request.form)
|
||||
msg_stampa = stampa_logica(request.form)
|
||||
else:
|
||||
res = calcola(request.form)
|
||||
return render_template('index.html', res=res, form=request.form, msg_stampa=msg_stampa)
|
||||
|
||||
@app.route('/stampa_pdf', methods=['POST'])
|
||||
def stampa_pdf():
|
||||
"""Nuova funzione integrata per la stampa su Docker"""
|
||||
def stampa_logica(f):
|
||||
"""Logica dettagliata per il PDF in formato PostScript"""
|
||||
try:
|
||||
f = request.form
|
||||
# Prepariamo il contenuto PostScript per il PDF
|
||||
ps_content = f"""%!PS
|
||||
/Helvetica-Bold findfont 16 scalefont setfont
|
||||
/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) show
|
||||
100 700 moveto (Peso Totale: {f.get('res_peso')} Kg) show
|
||||
100 680 moveto (Totale Sacchetti: {f.get('res_tot_s')}) show
|
||||
100 660 moveto (Costo Complessivo: {f.get('res_costo_t')} Euro) show
|
||||
100 630 moveto (Data: 20/01/2026) show
|
||||
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
|
||||
showpage"""
|
||||
|
||||
# Iniezione diretta nel container tramite docker exec
|
||||
comando = ["docker", "exec", "-i", "cups-pdf-server", "lp", "-d", "Virtual_PDF"]
|
||||
processo = subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True)
|
||||
|
||||
if processo.returncode == 0:
|
||||
subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True)
|
||||
return "OK - PDF generato correttamente!"
|
||||
else:
|
||||
return f"Errore Docker: {processo.stderr.decode()}"
|
||||
except Exception as e:
|
||||
return f"Errore: {str(e)}"
|
||||
|
||||
@app.route('/download', methods=['POST'])
|
||||
def download():
|
||||
# ... (resta invariato come nel tuo file originale) ...
|
||||
f = request.form
|
||||
report = f"""-------------------------------------------
|
||||
REPORT TECNICO CALCOLO CEMENTO
|
||||
-------------------------------------------
|
||||
PARAMETRI DI INPUT..."""
|
||||
return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report_Dettagliato.txt"})
|
||||
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')}
|
||||
-------------------------------------------"""
|
||||
return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report.txt"})
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
Reference in New Issue
Block a user