Spaces:
Paused

dushyantsingh0 commited on
Commit
4dd0b8a
Β·
2 Parent(s): f2e2626d6c6633

Merge branch 'claude/heuristic-grothendieck-4ee85e'

Browse files
Files changed (1) hide show
  1. tasks/stories.py +39 -14
tasks/stories.py CHANGED
@@ -32,6 +32,30 @@ def _recursive_clean_text(obj):
32
 
33
  logger = logging.getLogger(__name__)
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  # ---------------------------------------------------------------------------
36
  # Enterprise Color Palette
37
  # ---------------------------------------------------------------------------
@@ -341,7 +365,7 @@ def generate_enterprise_pdf(report, context):
341
  if self.page_no() > 1:
342
  self.set_font("helvetica", "B", 8)
343
  self.set_text_color(*TEXT_MUTED)
344
- self.cell(0, 10, f"NEXUS STRATEGIC REPORT | {report['title'].upper()}", align="R")
345
  self.ln(8)
346
  self.set_draw_color(*BRAND_PURPLE)
347
  self.set_line_width(0.4)
@@ -414,7 +438,7 @@ def generate_enterprise_pdf(report, context):
414
  pdf.set_xy(22, 55)
415
  pdf.set_font("helvetica", "B", 38)
416
  pdf.set_text_color(*BRAND_PURPLE)
417
- pdf.multi_cell(0, 14, report["title"].upper())
418
 
419
  pdf.set_xy(22, 118)
420
  pdf.set_draw_color(*BRAND_PURPLE_LIGHT)
@@ -471,7 +495,7 @@ def generate_enterprise_pdf(report, context):
471
  ("Priority & Resource Allocation", 5),
472
  ]
473
  for i, sec in enumerate(report.get("sections", [])):
474
- toc_items.append((sec["title"], 6 + i))
475
  toc_items.append(("Strategic Roadmap", 6 + len(report.get("sections", []))))
476
  toc_items.append(("Recent Signals Audit", 7 + len(report.get("sections", []))))
477
  pdf.add_toc(toc_items)
@@ -484,7 +508,7 @@ def generate_enterprise_pdf(report, context):
484
 
485
  pdf.set_font("helvetica", "", 10.5)
486
  pdf.set_text_color(*TEXT_MAIN)
487
- pdf.multi_cell(0, 6, report["executive_summary"])
488
  pdf.ln(8)
489
 
490
  # KPI row
@@ -517,7 +541,7 @@ def generate_enterprise_pdf(report, context):
517
 
518
  pdf.set_y(pdf.get_y() + 58)
519
  pdf.set_fill_color(*BRAND_PURPLE_LIGHT)
520
- insight = report.get("analytical_insight", "")
521
  if insight:
522
  pdf.set_fill_color(237, 233, 254)
523
  pdf.set_text_color(*BRAND_PURPLE_DARK)
@@ -587,11 +611,11 @@ def generate_enterprise_pdf(report, context):
587
  # -------------------------------------------------------------------------
588
  for i, section in enumerate(report.get("sections", [])):
589
  pdf.add_page()
590
- pdf.section_header(4 + i, section["title"])
591
 
592
  pdf.set_font("helvetica", "", 10.5)
593
  pdf.set_text_color(*TEXT_MAIN)
594
- pdf.multi_cell(0, 6.5, section["content"])
595
  pdf.ln(8)
596
 
597
  if section.get("highlights"):
@@ -609,7 +633,7 @@ def generate_enterprise_pdf(report, context):
609
  pdf.set_fill_color(237, 233, 254)
610
  pdf.set_text_color(*TEXT_MAIN)
611
  pdf.set_font("helvetica", "", 10)
612
- pdf.multi_cell(184, 8, f" {highlight}", fill=True)
613
  pdf.ln(2)
614
 
615
  # -------------------------------------------------------------------------
@@ -628,7 +652,7 @@ def generate_enterprise_pdf(report, context):
628
  pdf.set_fill_color(*BG_LIGHT)
629
  pdf.set_text_color(*TEXT_MAIN)
630
  pdf.set_font("helvetica", "", 10)
631
- pdf.multi_cell(158, 12, f" {item}", fill=True)
632
  pdf.ln(4)
633
 
634
  # -------------------------------------------------------------------------
@@ -655,11 +679,12 @@ def generate_enterprise_pdf(report, context):
655
 
656
  for t in context["recent_tickets"]:
657
  row = table.row()
658
- row.cell(t["id"])
659
- row.cell(t["title"][:50] + ("..." if len(t["title"]) > 50 else ""))
660
- row.cell(t["status"].upper())
661
- row.cell(t["priority"].upper())
662
- row.cell(t["created_at"][:10])
 
663
 
664
  return pdf.output(dest="S")
665
 
 
32
 
33
  logger = logging.getLogger(__name__)
34
 
