changeset 3d3d36549669 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=3d3d36549669
description:
        Add weasyprint support

        issue5964
        review266361002
diffstat:

 CHANGELOG                |   1 +
 setup.py                 |   1 +
 trytond/report/report.py |  10 ++++++++++
 3 files changed, 12 insertions(+), 0 deletions(-)

diffs (46 lines):

diff -r 173093bcb7b2 -r 3d3d36549669 CHANGELOG
--- a/CHANGELOG Mon Dec 02 11:35:47 2019 +0100
+++ b/CHANGELOG Tue Dec 03 18:40:28 2019 +0100
@@ -1,3 +1,4 @@
+* Add weasyprint support
 * Add slugify tool
 * Add is_secure, host and http_host to url module
 * Add __href__ to URLMixin
diff -r 173093bcb7b2 -r 3d3d36549669 setup.py
--- a/setup.py  Mon Dec 02 11:35:47 2019 +0100
+++ b/setup.py  Tue Dec 03 18:40:28 2019 +0100
@@ -155,6 +155,7 @@
         'Levenshtein': ['python-Levenshtein'],
         'BCrypt': ['passlib[bcrypt]'],
         'html2text': ['html2text'],
+        'weasyprint': ['weasyprint'],
         'coroutine': ['gevent>=1.1'],
         },
     zip_safe=False,
diff -r 173093bcb7b2 -r 3d3d36549669 trytond/report/report.py
--- a/trytond/report/report.py  Mon Dec 02 11:35:47 2019 +0100
+++ b/trytond/report/report.py  Tue Dec 03 18:40:28 2019 +0100
@@ -17,6 +17,11 @@
 except ImportError:
     html2text = None
 
+try:
+    import weasyprint
+except ImportError:
+    weasyprint = None
+
 warnings.simplefilter("ignore")
 import relatorio.reporting
 warnings.resetwarnings()
@@ -313,6 +318,11 @@
         input_format = report.template_extension
         output_format = report.extension or report.template_extension
 
+        if (weasyprint
+                and input_format in {'html', 'xhtml'}
+                and output_format == 'pdf'):
+            return output_format, weasyprint.HTML(string=data).write_pdf()
+
         if output_format in MIMETYPES:
             return output_format, data
 

Reply via email to