lims_report_html: add page_orientation field on lims.result_report.template
This commit is contained in:
parent
f967d22cc9
commit
a4c27c73dc
|
@ -9,7 +9,7 @@ class PdfGenerator:
|
||||||
|
|
||||||
def __init__(self, main_html, header_html=None, footer_html=None,
|
def __init__(self, main_html, header_html=None, footer_html=None,
|
||||||
base_url=None, side_margin=2, extra_vertical_margin=30,
|
base_url=None, side_margin=2, extra_vertical_margin=30,
|
||||||
stylesheets=None):
|
stylesheets=None, page_orientation='portrait'):
|
||||||
self.main_html = main_html
|
self.main_html = main_html
|
||||||
self.header_html = header_html
|
self.header_html = header_html
|
||||||
self.footer_html = footer_html
|
self.footer_html = footer_html
|
||||||
|
@ -17,6 +17,7 @@ class PdfGenerator:
|
||||||
self.side_margin = side_margin
|
self.side_margin = side_margin
|
||||||
self.extra_vertical_margin = extra_vertical_margin
|
self.extra_vertical_margin = extra_vertical_margin
|
||||||
self.stylesheets = stylesheets or []
|
self.stylesheets = stylesheets or []
|
||||||
|
self.page_orientation = page_orientation
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_element(boxes, element):
|
def get_element(boxes, element):
|
||||||
|
@ -43,8 +44,10 @@ class PdfGenerator:
|
||||||
footer_size=footer_height + self.extra_vertical_margin,
|
footer_size=footer_height + self.extra_vertical_margin,
|
||||||
side_margin='{}cm'.format(self.side_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)
|
margins)
|
||||||
|
)
|
||||||
stylesheets = [CSS(string=content_print_layout)]
|
stylesheets = [CSS(string=content_print_layout)]
|
||||||
for sheet in self.stylesheets:
|
for sheet in self.stylesheets:
|
||||||
stylesheets.append(CSS(string=sheet))
|
stylesheets.append(CSS(string=sheet))
|
||||||
|
@ -62,7 +65,7 @@ class PdfGenerator:
|
||||||
|
|
||||||
def _compute_overlay_element(self, element: str):
|
def _compute_overlay_element(self, element: str):
|
||||||
overlay_layout = (
|
overlay_layout = (
|
||||||
'@page {size: A4 portrait; margin: 0;}' +
|
'@page {size: A4 %s; margin: 0;}' % self.page_orientation +
|
||||||
'\nheader {position: fixed; width: 100%; top: 0;}' +
|
'\nheader {position: fixed; width: 100%; top: 0;}' +
|
||||||
'\nfooter {position: fixed; width: 100%; bottom: 0;}')
|
'\nfooter {position: fixed; width: 100%; bottom: 0;}')
|
||||||
stylesheets = [CSS(string=overlay_layout)]
|
stylesheets = [CSS(string=overlay_layout)]
|
||||||
|
|
|
@ -58,6 +58,10 @@ class ReportTemplate(ModelSQL, ModelView):
|
||||||
('1', '1'),
|
('1', '1'),
|
||||||
('2', '2'),
|
('2', '2'),
|
||||||
], 'Charts per Row')
|
], 'Charts per Row')
|
||||||
|
page_orientation = fields.Selection([
|
||||||
|
('portrait', 'Portrait'),
|
||||||
|
('landscape','Landscape'),
|
||||||
|
],'Page orientation',sort=False)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def default_type():
|
def default_type():
|
||||||
|
@ -67,6 +71,10 @@ class ReportTemplate(ModelSQL, ModelView):
|
||||||
def default_charts_x_row():
|
def default_charts_x_row():
|
||||||
return '1'
|
return '1'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def default_page_orientation():
|
||||||
|
return 'portrait'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def view_attributes(cls):
|
def view_attributes(cls):
|
||||||
return super().view_attributes() + [
|
return super().view_attributes() + [
|
||||||
|
|
|
@ -70,6 +70,10 @@ msgctxt "field:lims.result_report.template,type:"
|
||||||
msgid "Type"
|
msgid "Type"
|
||||||
msgstr "Tipo"
|
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:"
|
msgctxt "field:lims.result_report.template.section,data:"
|
||||||
msgid "File"
|
msgid "File"
|
||||||
msgstr "Archivo"
|
msgstr "Archivo"
|
||||||
|
@ -278,6 +282,14 @@ msgctxt "selection:lims.result_report.template,type:"
|
||||||
msgid "HTML - Header"
|
msgid "HTML - Header"
|
||||||
msgstr "HTML - Encabezado"
|
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:"
|
msgctxt "selection:lims.result_report.template.section,position:"
|
||||||
msgid "Following"
|
msgid "Following"
|
||||||
msgstr "Siguiente"
|
msgstr "Siguiente"
|
||||||
|
|
|
@ -346,15 +346,15 @@ class ResultsReportVersionDetailSample(metaclass=PoolMeta):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if count == 0:
|
if count == 0:
|
||||||
content += div_row
|
content += div_row
|
||||||
|
|
||||||
content += div_col
|
content += div_col
|
||||||
|
|
||||||
if attachment.title:
|
if attachment.title:
|
||||||
content += '<p style="font-size: 6pt;font-family: arial,\
|
content += '<p style="font-size: 6pt;font-family: arial,\
|
||||||
helvetica, sans-serif;">%s</p>' % (
|
helvetica, sans-serif;">%s</p>' % (
|
||||||
attachment.title, )
|
attachment.title, )
|
||||||
|
|
||||||
content += ('<img src="' +
|
content += ('<img src="' +
|
||||||
ResultReport.get_image(attachment.data) +
|
ResultReport.get_image(attachment.data) +
|
||||||
'" alt="" style="width:100%;">')
|
'" alt="" style="width:100%;">')
|
||||||
|
@ -499,16 +499,20 @@ class ResultReport(metaclass=PoolMeta):
|
||||||
footer = tfooter and cls.render_results_report_template(action,
|
footer = tfooter and cls.render_results_report_template(action,
|
||||||
tfooter, record=record, records=[record],
|
tfooter, record=record, records=[record],
|
||||||
data=data)
|
data=data)
|
||||||
|
|
||||||
stylesheets = cls.parse_stylesheets(tcontent)
|
stylesheets = cls.parse_stylesheets(tcontent)
|
||||||
if theader:
|
if theader:
|
||||||
stylesheets += cls.parse_stylesheets(theader)
|
stylesheets += cls.parse_stylesheets(theader)
|
||||||
if tfooter:
|
if tfooter:
|
||||||
stylesheets += cls.parse_stylesheets(tfooter)
|
stylesheets += cls.parse_stylesheets(tfooter)
|
||||||
|
|
||||||
|
page_orientation = record.template and record.template.page_orientation or 'portrait'
|
||||||
|
|
||||||
document = PdfGenerator(content,
|
document = PdfGenerator(content,
|
||||||
header_html=header, footer_html=footer,
|
header_html=header, footer_html=footer,
|
||||||
side_margin=1, extra_vertical_margin=30,
|
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:
|
if record.previous_sections or record.following_sections:
|
||||||
merger = PdfFileMerger(strict=False)
|
merger = PdfFileMerger(strict=False)
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
<field name="type"/>
|
<field name="type"/>
|
||||||
<label name="report"/>
|
<label name="report"/>
|
||||||
<field name="report"/>
|
<field name="report"/>
|
||||||
|
<label name="page_orientation"/>
|
||||||
|
<field name="page_orientation"/>
|
||||||
<notebook>
|
<notebook>
|
||||||
<page name="content">
|
<page name="content">
|
||||||
<field name="content" colspan="4" widget="html"/>
|
<field name="content" colspan="4" widget="html"/>
|
||||||
|
|
Loading…
Reference in New Issue