diff --git a/core/tasks.py b/core/tasks.py index 9a586bf..58a2f75 100644 --- a/core/tasks.py +++ b/core/tasks.py @@ -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}") diff --git a/core/templates/core/report.html b/core/templates/core/report.html index 15f82e8..12159d9 100644 --- a/core/templates/core/report.html +++ b/core/templates/core/report.html @@ -168,4 +168,21 @@ }); }); + +