1
0
forked from ScoDoc/ScoDoc

fix pdf code for py3

This commit is contained in:
Emmanuel Viennet 2021-07-13 22:07:59 +02:00
parent 86f728b781
commit b0717e35e0
2 changed files with 6 additions and 8 deletions

View File

@ -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

View File

@ -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