fixed cStringIO uses

This commit is contained in:
Emmanuel Viennet 2021-07-11 23:02:35 +02:00
parent 585e80e523
commit 49e95d0085
5 changed files with 21 additions and 12 deletions

View File

@ -43,9 +43,13 @@ La préférence 'bul_pdf_class_name' est obsolete (inutilisée).
""" """
import time import time
import cStringIO
import collections import collections
import traceback import traceback
try:
from io import StringIO # for Python 3
except ImportError:
from cStringIO import StringIO # for Python 2
import reportlab import reportlab
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Frame, PageBreak from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Frame, PageBreak
from reportlab.platypus import Table, TableStyle, Image, KeepInFrame from reportlab.platypus import Table, TableStyle, Image, KeepInFrame
@ -215,7 +219,7 @@ class BulletinGenerator(object):
else: else:
# Generation du document PDF # Generation du document PDF
sem = sco_formsemestre.get_formsemestre(self.context, formsemestre_id) sem = sco_formsemestre.get_formsemestre(self.context, formsemestre_id)
report = cStringIO.StringIO() # in-memory document, no disk file report = StringIO.StringIO() # in-memory document, no disk file
document = sco_pdf.BaseDocTemplate(report) document = sco_pdf.BaseDocTemplate(report)
document.addPageTemplates( document.addPageTemplates(
sco_pdf.ScolarsPageTemplate( sco_pdf.ScolarsPageTemplate(

View File

@ -54,8 +54,11 @@ import time
import traceback import traceback
import re import re
import os import os
import cStringIO
try:
from io import StringIO # for Python 3
except ImportError:
from cStringIO import StringIO # for Python 2
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate
from app.scodoc import VERSION from app.scodoc import VERSION
@ -89,7 +92,7 @@ def pdfassemblebulletins(
sco_preferences.get_preference(context, "bottom_margin", formsemestre_id), sco_preferences.get_preference(context, "bottom_margin", formsemestre_id),
) )
report = cStringIO.StringIO() # in-memory document, no disk file report = StringIO.StringIO() # in-memory document, no disk file
document = BaseDocTemplate(report) document = BaseDocTemplate(report)
document.addPageTemplates( document.addPageTemplates(
sco_pdf.ScolarsPageTemplate( sco_pdf.ScolarsPageTemplate(

View File

@ -36,7 +36,6 @@ Optimisation possible:
import time import time
import collections import collections
import re import re
import sets
import operator import operator
import xml.dom.minidom import xml.dom.minidom
@ -1274,7 +1273,7 @@ def groups_auto_repartition(context, partition_id=None, REQUEST=None):
) # > identdict ) # > identdict
identdict = nt.identdict identdict = nt.identdict
# build: { civilite : liste etudids trie par niveau croissant } # build: { civilite : liste etudids trie par niveau croissant }
civilites = sets.Set([x["civilite"] for x in identdict.values()]) civilites = set([x["civilite"] for x in identdict.values()])
listes = {} listes = {}
for civilite in civilites: for civilite in civilites:
listes[civilite] = [ listes[civilite] = [

View File

@ -314,7 +314,7 @@ def pdf_basic_page(
adding a title if specified. adding a title if specified.
""" """
StyleSheet = styles.getSampleStyleSheet() StyleSheet = styles.getSampleStyleSheet()
report = cStringIO.StringIO() # in-memory document, no disk file report = StringIO.StringIO() # in-memory document, no disk file
document = BaseDocTemplate(report) document = BaseDocTemplate(report)
document.addPageTemplates( document.addPageTemplates(
ScolarsPageTemplate( ScolarsPageTemplate(

View File

@ -28,9 +28,12 @@
"""Edition des PV de jury """Edition des PV de jury
""" """
import os import os
import types
import re import re
import cStringIO
try:
from io import StringIO # for Python 3
except ImportError:
from cStringIO import StringIO # for Python 2
import reportlab import reportlab
from reportlab.lib.units import cm, mm from reportlab.lib.units import cm, mm
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
@ -387,7 +390,7 @@ def pdf_lettres_individuelles(
) )
# ----- Build PDF # ----- Build PDF
report = cStringIO.StringIO() # in-memory document, no disk file report = StringIO.StringIO() # in-memory document, no disk file
document = BaseDocTemplate(report) document = BaseDocTemplate(report)
document.addPageTemplates( document.addPageTemplates(
CourrierIndividuelTemplate( CourrierIndividuelTemplate(
@ -587,7 +590,7 @@ def _make_signature_image(signature, leftindent, formsemestre_id, context=None):
# cree une image PIL pour avoir la taille (W,H) # cree une image PIL pour avoir la taille (W,H)
from PIL import Image as PILImage from PIL import Image as PILImage
f = cStringIO.StringIO(signature) f = StringIO.StringIO(signature)
im = PILImage.open(f) im = PILImage.open(f)
width, height = im.size width, height = im.size
pdfheight = ( pdfheight = (
@ -671,7 +674,7 @@ def pvjury_pdf(
) )
# ----- Build PDF # ----- Build PDF
report = cStringIO.StringIO() # in-memory document, no disk file report = StringIO.StringIO() # in-memory document, no disk file
document = BaseDocTemplate(report) document = BaseDocTemplate(report)
document.pagesize = landscape(A4) document.pagesize = landscape(A4)
document.addPageTemplates( document.addPageTemplates(