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,64 +804,61 @@ def formsemestre_bulletinetud(
except:
return scu.log_unknown_etud(context, REQUEST, format=format)
bulletin = do_formsemestre_bulletinetud(
context,
formsemestre_id,
etudid,
format=format,
version=version,
xml_with_decisions=xml_with_decisions,
force_publishing=force_publishing,
prefer_mail_perso=prefer_mail_perso,
REQUEST=REQUEST,
)[0]
if format not in {"html", "pdfmail"}:
return bulletin
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
H = [
_formsemestre_bulletinetud_header_html(
context, etud, etudid, sem, formsemestre_id, format, version, REQUEST
),
bulletin,
]
R = []
if format == "html" or format == "pdfmail":
R.append(
_formsemestre_bulletinetud_header_html(
context, etud, etudid, sem, formsemestre_id, format, version, REQUEST
)
H.append("""<p>Situation actuelle: """)
if etud["inscription_formsemestre_id"]:
H.append(
"""<a class="stdlink" href="formsemestre_status?formsemestre_id=%s">"""
% etud["inscription_formsemestre_id"]
)
R.append(
do_formsemestre_bulletinetud(
context,
formsemestre_id,
etudid,
format=format,
version=version,
xml_with_decisions=xml_with_decisions,
force_publishing=force_publishing,
prefer_mail_perso=prefer_mail_perso,
REQUEST=REQUEST,
)[0]
H.append(etud["inscriptionstr"])
if etud["inscription_formsemestre_id"]:
H.append("""</a>""")
H.append("""</p>""")
if sem["modalite"] == "EXT":
H.append(
"""<p><a
href="formsemestre_ext_edit_ue_validations?formsemestre_id=%s&etudid=%s"
class="stdlink">
Editer les validations d'UE dans ce semestre extérieur
</a></p>"""
% (formsemestre_id, etudid)
)
# Place du diagramme radar
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)
)
H.append('<div id="radar_bulletin"></div>')
if format == "html" or format == "pdfmail":
R.append("""<p>Situation actuelle: """)
if etud["inscription_formsemestre_id"]:
R.append(
"""<a class="stdlink" href="formsemestre_status?formsemestre_id=%s">"""
% etud["inscription_formsemestre_id"]
)
R.append(etud["inscriptionstr"])
if etud["inscription_formsemestre_id"]:
R.append("""</a>""")
R.append("""</p>""")
if sem["modalite"] == "EXT":
R.append(
"""<p><a
href="formsemestre_ext_edit_ue_validations?formsemestre_id=%s&etudid=%s"
class="stdlink">
Editer les validations d'UE dans ce semestre extérieur
</a></p>"""
% (formsemestre_id, etudid)
)
# Place du diagramme radar
R.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>')
# --- Pied de page
H.append(html_sco_header.sco_footer(context, REQUEST))
# --- Pied de page
R.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):