Feb 02 2026: fixed PDF report converter issue
This commit is contained in:
+23
-37
@@ -149,52 +149,37 @@ def _score_color(score):
|
|||||||
# ── Meta info table ───────────────────────────────────────────────────────────
|
# ── Meta info table ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
def _meta_table(inspection):
|
def _meta_table(inspection):
|
||||||
def cell(label, value):
|
"""Render a 6-column label/value grid covering the key inspection metadata."""
|
||||||
return [
|
|
||||||
Paragraph(label, STYLES['MetaLabel']),
|
|
||||||
Paragraph(str(value), STYLES['MetaValue']),
|
|
||||||
]
|
|
||||||
|
|
||||||
date_str = inspection.inspection_date.strftime('%B %d, %Y')
|
date_str = inspection.inspection_date.strftime('%B %d, %Y')
|
||||||
time_str = inspection.inspection_date.strftime('%I:%M %p ET')
|
time_str = inspection.inspection_date.strftime('%I:%M %p ET')
|
||||||
completed = (inspection.completed_at.strftime('%B %d, %Y %I:%M %p ET')
|
completed = (inspection.completed_at.strftime('%B %d, %Y %I:%M %p ET')
|
||||||
if inspection.completed_at else '—')
|
if inspection.completed_at else '—')
|
||||||
|
|
||||||
score_val = (f'{float(inspection.overall_score):.1f}%'
|
score_val = (f'{float(inspection.overall_score):.1f}%'
|
||||||
if inspection.overall_score is not None else '—')
|
if inspection.overall_score is not None else '—')
|
||||||
|
|
||||||
status_txt = inspection.status.replace('_', ' ').title()
|
status_txt = inspection.status.replace('_', ' ').title()
|
||||||
|
|
||||||
area_txt = inspection.area.name if inspection.area else '—'
|
area_txt = inspection.area.name if inspection.area else '—'
|
||||||
|
|
||||||
data = [
|
def lbl(text):
|
||||||
[cell('INSPECTOR', inspection.inspector.username),
|
return Paragraph(text, STYLES['MetaLabel'])
|
||||||
cell('DATE', date_str),
|
|
||||||
cell('TIME', time_str)],
|
def val(text):
|
||||||
[cell('FACILITY', inspection.facility.name),
|
return Paragraph(str(text), STYLES['MetaValue'])
|
||||||
cell('AREA', area_txt),
|
|
||||||
cell('COMPLETED', completed)],
|
# Each row: alternating label / value columns (6 cols total)
|
||||||
[cell('TEMPLATE', inspection.template.name),
|
rows = [
|
||||||
cell('FREQUENCY', inspection.template.frequency.title()),
|
[lbl('INSPECTOR'), val(inspection.inspector.username),
|
||||||
cell('STATUS / SCORE', f'{status_txt} {score_val}')],
|
lbl('DATE'), val(date_str),
|
||||||
|
lbl('TIME'), val(time_str)],
|
||||||
|
[lbl('FACILITY'), val(inspection.facility.name),
|
||||||
|
lbl('AREA'), val(area_txt),
|
||||||
|
lbl('COMPLETED'), val(completed)],
|
||||||
|
[lbl('TEMPLATE'), val(inspection.template.name),
|
||||||
|
lbl('FREQUENCY'), val(inspection.template.frequency.title()),
|
||||||
|
lbl('STATUS / SCORE'), val(f'{status_txt} {score_val}')],
|
||||||
]
|
]
|
||||||
|
|
||||||
# Flatten each inner list into a single-column cell using a mini Table
|
col_w = (letter[0] - 1.3 * inch) / 6
|
||||||
rows = []
|
tbl = Table(rows, colWidths=[col_w] * 6)
|
||||||
for row in data:
|
|
||||||
rows.append([Table([[item] for item in pair],
|
|
||||||
colWidths=[1.5 * inch],
|
|
||||||
style=TableStyle([
|
|
||||||
('VALIGN', (0, 0), (-1, -1), 'TOP'),
|
|
||||||
('LEFTPADDING', (0, 0), (-1, -1), 0),
|
|
||||||
('RIGHTPADDING', (0, 0), (-1, -1), 0),
|
|
||||||
('TOPPADDING', (0, 0), (-1, -1), 1),
|
|
||||||
('BOTTOMPADDING',(0, 0), (-1, -1), 1),
|
|
||||||
]))
|
|
||||||
for pair in row]
|
|
||||||
|
|
||||||
col_w = (letter[0] - 1.3 * inch) / 3
|
|
||||||
tbl = Table(rows, colWidths=[col_w] * 3)
|
|
||||||
tbl.setStyle(TableStyle([
|
tbl.setStyle(TableStyle([
|
||||||
('BACKGROUND', (0, 0), (-1, -1), C_LIGHT),
|
('BACKGROUND', (0, 0), (-1, -1), C_LIGHT),
|
||||||
('BOX', (0, 0), (-1, -1), 0.5, C_BORDER),
|
('BOX', (0, 0), (-1, -1), 0.5, C_BORDER),
|
||||||
@@ -202,8 +187,9 @@ def _meta_table(inspection):
|
|||||||
('VALIGN', (0, 0), (-1, -1), 'TOP'),
|
('VALIGN', (0, 0), (-1, -1), 'TOP'),
|
||||||
('LEFTPADDING', (0, 0), (-1, -1), 8),
|
('LEFTPADDING', (0, 0), (-1, -1), 8),
|
||||||
('RIGHTPADDING', (0, 0), (-1, -1), 8),
|
('RIGHTPADDING', (0, 0), (-1, -1), 8),
|
||||||
('TOPPADDING', (0, 0), (-1, -1), 6),
|
('TOPPADDING', (0, 0), (-1, -1), 5),
|
||||||
('BOTTOMPADDING',(0, 0), (-1, -1), 6),
|
('BOTTOMPADDING',(0, 0), (-1, -1), 5),
|
||||||
|
('TEXTCOLOR', (0, 0), (-1, -1), C_DARK),
|
||||||
]))
|
]))
|
||||||
return tbl
|
return tbl
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user