06/05 Optimize app

This commit is contained in:
2026-06-05 15:51:57 -04:00
parent 458044201e
commit 025f3f8823
14 changed files with 425 additions and 64 deletions
+6 -7
View File
@@ -1,5 +1,5 @@
from flask import (Blueprint, render_template, request, redirect, url_for,
Response, flash, send_file)
Response, flash, send_file, stream_with_context)
from flask_login import login_required, current_user
from app.models.transaction import Transaction
from app.services.report_service import (
@@ -8,7 +8,7 @@ from app.services.report_service import (
take_net_worth_snapshot, category_mom_comparison,
)
from app.services.export_service import (
transactions_to_csv, transactions_to_excel,
transactions_csv_stream, transactions_to_excel,
report_to_pdf, build_report_html,
)
from datetime import date
@@ -141,14 +141,13 @@ def export_csv():
)
if txn_type != 'all':
query = query.filter(Transaction.transaction_type == txn_type)
transactions = query.order_by(Transaction.date.desc()).all()
query = query.order_by(Transaction.date.desc())
csv_data = transactions_to_csv(transactions)
label = f'{year}-{month:02d}' if month else str(year)
filename = f'pfm_transactions_{label}.csv'
return Response(
csv_data,
stream_with_context(transactions_csv_stream(query)),
mimetype='text/csv',
headers={'Content-Disposition': f'attachment; filename="{filename}"'}
)
@@ -167,11 +166,11 @@ def export_excel():
__import__('calendar').monthrange(year, month)[1]),
Transaction.transaction_type.in_(['income', 'expense']),
)
transactions = query.order_by(Transaction.date.desc()).all()
query = query.order_by(Transaction.date.desc())
label = f'{year}-{month:02d}' if month else str(year)
period_label = f'{year} Month {month}' if month else str(year)
excel_bytes = transactions_to_excel(transactions, period_label)
excel_bytes = transactions_to_excel(query, period_label)
filename = f'pfm_transactions_{label}.xlsx'
return send_file(