Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,16 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
from datetime import datetime, timedelta
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# --- Página Inicial ---
|
| 8 |
@app.route("/", methods=["GET"])
|
| 9 |
def home():
|
|
@@ -66,148 +73,10 @@ def salvar_obra():
|
|
| 66 |
endereco=endereco,
|
| 67 |
inicio=inicio.strftime("%d/%m/%Y"),
|
| 68 |
itens=itens_formatados,
|
| 69 |
-
total=total,
|
| 70 |
-
pagamentos=pagamentos
|
| 71 |
)
|
| 72 |
|
| 73 |
-
# --- HTMLs Embutidos ---
|
| 74 |
-
|
| 75 |
-
HTML_FORM = """
|
| 76 |
-
<!DOCTYPE html>
|
| 77 |
-
<html lang="pt-br">
|
| 78 |
-
<head>
|
| 79 |
-
<meta charset="UTF-8">
|
| 80 |
-
<title>Simulador de Reforma</title>
|
| 81 |
-
<style>
|
| 82 |
-
body {
|
| 83 |
-
font-family: 'Segoe UI', sans-serif;
|
| 84 |
-
background-color: #f0f4f8;
|
| 85 |
-
color: #333;
|
| 86 |
-
padding: 40px;
|
| 87 |
-
}
|
| 88 |
-
.container {
|
| 89 |
-
max-width: 700px;
|
| 90 |
-
margin: auto;
|
| 91 |
-
background: white;
|
| 92 |
-
padding: 30px;
|
| 93 |
-
border-radius: 15px;
|
| 94 |
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
| 95 |
-
}
|
| 96 |
-
h1 {
|
| 97 |
-
color: #004080;
|
| 98 |
-
}
|
| 99 |
-
label {
|
| 100 |
-
display: block;
|
| 101 |
-
margin: 15px 0 5px;
|
| 102 |
-
}
|
| 103 |
-
input, select {
|
| 104 |
-
width: 100%;
|
| 105 |
-
padding: 8px;
|
| 106 |
-
margin-bottom: 10px;
|
| 107 |
-
border-radius: 6px;
|
| 108 |
-
border: 1px solid #ccc;
|
| 109 |
-
}
|
| 110 |
-
button {
|
| 111 |
-
background-color: #0070cc;
|
| 112 |
-
color: white;
|
| 113 |
-
padding: 10px 20px;
|
| 114 |
-
border: none;
|
| 115 |
-
border-radius: 8px;
|
| 116 |
-
font-size: 16px;
|
| 117 |
-
cursor: pointer;
|
| 118 |
-
}
|
| 119 |
-
button:hover {
|
| 120 |
-
background-color: #005bb5;
|
| 121 |
-
}
|
| 122 |
-
</style>
|
| 123 |
-
</head>
|
| 124 |
-
<body>
|
| 125 |
-
<div class="container">
|
| 126 |
-
<h1>Simulador de Reforma</h1>
|
| 127 |
-
<form action="/salvar_obra" method="post">
|
| 128 |
-
<label>Nome do Cliente: <input type="text" name="cliente" required></label>
|
| 129 |
-
<label>Endereço da Obra: <input type="text" name="endereco" required></label>
|
| 130 |
-
<label>M² da Obra: <input type="number" name="metros" required></label>
|
| 131 |
-
<label>Quantidade de Quartos: <input type="number" name="quartos" required></label>
|
| 132 |
-
<label>Número de Banheiros: <input type="number" name="banheiros" required></label>
|
| 133 |
-
<label>Tamanho dos Banheiros:
|
| 134 |
-
<select name="tamanho_banheiro">
|
| 135 |
-
<option value="pequeno">Pequeno</option>
|
| 136 |
-
<option value="medio">Médio</option>
|
| 137 |
-
<option value="grande">Grande</option>
|
| 138 |
-
</select>
|
| 139 |
-
</label>
|
| 140 |
-
<label>Tamanho da Cozinha (m²): <input type="number" name="cozinha_m2" required></label>
|
| 141 |
-
<label>Padrão de Acabamento:
|
| 142 |
-
<select name="acabamento">
|
| 143 |
-
<option value="simples">Simples</option>
|
| 144 |
-
<option value="medio">Médio</option>
|
| 145 |
-
<option value="luxo">Luxo</option>
|
| 146 |
-
</select>
|
| 147 |
-
</label>
|
| 148 |
-
<label>Início da Obra: <input type="date" name="inicio" required></label>
|
| 149 |
-
<button type="submit">Gerar Orçamento</button>
|
| 150 |
-
</form>
|
| 151 |
-
</div>
|
| 152 |
-
</body>
|
| 153 |
-
</html>
|
| 154 |
-
"""
|
| 155 |
-
|
| 156 |
-
HTML_RELATORIO = """
|
| 157 |
-
<!DOCTYPE html>
|
| 158 |
-
<html lang="pt-br">
|
| 159 |
-
<head>
|
| 160 |
-
<meta charset="UTF-8">
|
| 161 |
-
<title>Relatório da Obra</title>
|
| 162 |
-
<style>
|
| 163 |
-
body {
|
| 164 |
-
font-family: 'Segoe UI', sans-serif;
|
| 165 |
-
background-color: #f8f9fa;
|
| 166 |
-
padding: 40px;
|
| 167 |
-
}
|
| 168 |
-
.container {
|
| 169 |
-
max-width: 800px;
|
| 170 |
-
margin: auto;
|
| 171 |
-
background: white;
|
| 172 |
-
padding: 30px;
|
| 173 |
-
border-radius: 15px;
|
| 174 |
-
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
|
| 175 |
-
}
|
| 176 |
-
h1, h2 {
|
| 177 |
-
color: #004080;
|
| 178 |
-
}
|
| 179 |
-
.item {
|
| 180 |
-
padding: 6px 0;
|
| 181 |
-
border-bottom: 1px solid #ddd;
|
| 182 |
-
}
|
| 183 |
-
.total {
|
| 184 |
-
font-size: 1.2em;
|
| 185 |
-
color: #006600;
|
| 186 |
-
margin-top: 20px;
|
| 187 |
-
font-weight: bold;
|
| 188 |
-
}
|
| 189 |
-
</style>
|
| 190 |
-
</head>
|
| 191 |
-
<body>
|
| 192 |
-
<div class="container">
|
| 193 |
-
<h1>Relatório da Obra</h1>
|
| 194 |
-
<p><strong>Cliente:</strong> {{cliente}}</p>
|
| 195 |
-
<p><strong>Endereço:</strong> {{endereco}}</p>
|
| 196 |
-
<p><strong>Início da Obra:</strong> {{inicio}}</p>
|
| 197 |
-
<h2>Itens e Custos:</h2>
|
| 198 |
-
{% for i in itens %}
|
| 199 |
-
<div class="item">{{i.nome}} ({{i.inicio}} - {{i.fim}}) → R$ {{i.custo}}</div>
|
| 200 |
-
{% endfor %}
|
| 201 |
-
<p class="total">Total: R$ {{total}}</p>
|
| 202 |
-
<h2>Pagamentos:</h2>
|
| 203 |
-
{% for p in pagamentos %}
|
| 204 |
-
<div class="item">{{p.data}} → R$ {{p.valor}}</div>
|
| 205 |
-
{% endfor %}
|
| 206 |
-
</div>
|
| 207 |
-
</body>
|
| 208 |
-
</html>
|
| 209 |
-
"""
|
| 210 |
-
|
| 211 |
# --- Executa no Hugging Face Spaces ---
|
| 212 |
if __name__ == "__main__":
|
| 213 |
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
from flask import Flask, request, render_template_string, send_file
|
| 3 |
from datetime import datetime, timedelta
|
| 4 |
import os
|
| 5 |
+
import io
|
| 6 |
+
from fpdf import FPDF
|
| 7 |
|
| 8 |
app = Flask(__name__)
|
| 9 |
|
| 10 |
+
# --- Função para formatar como R$ ---
|
| 11 |
+
def formatar_moeda(valor):
|
| 12 |
+
return f"R$ {valor:,.2f}".replace(",", "v").replace(".", ",").replace("v", ".")
|
| 13 |
+
|
| 14 |
# --- Página Inicial ---
|
| 15 |
@app.route("/", methods=["GET"])
|
| 16 |
def home():
|
|
|
|
| 73 |
endereco=endereco,
|
| 74 |
inicio=inicio.strftime("%d/%m/%Y"),
|
| 75 |
itens=itens_formatados,
|
| 76 |
+
total=formatar_moeda(total),
|
| 77 |
+
pagamentos=[{ "data": p["data"], "valor": formatar_moeda(p["valor"]) } for p in pagamentos],
|
| 78 |
)
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
# --- Executa no Hugging Face Spaces ---
|
| 81 |
if __name__ == "__main__":
|
| 82 |
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
|