feat: 优化PDF报告生成逻辑并添加调试脚本
移除对weasyprint_available的冗余检查,使用更高效的Count查询统计家庭事项 添加debug_pdf_email.py调试脚本用于直接测试PDF生成和邮件发送功能
This commit is contained in:
@@ -355,8 +355,7 @@ def celery_send_pdf_report_email(self):
|
||||
logger.error(f"[任务 {task_id}] ❌ WeasyPrint库无法导入: {e}")
|
||||
raise ValueError("WeasyPrint库无法导入,PDF功能将不可用")
|
||||
|
||||
if not weasyprint_available:
|
||||
raise ValueError("WeasyPrint库不可用,无法生成PDF报告")
|
||||
|
||||
|
||||
# 从数据库获取邮件配置
|
||||
from core.models import SystemConfig, ReadingRecord, InsightRecord, TodayPlan, FamilyTask
|
||||
@@ -415,7 +414,8 @@ def celery_send_pdf_report_email(self):
|
||||
|
||||
# 获取家庭事项统计
|
||||
logger.info(f"[任务 {task_id}] 📊 获取家庭事项统计...")
|
||||
family_task_stats = FamilyTask.objects.values('type').annotate(count=FamilyTask.objects.values('id').filter(type=F('type')).count())
|
||||
from django.db.models import Count
|
||||
family_task_stats = FamilyTask.objects.values('type').annotate(count=Count('id'))
|
||||
logger.info(f"[任务 {task_id}] ✅ 家庭事项统计: {len(family_task_stats)} 个类型")
|
||||
|
||||
# 准备上下文数据
|
||||
@@ -445,7 +445,6 @@ def celery_send_pdf_report_email(self):
|
||||
|
||||
# 使用WeasyPrint生成PDF,设置超时
|
||||
logger.info(f"[任务 {task_id}] 📄 正在生成PDF...")
|
||||
from weasyprint import HTML
|
||||
HTML(string=html_string).write_pdf(pdf_path, timeout=60) # 设置60秒超时
|
||||
logger.info(f"[任务 {task_id}] ✅ PDF报告生成成功: {pdf_path}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user