Sep 16 - Optimize code, part 1

This commit is contained in:
2026-09-16 10:52:59 -04:00
parent 4212726611
commit 7626287344
22 changed files with 587 additions and 96 deletions
+9 -3
View File
@@ -15,10 +15,15 @@ from models.project import Project
from models.user import User
from sqlalchemy import text
from logger_handler import log_user_activity, log_database_operations
from utils.helpers import login_required, staff_or_admin_required
from utils.helpers import login_required, staff_or_admin_required, restrict_blueprint_to_roles, PAYROLL_AREA_ROLES
from utils.excel_safety import csv_safe
bp = Blueprint('statistics', __name__)
# Company-wide statistics: admins in the sidebar; the export already allowed
# payroll and accounting, so the same three roles are checked for every route.
restrict_blueprint_to_roles(bp, PAYROLL_AREA_ROLES)
@bp.route('/statistics', endpoint='qr_statistics')
@@ -278,7 +283,8 @@ def export_statistics():
# Write data
for row in export_data:
writer.writerow([
# csv_safe: device / address text starting with = + - @ must not run as a formula
writer.writerow([csv_safe(v) for v in [
row.id, row.employee_id, row.employee_name,
str(row.check_in_date), str(row.check_in_time),
row.qr_code_name, row.qr_location, row.location_event,
@@ -287,7 +293,7 @@ def export_statistics():
row.latitude or '', row.longitude or '',
row.address or '', row.location_name or '',
str(row.created_timestamp)
])
]])
output.seek(0)