From b0717e35e0e0aedb9fedc1667da73385113dfd0d Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 13 Jul 2021 22:07:59 +0200 Subject: [PATCH] fix pdf code for py3 --- app/scodoc/sco_pvpdf.py | 13 +++++-------- app/views/notes.py | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/scodoc/sco_pvpdf.py b/app/scodoc/sco_pvpdf.py index 315aedec7..623adaa43 100644 --- a/app/scodoc/sco_pvpdf.py +++ b/app/scodoc/sco_pvpdf.py @@ -27,13 +27,10 @@ """Edition des PV de jury """ +import io import os import re -try: - from io import StringIO # for Python 3 -except ImportError: - from cStringIO import StringIO # for Python 2 import reportlab from reportlab.lib.units import cm, mm from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY @@ -390,7 +387,7 @@ def pdf_lettres_individuelles( ) # ----- Build PDF - report = StringIO.StringIO() # in-memory document, no disk file + report = io.BytesIO() # in-memory document, no disk file document = BaseDocTemplate(report) document.addPageTemplates( CourrierIndividuelTemplate( @@ -590,7 +587,7 @@ def _make_signature_image(signature, leftindent, formsemestre_id, context=None): # cree une image PIL pour avoir la taille (W,H) from PIL import Image as PILImage - f = StringIO.StringIO(signature) + f = io.BytesIO(signature) im = PILImage.open(f) width, height = im.size pdfheight = ( @@ -674,7 +671,7 @@ def pvjury_pdf( ) # ----- Build PDF - report = StringIO.StringIO() # in-memory document, no disk file + report = io.BytesIO() # in-memory document, no disk file document = BaseDocTemplate(report) document.pagesize = landscape(A4) document.addPageTemplates( @@ -838,7 +835,7 @@ def _pvjury_pdf_type( def _format_pv_cell(x): """convert string to paragraph""" - if isinstance(x, bytes): + if isinstance(x, str): return Paragraph(SU(x), cell_style) else: return x diff --git a/app/views/notes.py b/app/views/notes.py index 2067981de..38095a1ad 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -2218,6 +2218,7 @@ sco_publish( "/formsemestre_lettres_individuelles", sco_pvjury.formsemestre_lettres_individuelles, Permission.ScoView, + methods=["GET", "POST"], ) sco_publish( "/formsemestre_pvjury_pdf", sco_pvjury.formsemestre_pvjury_pdf, Permission.ScoView