Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update backend_structured/routes.py
Browse files- backend_structured/routes.py +47 -14
backend_structured/routes.py
CHANGED
|
@@ -2284,13 +2284,30 @@ def generate_pdf_report(current_user, scan_id):
|
|
| 2284 |
pdf_bytes = io.BytesIO(pdf_bytes_data)
|
| 2285 |
pdf_bytes.seek(0)
|
| 2286 |
|
| 2287 |
-
|
| 2288 |
-
|
| 2289 |
-
if
|
| 2290 |
-
|
| 2291 |
-
|
| 2292 |
-
|
| 2293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2294 |
|
| 2295 |
# Store a copy in Firebase Cloud Storage for history
|
| 2296 |
from utils.firebase_storage import is_available, upload_bytes
|
|
@@ -2335,13 +2352,29 @@ def generate_public_pdf_report(scan_id):
|
|
| 2335 |
pdf_bytes = io.BytesIO(pdf_bytes_data)
|
| 2336 |
pdf_bytes.seek(0)
|
| 2337 |
|
| 2338 |
-
|
| 2339 |
-
|
| 2340 |
-
|
| 2341 |
-
|
| 2342 |
-
|
| 2343 |
-
|
| 2344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2345 |
|
| 2346 |
return send_file(
|
| 2347 |
pdf_bytes,
|
|
|
|
| 2284 |
pdf_bytes = io.BytesIO(pdf_bytes_data)
|
| 2285 |
pdf_bytes.seek(0)
|
| 2286 |
|
| 2287 |
+
# Fetch organization name for scan
|
| 2288 |
+
org_name = ""
|
| 2289 |
+
if scan.org_id:
|
| 2290 |
+
org = db.session.get(Organization, scan.org_id)
|
| 2291 |
+
if org and org.name:
|
| 2292 |
+
org_name = org.name
|
| 2293 |
+
if not org_name and scan.user_id:
|
| 2294 |
+
user = db.session.get(User, scan.user_id)
|
| 2295 |
+
if user and user.org_id:
|
| 2296 |
+
org = db.session.get(Organization, user.org_id)
|
| 2297 |
+
if org and org.name:
|
| 2298 |
+
org_name = org.name
|
| 2299 |
+
|
| 2300 |
+
if not org_name:
|
| 2301 |
+
org_name = "Global"
|
| 2302 |
+
|
| 2303 |
+
import re
|
| 2304 |
+
clean_org_name = re.sub(r'[^\w]', '', org_name)
|
| 2305 |
+
if not clean_org_name:
|
| 2306 |
+
clean_org_name = "Organization"
|
| 2307 |
+
|
| 2308 |
+
scan_date = scan.completed_at or scan.created_at or datetime.utcnow()
|
| 2309 |
+
date_str = scan_date.strftime('%d%m%Y')
|
| 2310 |
+
filename = f"LarShield_{clean_org_name}_Report_{date_str}.pdf"
|
| 2311 |
|
| 2312 |
# Store a copy in Firebase Cloud Storage for history
|
| 2313 |
from utils.firebase_storage import is_available, upload_bytes
|
|
|
|
| 2352 |
pdf_bytes = io.BytesIO(pdf_bytes_data)
|
| 2353 |
pdf_bytes.seek(0)
|
| 2354 |
|
| 2355 |
+
org_name = ""
|
| 2356 |
+
if scan.org_id:
|
| 2357 |
+
org = db.session.get(Organization, scan.org_id)
|
| 2358 |
+
if org and org.name:
|
| 2359 |
+
org_name = org.name
|
| 2360 |
+
if not org_name and scan.user_id:
|
| 2361 |
+
user = db.session.get(User, scan.user_id)
|
| 2362 |
+
if user and user.org_id:
|
| 2363 |
+
org = db.session.get(Organization, user.org_id)
|
| 2364 |
+
if org and org.name:
|
| 2365 |
+
org_name = org.name
|
| 2366 |
+
|
| 2367 |
+
if not org_name:
|
| 2368 |
+
org_name = "Global"
|
| 2369 |
+
|
| 2370 |
+
import re
|
| 2371 |
+
clean_org_name = re.sub(r'[^\w]', '', org_name)
|
| 2372 |
+
if not clean_org_name:
|
| 2373 |
+
clean_org_name = "Organization"
|
| 2374 |
+
|
| 2375 |
+
scan_date = scan.completed_at or scan.created_at or datetime.utcnow()
|
| 2376 |
+
date_str = scan_date.strftime('%d%m%Y')
|
| 2377 |
+
filename = f"LarShield_{clean_org_name}_Report_{date_str}.pdf"
|
| 2378 |
|
| 2379 |
return send_file(
|
| 2380 |
pdf_bytes,
|