lims_report_html: extend use of report templates (2)

This commit is contained in:
Adrián Bernardi 2023-08-10 09:22:22 -03:00
parent 0bbdddf87a
commit 3c0c317d3f
1 changed files with 30 additions and 20 deletions

View File

@ -377,23 +377,27 @@ class LimsReport:
content = bytearray(content) if bytes == str else bytes(content) content = bytearray(content) if bytes == str else bytes(content)
record = records[0] record = records[0]
if oext == 'pdf' and (record.previous_sections or if oext == 'pdf':
record.following_sections): previous_sections = (hasattr(record, 'previous_sections') and
merger = PdfFileMerger(strict=False) record.previous_sections or [])
# Previous Sections following_sections = (hasattr(record, 'following_sections') and
for section in record.previous_sections: record.following_sections or [])
filedata = BytesIO(section.data) if previous_sections or following_sections:
merger = PdfFileMerger(strict=False)
# Previous Sections
for section in previous_sections:
filedata = BytesIO(section.data)
merger.append(filedata)
# Main Report
filedata = BytesIO(content)
merger.append(filedata) merger.append(filedata)
# Main Report # Following Sections
filedata = BytesIO(content) for section in following_sections:
merger.append(filedata) filedata = BytesIO(section.data)
# Following Sections merger.append(filedata)
for section in record.following_sections: output = BytesIO()
filedata = BytesIO(section.data) merger.write(output)
merger.append(filedata) content = output.getvalue()
output = BytesIO()
merger.write(output)
content = output.getvalue()
return (oext, content, action.direct_print, action.name) return (oext, content, action.direct_print, action.name)
@ -454,10 +458,16 @@ class LimsReport:
stylesheets=stylesheets, stylesheets=stylesheets,
page_orientation=page_orientation).render_html().write_pdf() page_orientation=page_orientation).render_html().write_pdf()
previous_sections = (hasattr(record, 'previous_sections') and previous_sections = []
record.previous_sections or []) if hasattr(record, 'previous_sections'):
following_sections = (hasattr(record, 'following_sections') and previous_sections = record.previous_sections
record.following_sections or []) elif template:
previous_sections = template.previous_sections
following_sections = []
if hasattr(record, 'following_sections'):
following_sections = record.following_sections
elif template:
following_sections = template.following_sections
if previous_sections or following_sections: if previous_sections or following_sections:
merger = PdfFileMerger(strict=False) merger = PdfFileMerger(strict=False)
# Previous Sections # Previous Sections