Compare commits

..

No commits in common. "e6ee7802d62b930759b50ae5f9162093b7c45254" and "62e57d9ca0847ab12a2db0fab0a4888f5c1d7ca7" have entirely different histories.

3 changed files with 58 additions and 98 deletions

View File

@ -5,11 +5,10 @@ from flask import jsonify
from app.api import bp
from app.api.errors import error_response
from app.api.auth import token_auth, token_permission_required
from app.models import Identite, FormSemestre
from app.models import Identite
from app.scodoc import notesdb as ndb
from app.scodoc import sco_abs
from app.scodoc.sco_abs import list_abs_date, annule_absence, annule_justif, add_abslist
from app.scodoc.sco_groups import get_group_members
from app.scodoc.sco_permissions import Permission
@ -173,92 +172,3 @@ def abs_groupe_etat(group_id: int, date_debut=None, date_fin=None):
data.append(abs)
return jsonify(data)
@bp.route(
"/absences/formsemestre/<int:formsemestre_id>/etudid/<int:etudid>/set_etud_abs",
methods=["GET"],
defaults={"just_or_not": 0},
)
@bp.route(
"/absences/formsemestre/<int:formsemestre_id>/etudid/<int:etudid>/set_etud_abs/only_not_just",
methods=["GET"],
defaults={"just_or_not": 1},
)
@bp.route(
"/absences/formsemestre/<int:formsemestre_id>/etudid/<int:etudid>/set_etud_abs/only_just",
methods=["GET"],
defaults={"just_or_not": 2},
)
@token_auth.login_required
@token_permission_required(Permission.APIView)
def set_formsemestre_etud_abs(formsemestre_id: int, etudid: int, just_or_not: int = 0):
"""
Set la liste des absences d'un étudiant sur tout un semestre.
(les absences existant pour cet étudiant sur cette période sont effacées)
formsemestre_id : l'id d'un semestre
etudid : l'id d'un étudiant
Exemple de résultat :
[
{
"matin": true,
"estabs": true,
"estjust": true,
"description": "",
"begin": "2022-04-15 08:00:00",
"end": "2022-04-15 11:59:59"
},
...
]
"""
formsemestre = FormSemestre.query.filter_by(id=formsemestre_id).first_or_404()
date_debut = formsemestre.date_debut
date_fin = formsemestre.date_fin
list_abs = list_abs_date(etudid, date_debut, date_fin)
if just_or_not == 0:
for abs in list_abs:
jour = abs["jour"].isoformat()
if abs["matin"] is True:
annule_absence(etudid, jour, True)
annule_justif(etudid, jour, True)
else:
annule_absence(etudid, jour, False)
annule_justif(etudid, jour, False)
add_abslist(list_abs)
# return jsonify(list_abs)
elif just_or_not == 1:
list_abs_not_just = []
for abs in list_abs:
if abs["estjust"] is False:
list_abs_not_just.append(abs)
for abs in list_abs:
jour = abs["jour"].isoformat()
if abs["matin"] is True:
annule_absence(etudid, jour, True)
annule_justif(etudid, jour, True)
else:
annule_absence(etudid, jour, False)
annule_justif(etudid, jour, False)
add_abslist(list_abs_not_just)
# return jsonify(res)
elif just_or_not == 2:
list_abs_just = []
for abs in list_abs:
if abs["estjust"] is True:
list_abs_just.append(abs)
for abs in list_abs:
jour = abs["jour"].isoformat()
if abs["matin"] is True:
annule_absence(etudid, jour, True)
annule_justif(etudid, jour, True)
else:
annule_absence(etudid, jour, False)
annule_justif(etudid, jour, False)
add_abslist(list_abs_just)
# return jsonify(res)

View File

@ -8,7 +8,7 @@
API : accès aux étudiants
"""
from flask import jsonify, make_response
from flask import jsonify
import app
from app.api import bp
@ -18,7 +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 import do_formsemestre_bulletinetud
from app.scodoc.sco_bulletins_pdf import get_bulletin_etud_formsemestre_pdf
from app.scodoc.sco_permissions import Permission
@ -464,11 +464,8 @@ def etudiant_bulletin_semestre( # XXX TODO Ajouter la possibilité de retourner
app.set_sco_dept(dept.acronym)
if pdf:
response = make_response(
do_formsemestre_bulletinetud(formsemestre, etudid, version, "pdf")
)
response.headers["Content-Type"] = "application/json"
return response
return get_bulletin_etud_formsemestre_pdf(etudid, formsemestre_id, version)
return sco_bulletins.get_formsemestre_bulletin_etud_json(
formsemestre, etud, version

View File

@ -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)
fragments, filigranne = sco_bulletins.do_formsemestre_bulletinetud(
formsemestre,
etudid,
format="pdfpart",
version=version,
)
# fragments.append(frag)
filigrannes[0] = 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(
formsemestre_id,
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: