Update cemento.py
This commit is contained in:
54
cemento.py
54
cemento.py
@@ -47,41 +47,37 @@ def calcola(d):
|
|||||||
def index():
|
def index():
|
||||||
res = None
|
res = None
|
||||||
msg_stampa = None
|
msg_stampa = None
|
||||||
# Gestione stampa interna per non cambiare pagina
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
res = calcola(request.form)
|
||||||
if 'btn_stampa' in request.form:
|
if 'btn_stampa' in request.form:
|
||||||
res = calcola(request.form)
|
msg_stampa = stampa_pdf_docker(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)
|
return render_template('index.html', res=res, form=request.form, msg_stampa=msg_stampa)
|
||||||
|
|
||||||
def stampa_logica(f):
|
def stampa_pdf_docker(f):
|
||||||
"""Logica dettagliata per il PDF in formato PostScript"""
|
|
||||||
try:
|
try:
|
||||||
|
# Contenuto PostScript con tutti i dettagli richiesti
|
||||||
ps_content = f"""%!PS
|
ps_content = f"""%!PS
|
||||||
/Helvetica-Bold findfont 18 scalefont setfont
|
/Helvetica-Bold findfont 18 scalefont setfont
|
||||||
100 750 moveto (REPORT TECNICO CALCOLO CEMENTO) show
|
100 750 moveto (REPORT TECNICO CALCOLO CEMENTO) show
|
||||||
/Helvetica findfont 12 scalefont setfont
|
/Helvetica findfont 12 scalefont setfont
|
||||||
100 720 moveto (Volume Totale: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg) 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) 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:) show
|
100 670 moveto (DETTAGLIO ACQUISTI (Sacchetti):) show
|
||||||
120 650 moveto (- Cemento: {f.get('res_s_cem')} sacchetti) show
|
120 655 moveto (- Cemento: {f.get('res_s_cem')} pezzi) show
|
||||||
120 635 moveto (- Sabbia: {f.get('res_s_sab')} sacchetti) show
|
120 640 moveto (- Sabbia: {f.get('res_s_sab')} pezzi) show
|
||||||
120 620 moveto (- Ghiaia: {f.get('res_s_ghi')} sacchetti) show
|
120 625 moveto (- Ghiaia: {f.get('res_s_ghi')} pezzi) show
|
||||||
100 595 moveto (COSTO COMPLESSIVO: {f.get('res_costo_t')} Euro) show
|
100 595 moveto (DOSAGGIO PER SINGOLO CARICO ({f.get('res_nc')} carichi):) show
|
||||||
100 565 moveto (DOSAGGIO PER SINGOLO CARICO ({f.get('res_nc')} carichi):) show
|
120 580 moveto (- Cemento: {f.get('res_bc_cem')} sacch.) show
|
||||||
120 545 moveto (- Cemento: {f.get('res_bc_cem')} sacch.) show
|
120 565 moveto (- Sabbia: {f.get('res_bc_sab')} sacch.) show
|
||||||
120 530 moveto (- Sabbia: {f.get('res_bc_sab')} sacch.) show
|
120 550 moveto (- Ghiaia: {f.get('res_bc_ghi')} sacch.) show
|
||||||
120 515 moveto (- Ghiaia: {f.get('res_bc_ghi')} sacch.) show
|
120 535 moveto (- Acqua: {f.get('res_bc_aq')} L) show
|
||||||
120 500 moveto (- Acqua: {f.get('res_bc_aq')} L) show
|
100 490 moveto (Data Generazione: 20/01/2026) show
|
||||||
100 460 moveto (Data: 20/01/2026) show
|
|
||||||
showpage"""
|
showpage"""
|
||||||
comando = ["docker", "exec", "-i", "cups-pdf-server", "lp", "-d", "Virtual_PDF"]
|
comando = ["docker", "exec", "-i", "cups-pdf-server", "lp", "-d", "Virtual_PDF"]
|
||||||
subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True)
|
subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True)
|
||||||
return "OK - PDF generato correttamente!"
|
return "OK - PDF generato correttamente!"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Errore: {str(e)}"
|
return f"Errore Stampa: {str(e)}"
|
||||||
|
|
||||||
@app.route('/download', methods=['POST'])
|
@app.route('/download', methods=['POST'])
|
||||||
def download():
|
def download():
|
||||||
@@ -89,23 +85,9 @@ def download():
|
|||||||
report = f"""-------------------------------------------
|
report = f"""-------------------------------------------
|
||||||
REPORT TECNICO CALCOLO CEMENTO
|
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:
|
RISULTATI:
|
||||||
- Volume: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg
|
- 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')}
|
- Acqua: {f.get('res_aq')} L | Costo: {f.get('res_costo_t')} EUR
|
||||||
- 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"})
|
return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report.txt"})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user