Feb 02 2026: fixed PDF report converter issue

This commit is contained in:
2026-02-28 15:06:44 -05:00
parent 118a2a194d
commit c6707c643f
+33 -47
View File
@@ -149,61 +149,47 @@ 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 [ date_str = inspection.inspection_date.strftime('%B %d, %Y')
Paragraph(label, STYLES['MetaLabel']), time_str = inspection.inspection_date.strftime('%I:%M %p ET')
Paragraph(str(value), STYLES['MetaValue']), completed = (inspection.completed_at.strftime('%B %d, %Y %I:%M %p ET')
] if inspection.completed_at else '')
score_val = (f'{float(inspection.overall_score):.1f}%'
date_str = inspection.inspection_date.strftime('%B %d, %Y') if inspection.overall_score is not None else '')
time_str = inspection.inspection_date.strftime('%I:%M %p ET')
completed = (inspection.completed_at.strftime('%B %d, %Y %I:%M %p ET')
if inspection.completed_at else '')
score_val = (f'{float(inspection.overall_score):.1f}%'
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 '' def lbl(text):
return Paragraph(text, STYLES['MetaLabel'])
data = [ def val(text):
[cell('INSPECTOR', inspection.inspector.username), return Paragraph(str(text), STYLES['MetaValue'])
cell('DATE', date_str),
cell('TIME', time_str)], # Each row: alternating label / value columns (6 cols total)
[cell('FACILITY', inspection.facility.name), rows = [
cell('AREA', area_txt), [lbl('INSPECTOR'), val(inspection.inspector.username),
cell('COMPLETED', completed)], lbl('DATE'), val(date_str),
[cell('TEMPLATE', inspection.template.name), lbl('TIME'), val(time_str)],
cell('FREQUENCY', inspection.template.frequency.title()), [lbl('FACILITY'), val(inspection.facility.name),
cell('STATUS / SCORE', f'{status_txt} {score_val}')], 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),
('INNERGRID', (0, 0), (-1, -1), 0.5, C_BORDER), ('INNERGRID', (0, 0), (-1, -1), 0.5, C_BORDER),
('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