From 76bb83c55a194ccf4e435cc8707de04117f840c8 Mon Sep 17 00:00:00 2001 From: leonard_montalbano Date: Thu, 19 May 2022 16:17:27 +0200 Subject: [PATCH] =?UTF-8?q?=C3=A9bauche=20retour=20de=20bulletin=20pdf=20d?= =?UTF-8?q?'un=20formsemestre=20d'un=20etudiant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/etudiants.py | 16 ++++++---- app/scodoc/sco_bulletins_pdf.py | 53 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/app/api/etudiants.py b/app/api/etudiants.py index ee1c2fbb..1b11fa6f 100644 --- a/app/api/etudiants.py +++ b/app/api/etudiants.py @@ -18,6 +18,7 @@ from app.api.tools import get_last_instance_etud_from_etudid_or_nip_or_ine from app.models import Departement, FormSemestreInscription, FormSemestre, Identite from app.scodoc import sco_bulletins from app.scodoc import sco_groups +from app.scodoc.sco_bulletins_pdf import get_etud_bulletins_pdf, get_bulletin_etud_formsemestre from app.scodoc.sco_permissions import Permission @@ -230,11 +231,11 @@ def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None) defaults={"version": "long", "pdf": False}, ) # Version PDF non fonctionnelle -# @bp.route( -# "/etudiant/etudid//formsemestre//bulletin/pdf", -# methods=["GET"], -# defaults={"version": "long", "pdf": True}, -# ) +@bp.route( + "/etudiant/etudid//formsemestre//bulletin/pdf", + methods=["GET"], + defaults={"version": "long", "pdf": True}, +) # @bp.route( # "/etudiant/nip//formsemestre//bulletin/pdf", # methods=["GET"], @@ -461,6 +462,11 @@ def etudiant_bulletin_semestre( # XXX TODO Ajouter la possibilité de retourner ) app.set_sco_dept(dept.acronym) + + if pdf: + return get_bulletin_etud_formsemestre(etudid, formsemestre_id, version) + + return sco_bulletins.get_formsemestre_bulletin_etud_json( formsemestre, etud, version ) diff --git a/app/scodoc/sco_bulletins_pdf.py b/app/scodoc/sco_bulletins_pdf.py index 501bd98c..8d10b37f 100644 --- a/app/scodoc/sco_bulletins_pdf.py +++ b/app/scodoc/sco_bulletins_pdf.py @@ -271,6 +271,59 @@ def get_etud_bulletins_pdf(etudid, version="selectedevals"): return pdfdoc, filename +def get_bulletin_etud_formsemestre_pdf(etudid: int, formsemestre_id: int, version: str = "long"): + """ + Retourne le bulletin au format pdf d'un semestre d'un etudiant + + etudid : l'id de l'étudiant + formsemestre_id : l'id d'un semestre + """ + from app.scodoc import sco_bulletins + + etud = sco_etud.get_etud_info(etudid=etudid, filled=True)[0] + fragments = [] + bookmarks = {} + filigrannes = {} + + formsemestre = FormSemestre.query.get(formsemestre_id) + frag, filigranne = sco_bulletins.do_formsemestre_bulletinetud( + formsemestre, + etudid, + format="pdfpart", + version=version, + ) + # fragments += frag + # filigrannes[i] = filigranne + # bookmarks[i] = sem["session_id"] # eg RT-DUT-FI-S1-2015 + + infos = {"DeptName": sco_preferences.get_preference("DeptName")} + if request: + server_name = request.url_root + else: + server_name = "" + try: + sco_pdf.PDFLOCK.acquire() + pdfdoc = assemble_bulletins_pdf( + None, + fragments, + etud["nomprenom"], + infos, + bookmarks, + filigranne=filigrannes, + server_name=server_name, + ) + finally: + sco_pdf.PDFLOCK.release() + # + filename = "bul-%s" % (etud["nomprenom"]) + filename = ( + scu.unescape_html(filename).replace(" ", "_").replace("&", "").replace(".", "") + + ".pdf" + ) + + return pdfdoc, filename + + def get_filigranne(etud_etat: str, prefs, decision_sem=None) -> str: """Texte à placer en "filigranne" sur le bulletin pdf""" if etud_etat == scu.DEMISSION: