1
0
forked from ScoDoc/ScoDoc

support pdf generation in Python 3

This commit is contained in:
Emmanuel Viennet 2021-07-13 17:00:25 +02:00
parent 6a18188eda
commit 86f728b781
3 changed files with 57 additions and 64 deletions

View File

@ -804,18 +804,7 @@ def formsemestre_bulletinetud(
except:
return scu.log_unknown_etud(context, REQUEST, format=format)
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
R = []
if format == "html" or format == "pdfmail":
R.append(
_formsemestre_bulletinetud_header_html(
context, etud, etudid, sem, formsemestre_id, format, version, REQUEST
)
)
R.append(
do_formsemestre_bulletinetud(
bulletin = do_formsemestre_bulletinetud(
context,
formsemestre_id,
etudid,
@ -826,21 +815,29 @@ def formsemestre_bulletinetud(
prefer_mail_perso=prefer_mail_perso,
REQUEST=REQUEST,
)[0]
)
if format not in {"html", "pdfmail"}:
return bulletin
if format == "html" or format == "pdfmail":
R.append("""<p>Situation actuelle: """)
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
H = [
_formsemestre_bulletinetud_header_html(
context, etud, etudid, sem, formsemestre_id, format, version, REQUEST
),
bulletin,
]
H.append("""<p>Situation actuelle: """)
if etud["inscription_formsemestre_id"]:
R.append(
H.append(
"""<a class="stdlink" href="formsemestre_status?formsemestre_id=%s">"""
% etud["inscription_formsemestre_id"]
)
R.append(etud["inscriptionstr"])
H.append(etud["inscriptionstr"])
if etud["inscription_formsemestre_id"]:
R.append("""</a>""")
R.append("""</p>""")
H.append("""</a>""")
H.append("""</p>""")
if sem["modalite"] == "EXT":
R.append(
H.append(
"""<p><a
href="formsemestre_ext_edit_ue_validations?formsemestre_id=%s&etudid=%s"
class="stdlink">
@ -849,19 +846,19 @@ def formsemestre_bulletinetud(
% (formsemestre_id, etudid)
)
# Place du diagramme radar
R.append(
H.append(
"""<form id="params">
<input type="hidden" name="etudid" id="etudid" value="%s"/>
<input type="hidden" name="formsemestre_id" id="formsemestre_id" value="%s"/>
</form>"""
% (etudid, formsemestre_id)
)
R.append('<div id="radar_bulletin"></div>')
H.append('<div id="radar_bulletin"></div>')
# --- Pied de page
R.append(html_sco_header.sco_footer(context, REQUEST))
H.append(html_sco_header.sco_footer(context, REQUEST))
return "".join(R)
return "".join(H)
def can_send_bulletin_by_mail(context, formsemestre_id, REQUEST):

View File

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

View File

@ -77,16 +77,14 @@ DEFAULT_PDF_FOOTER_TEMPLATE = CONFIG.DEFAULT_PDF_FOOTER_TEMPLATE
def SU(s):
"convert s from SCO default encoding to UTF8"
# Mis en service le 4/11/06, passage à ReportLab 2.0
if not s:
s = ""
"convert s from string to string suitable for ReportLab"
# A priori inutile en Python 3, mais tester les "combining accents"
return s or ""
# Remplace caractères composés
# eg 'e\xcc\x81' COMBINING ACUTE ACCENT par '\xc3\xa9' LATIN SMALL LETTER E WITH ACUTE
# car les "combining accents" ne sont pas traités par ReportLab mais peuvent
# nous être envoyés par certains navigateurs ou imports
u = unicodedata.normalize("NFC", six.text_type(s, SCO_ENCODING, "replace"))
return u.encode("utf8")
# return unicodedata.normalize("NFC", s)
def _splitPara(txt):