35
+ # ---------------------------------------------------------------------------
36
+ # Unicode β†’ Latin-1 sanitizer (fpdf2 built-in fonts are Latin-1 only)
37
+ # ---------------------------------------------------------------------------
38
+ _UNICODE_REPLACEMENTS = str.maketrans({
39
+ "β€”": "--", # em dash
40
+ "–": "-", # en dash
41
+ "β€˜": "'", # left single quote
42
+ "’": "'", # right single quote
43
+ "β€œ": '"', # left double quote
44
+ "”": '"', # right double quote
45
+ "…": "...", # ellipsis
46
+ "Β°": " deg", # degree sign (outside common Latin-1 range in fpdf)
47
+ "β€’": "-", # bullet
48
+ "β†’": "->", # right arrow
49
+ "Γ’": "a", # a circumflex (sometimes LLM-injected)
50
+ })
51
+
52
+ def _s(text: str) -> str:
53
+ """Sanitize LLM-generated text for fpdf Latin-1 helvetica rendering."""
54
+ if not text:
55
+ return ""
56
+ text = str(text).translate(_UNICODE_REPLACEMENTS)
57
+ return text.encode("latin-1", errors="replace").decode("latin-1")
58
+
59
  # ---------------------------------------------------------------------------
60
  # Enterprise Color Palette
61
  # ---------------------------------------------------------------------------
 
365
  if self.page_no() > 1:
366
  self.set_font("helvetica", "B", 8)
367
  self.set_text_color(*TEXT_MUTED)
368
+ self.cell(0, 10, f"NEXUS STRATEGIC REPORT | {_s(report['title']).upper()}", align="R")
369
  self.ln(8)
370
  self.set_draw_color(*BRAND_PURPLE)
371
  self.set_line_width(0.4)
 
438
  pdf.set_xy(22, 55)
439
  pdf.set_font("helvetica", "B", 38)
440
  pdf.set_text_color(*BRAND_PURPLE)
441
+ pdf.multi_cell(0, 14, _s(report["title"]).upper())
442
 
443
  pdf.set_xy(22, 118)
444
  pdf.set_draw_color(*BRAND_PURPLE_LIGHT)
 
495
  ("Priority & Resource Allocation", 5),
496
  ]
497
  for i, sec in enumerate(report.get("sections", [])):
498
+ toc_items.append((_s(sec["title"]), 6 + i))
499
  toc_items.append(("Strategic Roadmap", 6 + len(report.get("sections", []))))
500
  toc_items.append(("Recent Signals Audit", 7 + len(report.get("sections", []))))
501
  pdf.add_toc(toc_items)
 
508
 
509
  pdf.set_font("helvetica", "", 10.5)
510
  pdf.set_text_color(*TEXT_MAIN)
511
+ pdf.multi_cell(0, 6, _s(report["executive_summary"]))
512
  pdf.ln(8)
513
 
514
  # KPI row
 
541
 
542
  pdf.set_y(pdf.get_y() + 58)
543
  pdf.set_fill_color(*BRAND_PURPLE_LIGHT)
544
+ insight = _s(report.get("analytical_insight", ""))
545
  if insight:
546
  pdf.set_fill_color(237, 233, 254)
547
  pdf.set_text_color(*BRAND_PURPLE_DARK)
 
611
  # -------------------------------------------------------------------------
612
  for i, section in enumerate(report.get("sections", [])):
613
  pdf.add_page()
614
+ pdf.section_header(4 + i, _s(section["title"]))
615
 
616
  pdf.set_font("helvetica", "", 10.5)
617
  pdf.set_text_color(*TEXT_MAIN)
618
+ pdf.multi_cell(0, 6.5, _s(section.get("content", "")))
619
  pdf.ln(8)
620
 
621
  if section.get("highlights"):
 
633
  pdf.set_fill_color(237, 233, 254)
634
  pdf.set_text_color(*TEXT_MAIN)
635
  pdf.set_font("helvetica", "", 10)
636
+ pdf.multi_cell(184, 8, f" {_s(highlight)}", fill=True)
637
  pdf.ln(2)
638
 
639
  # -------------------------------------------------------------------------
 
652
  pdf.set_fill_color(*BG_LIGHT)
653
  pdf.set_text_color(*TEXT_MAIN)
654
  pdf.set_font("helvetica", "", 10)
655
+ pdf.multi_cell(158, 12, f" {_s(item)}", fill=True)
656
  pdf.ln(4)
657
 
658
  # -------------------------------------------------------------------------
 
679
 
680
  for t in context["recent_tickets"]:
681
  row = table.row()
682
+ title_raw = _s(t.get("title", ""))
683
+ row.cell(_s(t.get("id", "")))
684
+ row.cell(title_raw[:50] + ("..." if len(title_raw) > 50 else ""))
685
+ row.cell(_s(t.get("status", "")).upper())
686
+ row.cell(_s(t.get("priority", "")).upper())
687
+ row.cell(str(t.get("created_at", ""))[:10])
688
 
689
  return pdf.output(dest="S")
690