Quellcode durchsuchen

Fix: 修复路径问题

iaun vor 2 Monaten
Ursprung
Commit
f1773d3e63
1 geänderte Dateien mit 18 neuen und 12 gelöschten Zeilen
  1. 18 12
      backend/app/services/report_generator.py

+ 18 - 12
backend/app/services/report_generator.py

@@ -368,21 +368,27 @@ class ReportGenerator:
     def _get_default_template_path(self) -> str:
         """Get the default template path from sample-reports folder."""
         # Look for the template with placeholders
-        base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
-        sample_reports_dir = os.path.join(base_dir, 'sample-reports')
+        # Try multiple possible locations
+        possible_base_dirs = [
+            os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))),  # Development
+            os.path.dirname(os.path.dirname(os.path.dirname(__file__))),  # Docker /app
+            '/app',  # Docker absolute
+        ]
         
-        # Prefer the template with [Client Name]-[Project Name] format
         template_name = '[Client Name]-[Project Name]-Project-Report-v1.0.docx'
-        template_path = os.path.join(sample_reports_dir, template_name)
         
-        if os.path.exists(template_path):
-            return template_path
-        
-        # Fall back to any .docx file in sample-reports
-        if os.path.exists(sample_reports_dir):
-            for file in os.listdir(sample_reports_dir):
-                if file.endswith('.docx'):
-                    return os.path.join(sample_reports_dir, file)
+        for base_dir in possible_base_dirs:
+            sample_reports_dir = os.path.join(base_dir, 'sample-reports')
+            template_path = os.path.join(sample_reports_dir, template_name)
+            
+            if os.path.exists(template_path):
+                return template_path
+            
+            # Fall back to any .docx file in sample-reports
+            if os.path.exists(sample_reports_dir):
+                for file in os.listdir(sample_reports_dir):
+                    if file.endswith('.docx'):
+                        return os.path.join(sample_reports_dir, file)
         
         raise FileNotFoundError("No template file found in sample-reports folder")