forked from ScoDoc/ScoDoc
support pdf generation in Python 3
This commit is contained in:
parent
6a18188eda
commit
86f728b781
@ -804,64 +804,61 @@ def formsemestre_bulletinetud(
|
|||||||
except:
|
except:
|
||||||
return scu.log_unknown_etud(context, REQUEST, format=format)
|
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)
|
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
|
||||||
|
H = [
|
||||||
|
_formsemestre_bulletinetud_header_html(
|
||||||
|
context, etud, etudid, sem, formsemestre_id, format, version, REQUEST
|
||||||
|
),
|
||||||
|
bulletin,
|
||||||
|
]
|
||||||
|
|
||||||
R = []
|
H.append("""<p>Situation actuelle: """)
|
||||||
if format == "html" or format == "pdfmail":
|
if etud["inscription_formsemestre_id"]:
|
||||||
R.append(
|
H.append(
|
||||||
_formsemestre_bulletinetud_header_html(
|
"""<a class="stdlink" href="formsemestre_status?formsemestre_id=%s">"""
|
||||||
context, etud, etudid, sem, formsemestre_id, format, version, REQUEST
|
% etud["inscription_formsemestre_id"]
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
H.append(etud["inscriptionstr"])
|
||||||
R.append(
|
if etud["inscription_formsemestre_id"]:
|
||||||
do_formsemestre_bulletinetud(
|
H.append("""</a>""")
|
||||||
context,
|
H.append("""</p>""")
|
||||||
formsemestre_id,
|
if sem["modalite"] == "EXT":
|
||||||
etudid,
|
H.append(
|
||||||
format=format,
|
"""<p><a
|
||||||
version=version,
|
href="formsemestre_ext_edit_ue_validations?formsemestre_id=%s&etudid=%s"
|
||||||
xml_with_decisions=xml_with_decisions,
|
class="stdlink">
|
||||||
force_publishing=force_publishing,
|
Editer les validations d'UE dans ce semestre extérieur
|
||||||
prefer_mail_perso=prefer_mail_perso,
|
</a></p>"""
|
||||||
REQUEST=REQUEST,
|
% (formsemestre_id, etudid)
|
||||||
)[0]
|
)
|
||||||
|
# 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":
|
# --- Pied de page
|
||||||
R.append("""<p>Situation actuelle: """)
|
H.append(html_sco_header.sco_footer(context, REQUEST))
|
||||||
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
|
return "".join(H)
|
||||||
R.append(html_sco_header.sco_footer(context, REQUEST))
|
|
||||||
|
|
||||||
return "".join(R)
|
|
||||||
|
|
||||||
|
|
||||||
def can_send_bulletin_by_mail(context, formsemestre_id, REQUEST):
|
def can_send_bulletin_by_mail(context, formsemestre_id, REQUEST):
|
||||||
|
@ -42,14 +42,12 @@ La préférence 'bul_pdf_class_name' est obsolete (inutilisée).
|
|||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import time
|
|
||||||
import collections
|
import collections
|
||||||
|
import io
|
||||||
|
import time
|
||||||
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
|
||||||
@ -219,7 +217,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 = StringIO.StringIO() # in-memory document, no disk file
|
report = io.BytesIO() # 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(
|
||||||
|
@ -77,16 +77,14 @@ DEFAULT_PDF_FOOTER_TEMPLATE = CONFIG.DEFAULT_PDF_FOOTER_TEMPLATE
|
|||||||
|
|
||||||
|
|
||||||
def SU(s):
|
def SU(s):
|
||||||
"convert s from SCO default encoding to UTF8"
|
"convert s from string to string suitable for ReportLab"
|
||||||
# Mis en service le 4/11/06, passage à ReportLab 2.0
|
# A priori inutile en Python 3, mais tester les "combining accents"
|
||||||
if not s:
|
return s or ""
|
||||||
s = ""
|
|
||||||
# Remplace caractères composés
|
# Remplace caractères composés
|
||||||
# eg 'e\xcc\x81' COMBINING ACUTE ACCENT par '\xc3\xa9' LATIN SMALL LETTER E WITH ACUTE
|
# 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
|
# car les "combining accents" ne sont pas traités par ReportLab mais peuvent
|
||||||
# nous être envoyés par certains navigateurs ou imports
|
# nous être envoyés par certains navigateurs ou imports
|
||||||
u = unicodedata.normalize("NFC", six.text_type(s, SCO_ENCODING, "replace"))
|
# return unicodedata.normalize("NFC", s)
|
||||||
return u.encode("utf8")
|
|
||||||
|
|
||||||
|
|
||||||
def _splitPara(txt):
|
def _splitPara(txt):
|
||||||
|
Loading…
Reference in New Issue
Block a user