Files
fleet-management/app/routes/admin.py
T
alro65 5b7b41aa50 Initial commit: Fleet Management app with security hardening and background launcher
- Flask app with SQLAlchemy, Flask-Login, Flask-Mail
- Admin/owner roles, vessel management, charters, work orders
- Background launcher (Iniciar.vbs) runs server without terminal window
- Root redirect fixed: / → /login
- debug=False, use_reloader=False for pythonw.exe compatibility

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 02:54:10 -04:00

40 lines
1.5 KiB
Python

from flask import Blueprint, render_template, abort, redirect, url_for
from flask_login import login_required, current_user
from app.models import Vessel, Company
bp = Blueprint('admin', __name__, url_prefix='/admin')
@bp.route('/dashboard')
@login_required
def dashboard():
if current_user.role != 'admin':
return 'Acceso denegado', 403
return render_template('admin/dashboard.html', user=current_user)
@bp.route('/companies')
@login_required
def companies():
from app.models import Company, User
if not getattr(current_user, 'is_super_admin', False):
return redirect(url_for('admin.dashboard'))
mgmt_companies = Company.query.filter_by(type='management').all()
return render_template('admin/companies.html', companies=mgmt_companies, user=current_user)
@bp.route('/vessel/<int:vessel_id>/accounting')
@login_required
def vessel_accounting(vessel_id):
if current_user.role != 'admin':
return 'Acceso denegado', 403
vessel = Vessel.query.get_or_404(vessel_id)
owner = Company.query.get(vessel.owner_company_id)
plan_names = {1: 'Básico ($199/mes)', 2: 'Estándar ($399/mes)',
3: 'Mantenimiento ($299/mes)', 4: 'Plus ($599/mes)'}
plan_costs = {1: 199, 2: 399, 3: 299, 4: 599}
return render_template('admin/vessel_accounting.html',
vessel=vessel,
owner=owner,
plan_name=plan_names.get(vessel.plan_id, 'Sin plan'),
plan_cost=plan_costs.get(vessel.plan_id, 0),
user=current_user
)