forked from ScoDoc/ScoDoc
Classeur PDF des bulletins BUT courts
This commit is contained in:
parent
78fbaf1ac8
commit
0f860f912c
@ -65,6 +65,38 @@ def bulletin_but(formsemestre_id: int, etudid: int = None, fmt="html"):
|
||||
)
|
||||
if not formsemestre.formation.is_apc():
|
||||
raise ScoValueError("formation non BUT")
|
||||
|
||||
args = _build_bulletin_but_infos(etud, formsemestre, fmt=fmt)
|
||||
|
||||
if fmt == "pdf":
|
||||
filename = scu.bul_filename(formsemestre, etud, prefix="bul-but")
|
||||
bul_pdf = bulletin_but_court_pdf.make_bulletin_but_court_pdf(args)
|
||||
return scu.sendPDFFile(bul_pdf, filename + ".pdf")
|
||||
|
||||
return render_template(
|
||||
"but/bulletin_court_page.j2",
|
||||
datetime=datetime,
|
||||
sco=ScoData(formsemestre=formsemestre, etud=etud),
|
||||
time=time,
|
||||
version="butcourt",
|
||||
**args,
|
||||
)
|
||||
|
||||
|
||||
def bulletin_but_court_pdf_frag(etud: Identite, formsemestre: FormSemestre) -> bytes:
|
||||
"""Le code PDF d'un bulletin BUT court, à intégrer dans un document
|
||||
(pour les classeurs de tous les bulletins)
|
||||
"""
|
||||
args = _build_bulletin_but_infos(etud, formsemestre)
|
||||
return bulletin_but_court_pdf.make_bulletin_but_court_pdf(args, stand_alone=False)
|
||||
|
||||
|
||||
def _build_bulletin_but_infos(
|
||||
etud: Identite, formsemestre: FormSemestre, fmt="pdf"
|
||||
) -> dict:
|
||||
"""Réuni toutes les information pour le contenu d'un bulletin BUT court.
|
||||
On indique le format ("html" ou "pdf") car il y a moins d'infos en HTML.
|
||||
"""
|
||||
bulletins_sem = BulletinBUT(formsemestre)
|
||||
if fmt == "pdf":
|
||||
bul: dict = bulletins_sem.bulletin_etud_complet(etud)
|
||||
@ -106,16 +138,4 @@ def bulletin_but(formsemestre_id: int, etudid: int = None, fmt="html"):
|
||||
if ue.type == UE_STANDARD and ue.acronyme in ue_acronyms
|
||||
],
|
||||
}
|
||||
if fmt == "pdf":
|
||||
filename = scu.bul_filename(formsemestre, etud, prefix="bul-but")
|
||||
bul_pdf = bulletin_but_court_pdf.make_bulletin_but_court_pdf(**args)
|
||||
return scu.sendPDFFile(bul_pdf, filename + ".pdf")
|
||||
|
||||
return render_template(
|
||||
"but/bulletin_court_page.j2",
|
||||
datetime=datetime,
|
||||
sco=ScoData(formsemestre=formsemestre, etud=etud),
|
||||
time=time,
|
||||
version="butcourt",
|
||||
**args,
|
||||
)
|
||||
return args
|
||||
|
@ -34,6 +34,14 @@ from app.scodoc.sco_preferences import SemPreferences
|
||||
|
||||
|
||||
def make_bulletin_but_court_pdf(
|
||||
args: dict,
|
||||
stand_alone: bool = True,
|
||||
) -> bytes:
|
||||
"""génère le bulletin court BUT en pdf.
|
||||
Si stand_alone, génère un doc pdf complet (une page ici),
|
||||
sinon un morceau (fragment) à intégrer dans un autre document.
|
||||
|
||||
args donne toutes les infos du contenu du bulletin:
|
||||
bul: dict = None,
|
||||
cursus: cursus_but.EtudCursusBUT = None,
|
||||
decision_ues: dict = None,
|
||||
@ -45,14 +53,13 @@ def make_bulletin_but_court_pdf(
|
||||
title: str = "",
|
||||
ue_validation_by_niveau: dict[tuple[int, str], ScolarFormSemestreValidation] = None,
|
||||
ues_acronyms: list[str] = None,
|
||||
) -> bytes:
|
||||
"génère le bulletin court BUT en pdf"
|
||||
"""
|
||||
# A priori ce verrou n'est plus nécessaire avec Flask (multi-process)
|
||||
# mais...
|
||||
try:
|
||||
PDFLOCK.acquire()
|
||||
bul_generator = BulletinGeneratorBUTCourt(**locals())
|
||||
bul_pdf = bul_generator.generate(fmt="pdf")
|
||||
bul_generator = BulletinGeneratorBUTCourt(**args)
|
||||
bul_pdf = bul_generator.generate(fmt="pdf", stand_alone=stand_alone)
|
||||
finally:
|
||||
PDFLOCK.release()
|
||||
return bul_pdf
|
||||
|
@ -61,7 +61,6 @@ from flask import g, request
|
||||
|
||||
from app import log, ScoValueError
|
||||
from app.models import FormSemestre, Identite
|
||||
|
||||
from app.scodoc import sco_cache
|
||||
from app.scodoc import codes_cursus
|
||||
from app.scodoc import sco_pdf
|
||||
@ -213,17 +212,27 @@ def process_field(
|
||||
|
||||
def get_formsemestre_bulletins_pdf(formsemestre_id, version="selectedevals"):
|
||||
"Document pdf avec tous les bulletins du semestre, et filename"
|
||||
from app.but import bulletin_but_court
|
||||
from app.scodoc import sco_bulletins
|
||||
|
||||
if version not in scu.BULLETINS_VERSIONS:
|
||||
raise ScoValueError("version de bulletin demandée invalide")
|
||||
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
||||
versions = (
|
||||
scu.BULLETINS_VERSIONS_BUT
|
||||
if formsemestre.formation.is_apc()
|
||||
else scu.BULLETINS_VERSIONS
|
||||
)
|
||||
if version not in versions:
|
||||
raise ScoValueError("version de bulletin demandée invalide !")
|
||||
cached = sco_cache.SemBulletinsPDFCache.get(str(formsemestre_id) + "_" + version)
|
||||
if cached:
|
||||
return cached[1], cached[0]
|
||||
fragments = []
|
||||
# Make each bulletin
|
||||
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
||||
|
||||
for etud in formsemestre.get_inscrits(include_demdef=True, order=True):
|
||||
if version == "butcourt":
|
||||
frag = bulletin_but_court.bulletin_but_court_pdf_frag(etud, formsemestre)
|
||||
else:
|
||||
frag, _ = sco_bulletins.do_formsemestre_bulletinetud(
|
||||
formsemestre,
|
||||
etud,
|
||||
|
@ -190,7 +190,7 @@ class SemBulletinsPDFCache(ScoDocCache):
|
||||
@classmethod
|
||||
def invalidate_sems(cls, formsemestre_ids):
|
||||
"""Clear cached pdf for all given formsemestres"""
|
||||
for version in scu.BULLETINS_VERSIONS:
|
||||
for version in scu.BULLETINS_VERSIONS_BUT:
|
||||
oids = [
|
||||
str(formsemestre_id) + "_" + version
|
||||
for formsemestre_id in formsemestre_ids
|
||||
|
@ -157,11 +157,24 @@ def formsemestre_recapcomplet(
|
||||
H.append(f'<option value="{fmt}"{selected}>{label}</option>')
|
||||
H.append(
|
||||
f"""
|
||||
</select> (cliquer sur un nom pour afficher son bulletin ou
|
||||
</select> <span class="help">cliquer sur un nom pour afficher son bulletin ou
|
||||
<a class="stdlink"
|
||||
href="{url_for('notes.formsemestre_bulletins_pdf',
|
||||
scodoc_dept=g.scodoc_dept, formsemestre_id=formsemestre_id)
|
||||
}">ici avoir le classeur papier</a>)
|
||||
}">ici avoir le classeur pdf</a>
|
||||
"""
|
||||
)
|
||||
if formsemestre.formation.is_apc():
|
||||
H.append(
|
||||
f""" ou en <a class="stdlink"
|
||||
href="{url_for('notes.formsemestre_bulletins_pdf',
|
||||
scodoc_dept=g.scodoc_dept, formsemestre_id=formsemestre_id, version="butcourt")
|
||||
}">version courte BUT</a>
|
||||
"""
|
||||
)
|
||||
|
||||
H.append(
|
||||
"""</span>
|
||||
</form>
|
||||
"""
|
||||
)
|
||||
|
@ -271,9 +271,7 @@ sco_publish(
|
||||
)
|
||||
|
||||
|
||||
@bp.route(
|
||||
"/formsemestre_bulletinetud", methods=["GET", "POST"]
|
||||
) # POST pour compat anciens clients PHP (deprecated)
|
||||
@bp.route("/formsemestre_bulletinetud")
|
||||
@scodoc
|
||||
@permission_required_compat_scodoc7(Permission.ScoView)
|
||||
@scodoc7func
|
||||
@ -1863,8 +1861,6 @@ sco_publish(
|
||||
@scodoc7func
|
||||
def formsemestre_bulletins_pdf(formsemestre_id, version="selectedevals"):
|
||||
"Publie les bulletins dans un classeur PDF"
|
||||
if version not in scu.BULLETINS_VERSIONS:
|
||||
raise ScoValueError("version de bulletin demandée invalide")
|
||||
pdfdoc, filename = sco_bulletins_pdf.get_formsemestre_bulletins_pdf(
|
||||
formsemestre_id, version=version
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user