Fix: bytes I/O (zips and pdfs)

This commit is contained in:
Emmanuel Viennet 2021-07-26 18:11:00 +03:00
parent c3e3f45370
commit 0252bf4df4
2 changed files with 8 additions and 8 deletions

View File

@ -28,7 +28,7 @@
"""Photos: trombinoscopes
"""
from io import StringIO
import io
from zipfile import ZipFile, BadZipfile
import reportlab
from reportlab.lib.units import cm, mm
@ -221,7 +221,7 @@ def check_local_photos_availability(context, groups_infos, REQUEST, format=""):
def _trombino_zip(context, groups_infos, REQUEST):
"Send photos as zip archive"
data = StringIO()
data = io.BytesIO()
Z = ZipFile(data, "w")
# assume we have the photos (or the user acknowledged the fact)
# Archive originals (not reduced) images, in JPEG
@ -229,7 +229,7 @@ def _trombino_zip(context, groups_infos, REQUEST):
im_path = sco_photos.photo_pathname(context, t, size="orig")
if not im_path:
continue
img = open(im_path).read()
img = open(im_path, "rb").read()
code_nip = t["code_nip"]
if code_nip:
filename = code_nip + ".jpg"
@ -337,7 +337,7 @@ def _trombino_pdf(context, groups_infos, REQUEST):
N_PER_ROW = 5 # XXX should be in ScoDoc preferences
StyleSheet = styles.getSampleStyleSheet()
report = StringIO() # in-memory document, no disk file
report = io.BytesIO() # in-memory document, no disk file
objects = [
Paragraph(
SU("Trombinoscope " + sem["titreannee"] + " " + groups_infos.groups_titles),
@ -411,7 +411,7 @@ def _listeappel_photos_pdf(context, groups_infos, REQUEST):
# ROWS_PER_PAGE = 26 # XXX should be in ScoDoc preferences
StyleSheet = styles.getSampleStyleSheet()
report = StringIO() # in-memory document, no disk file
report = io.BytesIO() # in-memory document, no disk file
objects = [
Paragraph(
SU(

View File

@ -30,7 +30,7 @@
Modification Jérome Billoue,Vincent Grimaud, IUT de Tours, 2017
"""
from io import StringIO
import io
from reportlab.lib import colors
from reportlab.lib import pagesizes
@ -265,7 +265,7 @@ def pdf_trombino_tours(
# Réduit sur une page
objects = [KeepInFrame(0, 0, objects, mode="shrink")]
# Build document
report = StringIO() # in-memory document, no disk file
report = io.BytesIO() # in-memory document, no disk file
filename = "trombino-%s-%s.pdf" % (DeptName, groups_infos.groups_filename)
document = BaseDocTemplate(report)
document.addPageTemplates(
@ -456,7 +456,7 @@ def pdf_feuille_releve_absences(
# Réduit sur une page
objects = [KeepInFrame(0, 0, objects, mode="shrink")]
# Build document
report = StringIO() # in-memory document, no disk file
report = io.BytesIO() # in-memory document, no disk file
filename = "absences-%s-%s.pdf" % (DeptName, groups_infos.groups_filename)
if sco_preferences.get_preference(context, "feuille_releve_abs_taille") == "A3":
taille = A3