update autopol 4 nov
This commit is contained in:
+2
-1
@@ -9,8 +9,9 @@ COPY . .
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:5000", "app:app"]
|
||||
CMD ["gunicorn", "-b", "0.0.0.0:5000", "--workers", "3", "--threads", "4", "--worker-class", "gthread", "--timeout", "60", "app:app"]
|
||||
|
||||
# CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:5000", "app:app"]
|
||||
# CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"]
|
||||
# gunicorn -w 2 -b 0.0.0.0:5000 app:app
|
||||
# CMD ["python", "app.py"]
|
||||
|
||||
Executable → Regular
BIN
Binary file not shown.
Executable → Regular
BIN
Binary file not shown.
+102
-26
@@ -31,9 +31,9 @@ ALLOWED_EXTENSIONS = {'pdf'}
|
||||
|
||||
# Configuración MySQL
|
||||
DB_CONFIG = {
|
||||
'host': '192.168.18.4',
|
||||
'host': 'localhost',
|
||||
'user': 'admin',
|
||||
'password': '',
|
||||
'password': 'admin123',
|
||||
'database': 'automocion',
|
||||
'charset': 'utf8mb4',
|
||||
'cursorclass': pymysql.cursors.DictCursor # equivale a row_factory en SQLite
|
||||
@@ -175,8 +175,8 @@ def close_db(e=None):
|
||||
|
||||
|
||||
def init_db():
|
||||
conn = pymysql.connect(host='192.168.18.4', user='admin',
|
||||
password='', charset='utf8mb4',
|
||||
conn = pymysql.connect(host='localhost', user='admin',
|
||||
password='admin123', charset='utf8mb4',
|
||||
cursorclass=pymysql.cursors.DictCursor)
|
||||
cursor = conn.cursor()
|
||||
# cursor.execute('CREATE DATABASE IF NOT EXISTS nexus CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci')
|
||||
@@ -396,44 +396,120 @@ def vehiculos_editar(id):
|
||||
flash('Vehículo no encontrado.', 'error')
|
||||
return redirect(url_for('vehiculos_list'))
|
||||
|
||||
|
||||
if request.method == 'POST':
|
||||
# Recoger parámetros del POST (campos ocultos)
|
||||
q = request.form.get('_q', '')
|
||||
desde = request.form.get('_desde', '')
|
||||
hasta = request.form.get('_hasta', '')
|
||||
q_itv = request.form.get('_q_itv', '')
|
||||
|
||||
f = request.form
|
||||
origen = request.form.get('_origen', '')
|
||||
q_viat = request.form.get('_q_viat', '')
|
||||
|
||||
lanzadestellos = 1 if f.get('lanzadestellos') else 0
|
||||
|
||||
# Preparar los nuevos valores
|
||||
nuevos = (
|
||||
f.get('m_oficial'), f.get('m_reservada'), f.get('m_propia'),
|
||||
f.get('VIN'), f.get('poliza'), f.get('viat') or '',
|
||||
f.get('legajo') or None,
|
||||
f.get('marca'), f.get('modelo'), f.get('tipo'),
|
||||
f.get('color'), f.get('combustible'), f.get('plazas'),
|
||||
lanzadestellos, f.get('situacion'), f.get('poblacion'),
|
||||
f.get('unidad'), f.get('int_operacion'), f.get('int_grupo'),
|
||||
f.get('int_juzgado'), f.get('int_procedimiento'),
|
||||
f.get('km') or None, f.get('km_1') or None,
|
||||
f.get('itv_ultima') or None, f.get('itv') or None,
|
||||
f.get('notas')
|
||||
)
|
||||
|
||||
# Valores actuales de MySQL
|
||||
anteriores = (
|
||||
vehiculo['m_oficial'], vehiculo['m_reservada'],
|
||||
vehiculo['m_propia'], vehiculo['VIN'], vehiculo['poliza'],
|
||||
vehiculo['viat'], vehiculo['legajo'], vehiculo['marca'],
|
||||
vehiculo['modelo'], vehiculo['tipo'], vehiculo['color'],
|
||||
vehiculo['combustible'], vehiculo['plazas'],
|
||||
vehiculo['lanzadestellos'], vehiculo['situacion'],
|
||||
vehiculo['poblacion'], vehiculo['unidad'],
|
||||
vehiculo['int_operacion'], vehiculo['int_grupo'],
|
||||
vehiculo['int_juzgado'], vehiculo['int_procedimiento'],
|
||||
vehiculo['km'], vehiculo['km_1'], vehiculo['itv_ultima'],
|
||||
vehiculo['itv'], vehiculo['notas']
|
||||
)
|
||||
|
||||
# Normalizar valores para evitar diferencias de tipo
|
||||
from decimal import Decimal, InvalidOperation
|
||||
|
||||
campos_numericos = {
|
||||
'plazas', 'lanzadestellos', 'km', 'km_1'
|
||||
}
|
||||
|
||||
campos = [
|
||||
'm_oficial', 'm_reservada', 'm_propia', 'VIN', 'poliza',
|
||||
'viat', 'legajo', 'marca', 'modelo', 'tipo', 'color',
|
||||
'combustible', 'plazas', 'lanzadestellos', 'situacion',
|
||||
'poblacion', 'unidad', 'int_operacion', 'int_grupo',
|
||||
'int_juzgado', 'int_procedimiento', 'km', 'km_1',
|
||||
'itv_ultima', 'itv', 'notas'
|
||||
]
|
||||
|
||||
def normalizar(campo, valor):
|
||||
if valor is None or valor == '':
|
||||
return None
|
||||
|
||||
if hasattr(valor, 'isoformat'):
|
||||
valor = valor.isoformat()
|
||||
|
||||
if campo in campos_numericos:
|
||||
try:
|
||||
return Decimal(str(valor)).normalize()
|
||||
except (InvalidOperation, ValueError):
|
||||
pass
|
||||
|
||||
# Evitar diferencias por espacios
|
||||
return str(valor).strip()
|
||||
|
||||
hay_cambios = False
|
||||
|
||||
for campo, anterior, nuevo in zip(campos, anteriores, nuevos):
|
||||
|
||||
valor_anterior = normalizar(campo, anterior)
|
||||
valor_nuevo = normalizar(campo, nuevo)
|
||||
|
||||
if valor_anterior != valor_nuevo:
|
||||
hay_cambios = True
|
||||
break
|
||||
|
||||
if not hay_cambios:
|
||||
|
||||
flash('No hay cambios que guardar.', 'info')
|
||||
|
||||
else:
|
||||
|
||||
db.execute('''
|
||||
UPDATE vehiculos SET
|
||||
m_oficial=%s, m_reservada=%s, m_propia=%s, VIN=%s, poliza=%s, viat=%s, legajo=%s,
|
||||
marca=%s, modelo=%s, tipo=%s, color=%s, combustible=%s, plazas=%s, lanzadestellos=%s,
|
||||
m_oficial=%s, m_reservada=%s, m_propia=%s,
|
||||
VIN=%s, poliza=%s, viat=%s, legajo=%s,
|
||||
marca=%s, modelo=%s, tipo=%s, color=%s,
|
||||
combustible=%s, plazas=%s, lanzadestellos=%s,
|
||||
situacion=%s, poblacion=%s, unidad=%s,
|
||||
int_operacion=%s, int_grupo=%s, int_juzgado=%s, int_procedimiento=%s,
|
||||
km=%s, km_1=%s, itv_ultima=%s, itv=%s, notas=%s
|
||||
int_operacion=%s, int_grupo=%s,
|
||||
int_juzgado=%s, int_procedimiento=%s,
|
||||
km=%s, km_1=%s, itv_ultima=%s, itv=%s,
|
||||
notas=%s
|
||||
WHERE id=%s
|
||||
''', (
|
||||
f.get('m_oficial'), f.get('m_reservada'), f.get('m_propia'), f.get('VIN'), f.get('poliza'), f.get('viat') or '', f.get('legajo') or None,
|
||||
f.get('marca'), f.get('modelo'), f.get('tipo'), f.get('color'), f.get('combustible'), f.get('plazas'), lanzadestellos,
|
||||
f.get('situacion'), f.get('poblacion'), f.get('unidad'),
|
||||
f.get('int_operacion'), f.get('int_grupo'), f.get('int_juzgado'), f.get('int_procedimiento'),
|
||||
f.get('km') or None, f.get('km_1') or None, f.get('itv_ultima') or None, f.get('itv') or None,
|
||||
f.get('notas'),
|
||||
id
|
||||
))
|
||||
''', nuevos + (id,))
|
||||
|
||||
db.commit()
|
||||
flash('Vehículo actualizado.', 'ok')
|
||||
|
||||
flash('✔ Datos actualizados.', 'ok')
|
||||
|
||||
# Volver a ITV si venía de ahí
|
||||
if desde or hasta or q_itv:
|
||||
return redirect(f'/itv?desde={desde}&hasta={hasta}&q_itv={q_itv}')
|
||||
elif origen == 'viat':
|
||||
return redirect(f'/viat?q={q_viat}')
|
||||
return redirect(url_for('vehiculos_list', q=q) if q else url_for('vehiculos_list'))
|
||||
return redirect(
|
||||
url_for('vehiculos_list', q=q)
|
||||
if q else url_for('vehiculos_list')
|
||||
)
|
||||
|
||||
|
||||
documentos = db.execute(
|
||||
'SELECT * FROM documentos WHERE vehiculo_id=%s ORDER BY fecha DESC',
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
services:
|
||||
flask:
|
||||
build: .
|
||||
container_name: pyfleet
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- ./:/app
|
||||
# - ./database:/app/database
|
||||
# - ./templates:/app
|
||||
|
||||
|
||||
adminer:
|
||||
image: adminer:latest
|
||||
container_name: adminernexus
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "5001:8080"
|
||||
# - 127.0.0.1:8080:8080
|
||||
environment:
|
||||
ADMINER_PASSWORD: "p4ssw0rd"
|
||||
volumes:
|
||||
- ./database:/db
|
||||
# - ./db:/db
|
||||
- ./adminer/plugins-enabled:/var/www/html/plugins-enabled
|
||||
- ./adminer/adminer.css:/var/www/html/adminer.css
|
||||
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
services:
|
||||
flask:
|
||||
build: .
|
||||
container_name: autopol
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- ./:/app
|
||||
Binary file not shown.
Binary file not shown.
Executable
+41
@@ -0,0 +1,41 @@
|
||||
services:
|
||||
flask:
|
||||
build: .
|
||||
container_name: autopol
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- ./:/app
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
db:
|
||||
image: mysql:8.0
|
||||
container_name: mysql
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: root
|
||||
MYSQL_DATABASE: automocion
|
||||
MYSQL_USER: admin
|
||||
MYSQL_PASSWORD: password
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- db_data_autopol:/var/lib/mysql
|
||||
|
||||
phpmyadmin:
|
||||
image: phpmyadmin/phpmyadmin
|
||||
container_name: phpmyadmin-autopol
|
||||
restart: always
|
||||
environment:
|
||||
PMA_HOST: db
|
||||
MYSQL_ROOT_PASSWORD: root
|
||||
ports:
|
||||
- "8081:80"
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
volumes:
|
||||
db_data_autopol:
|
||||
|
||||
@@ -25,13 +25,29 @@ UPDATE vehiculos SET itv = NULL WHERE TRIM(itv) = '';
|
||||
ALTER TABLE vehiculos MODIFY itv DATE NULL;
|
||||
|
||||
|
||||
UPDATE vehiculos SET lanzadestellos = NULL WHERE TRIM(lanzadestellos) = '';
|
||||
ALTER TABLE vehiculos MODIFY lanzadestellos INT;
|
||||
|
||||
|
||||
pip install -r requirements.txt
|
||||
python app.py
|
||||
# → http://127.0.0.1:5000
|
||||
|
||||
Gunicorn
|
||||
|
||||
Solucionar problemas carga lenta en paginas web, modificar Dockerfile:
|
||||
|
||||
CMD ["gunicorn", "-b", "0.0.0.0:5000", "--workers", "3", "--threads", "4", "--worker-class", "gthread", "--timeout", "60", "app:app"]
|
||||
|
||||
gunicorn -b 0.0.0.0:5000 --workers 3 --threads 4 --worker-class gthread --timeout 60 app:app
|
||||
|
||||
|
||||
Luego reconstruye con docker compose up -d --build
|
||||
|
||||
|
||||
gunicorn -w 2 -b 0.0.0.0:5000 app:app
|
||||
|
||||
|
||||
Ejecutar con Python en segundo plano
|
||||
nohup python app.py > flask.log 2>&1 &
|
||||
Comprobar que esta activo
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
SQLITE_WEB_PASSWORD=p4ssw0rd
|
||||
@@ -1,11 +0,0 @@
|
||||
services:
|
||||
sqlite-web:
|
||||
image: coleifer/sqlite-web:latest
|
||||
ports:
|
||||
- "5005:8080"
|
||||
environment:
|
||||
SQLITE_WEB_PASSWORD: ${SQLITE_WEB_PASSWORD}
|
||||
# SQLITE_WEB_PASSWORD: 1234
|
||||
volumes:
|
||||
- ../database:/data
|
||||
command: sqlite_web /data/nexus.db --host 0.0.0.0 --password
|
||||
File diff suppressed because it is too large
Load Diff
BIN
Binary file not shown.
+34
-6
@@ -107,7 +107,6 @@
|
||||
--success: #059669;
|
||||
} */
|
||||
|
||||
|
||||
body {
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
@@ -686,8 +685,10 @@
|
||||
.form-actions { display: flex; gap: 10px; margin-top: 28px; }
|
||||
|
||||
/* ── FLASH ── */
|
||||
.flash { padding: 11px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 20px; animation: slideIn .2s ease; }
|
||||
.flash.ok { background: rgba(52,211,153,.12); border: 1px solid rgba(52,211,153,.3); color: #34d399; }
|
||||
.flash { padding: 11px 16px; border-radius: 8px; font-size: 12px; margin-bottom: 20px; animation: slideIn .2s ease; }
|
||||
.flash.ok { background: rgba(52,211,153,.12); border: 1px solid rgba(52,211,153,.3); color: rgb(2, 112, 48); }
|
||||
.flash.info { background: rgba(59,130,246,.12); border: 1px solid rgba(59,130,246,.3); color: rgb(29,78,216);
|
||||
}
|
||||
.flash.error { background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.3); color: #f87171; }
|
||||
|
||||
@font-face {
|
||||
@@ -718,8 +719,8 @@
|
||||
class="animate__animated animate__backInUp"
|
||||
{% endif %}>
|
||||
<div style="
|
||||
padding: 10px 5px 5px;
|
||||
margin-bottom: 20px;">
|
||||
padding: 1px 5px 5px;
|
||||
margin-bottom: 40px;">
|
||||
<img
|
||||
id="siteLogo"
|
||||
src="{{ url_for('static', filename='img/logo.png') }}"
|
||||
@@ -866,7 +867,10 @@
|
||||
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% for category, message in messages %}
|
||||
<div class="flash {{ category }}">{{ message }}</div>
|
||||
<div style="width: 300px; position: fixed; left: 45%; text-align: center; z-index: 1000;" class="flash {{ category }}">{{ message }}</div>
|
||||
<!-- <div style="width: 300px; float: right; text-align: center;" class="flash {{ category }}">{{ message }}</div> -->
|
||||
<!-- <div style="width: 300px; margin: 0 auto; text-align: center;" class="flash {{ category }}">{{ message }}</div> -->
|
||||
<!-- <div style="width: 400px;" class="flash {{ category }}">{{ message }}</div> -->
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
|
||||
@@ -876,6 +880,30 @@
|
||||
|
||||
</main>
|
||||
|
||||
<script>
|
||||
// Espera a que todo el documento esté cargado
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Busca todos los elementos con la clase 'flash'
|
||||
const flashMessages = document.querySelectorAll('.flash');
|
||||
|
||||
flashMessages.forEach(function(message) {
|
||||
// 1. Configura la transición CSS para que desaparezca suavemente
|
||||
message.style.transition = "opacity 0.5s ease";
|
||||
|
||||
// 2. Espera 10 segundos (10000 milisegundos) antes de iniciar el cierre
|
||||
setTimeout(function() {
|
||||
message.style.opacity = "0"; // Vuelve el mensaje invisible
|
||||
|
||||
// 3. Espera a que termine la animación (0.5s) y elimina el elemento del HTML
|
||||
setTimeout(function() {
|
||||
message.remove();
|
||||
}, 500);
|
||||
|
||||
}, 5000); // 5000 ms = 5 segundos
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- <script>
|
||||
function confirmarEliminar(e) {
|
||||
e.preventDefault();
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user