05/26 Fix exported PDF form layout broken 2

This commit is contained in:
2026-05-26 14:45:28 -04:00
parent 7520059d44
commit 6286f95e1c
+16 -7
View File
@@ -913,18 +913,27 @@ def export_pdf(inspection_id):
flash('Access denied.', 'danger') flash('Access denied.', 'danger')
return redirect(url_for('inspections.index')) return redirect(url_for('inspections.index'))
template = inspection.template template = inspection.template
form_fields = sorted(template.get_form_schema(),
key=lambda f: (f.get('row', 0), f.get('col', 0)))
form_data = {} # Use the snapshot saved at submission time (same source as view()) so the
# PDF reflects the exact template the inspector saw, not a later revision.
form_fields = None
form_data = {}
if inspection.notes: if inspection.notes:
try: try:
parsed = json.loads(inspection.notes) _snap = json.loads(inspection.notes)
if isinstance(parsed, dict): if isinstance(_snap, dict):
form_data = parsed.get('_form_data', {}) if '_template_schema' in _snap:
form_fields = sorted(
_snap['_template_schema'],
key=lambda f: (f.get('row', 0), f.get('col', 0)),
)
form_data = _snap.get('_form_data') or {}
except (json.JSONDecodeError, TypeError): except (json.JSONDecodeError, TypeError):
pass pass
if form_fields is None:
form_fields = sorted(template.get_form_schema(),
key=lambda f: (f.get('row', 0), f.get('col', 0)))
issues = inspection.issues.order_by(Issue.reported_at.desc()).all() issues = inspection.issues.order_by(Issue.reported_at.desc()).all()
static_folder = os.path.join(current_app.root_path, 'static') static_folder = os.path.join(current_app.root_path, 'static')