lims_report_html: add page_orientation field on lims.result_report.template

This commit is contained in:
Francisco Moyano 2021-06-02 09:57:01 -03:00 committed by Sebastián Marró
parent f967d22cc9
commit a4c27c73dc
5 changed files with 36 additions and 7 deletions

View File

@ -9,7 +9,7 @@ class PdfGenerator:
def __init__(self, main_html, header_html=None, footer_html=None,
base_url=None, side_margin=2, extra_vertical_margin=30,
stylesheets=None):
stylesheets=None, page_orientation='portrait'):
self.main_html = main_html
self.header_html = header_html
self.footer_html = footer_html
@ -17,6 +17,7 @@ class PdfGenerator:
self.side_margin = side_margin
self.extra_vertical_margin = extra_vertical_margin
self.stylesheets = stylesheets or []
self.page_orientation = page_orientation
@staticmethod
def get_element(boxes, element):
@ -43,8 +44,10 @@ class PdfGenerator:
footer_size=footer_height + self.extra_vertical_margin,
side_margin='{}cm'.format(self.side_margin),
)
content_print_layout = ('@page {size: A4 portrait; margin: %s;}' %
content_print_layout = ('@page {size: A4 %s; margin: %s;}' %
(self.page_orientation,
margins)
)
stylesheets = [CSS(string=content_print_layout)]
for sheet in self.stylesheets:
stylesheets.append(CSS(string=sheet))
@ -62,7 +65,7 @@ class PdfGenerator:
def _compute_overlay_element(self, element: str):
overlay_layout = (
'@page {size: A4 portrait; margin: 0;}' +
'@page {size: A4 %s; margin: 0;}' % self.page_orientation +
'\nheader {position: fixed; width: 100%; top: 0;}' +
'\nfooter {position: fixed; width: 100%; bottom: 0;}')
stylesheets = [CSS(string=overlay_layout)]

View File

@ -58,6 +58,10 @@ class ReportTemplate(ModelSQL, ModelView):
('1', '1'),
('2', '2'),
], 'Charts per Row')
page_orientation = fields.Selection([
('portrait', 'Portrait'),
('landscape','Landscape'),
],'Page orientation',sort=False)
@staticmethod
def default_type():
@ -67,6 +71,10 @@ class ReportTemplate(ModelSQL, ModelView):
def default_charts_x_row():
return '1'
@staticmethod
def default_page_orientation():
return 'portrait'
@classmethod
def view_attributes(cls):
return super().view_attributes() + [

View File

@ -70,6 +70,10 @@ msgctxt "field:lims.result_report.template,type:"
msgid "Type"
msgstr "Tipo"
msgctxt "field:lims.result_report.template,page_orientation:"
msgid "Page orientation"
msgstr "Orientación de la página"
msgctxt "field:lims.result_report.template.section,data:"
msgid "File"
msgstr "Archivo"
@ -278,6 +282,14 @@ msgctxt "selection:lims.result_report.template,type:"
msgid "HTML - Header"
msgstr "HTML - Encabezado"
msgctxt "selection:lims.result_report.template,page_orientation:"
msgid "Portrait"
msgstr "Vertical"
msgctxt "selection:lims.result_report.template,page_orientation:"
msgid "Landscape"
msgstr "Horizontal"
msgctxt "selection:lims.result_report.template.section,position:"
msgid "Following"
msgstr "Siguiente"

View File

@ -346,15 +346,15 @@ class ResultsReportVersionDetailSample(metaclass=PoolMeta):
continue
if count == 0:
content += div_row
content += div_row
content += div_col
if attachment.title:
content += '<p style="font-size: 6pt;font-family: arial,\
helvetica, sans-serif;">%s</p>' % (
attachment.title, )
content += ('<img src="' +
ResultReport.get_image(attachment.data) +
'" alt="" style="width:100%;">')
@ -499,16 +499,20 @@ class ResultReport(metaclass=PoolMeta):
footer = tfooter and cls.render_results_report_template(action,
tfooter, record=record, records=[record],
data=data)
stylesheets = cls.parse_stylesheets(tcontent)
if theader:
stylesheets += cls.parse_stylesheets(theader)
if tfooter:
stylesheets += cls.parse_stylesheets(tfooter)
page_orientation = record.template and record.template.page_orientation or 'portrait'
document = PdfGenerator(content,
header_html=header, footer_html=footer,
side_margin=1, extra_vertical_margin=30,
stylesheets=stylesheets).render_html().write_pdf()
stylesheets=stylesheets,
page_orientation=page_orientation).render_html().write_pdf()
if record.previous_sections or record.following_sections:
merger = PdfFileMerger(strict=False)

View File

@ -6,6 +6,8 @@
<field name="type"/>
<label name="report"/>
<field name="report"/>
<label name="page_orientation"/>
<field name="page_orientation"/>
<notebook>
<page name="content">
<field name="content" colspan="4" widget="html"/>