Compare commits

...

2 Commits

3 changed files with 98 additions and 58 deletions

View File

@ -5,10 +5,11 @@ from flask import jsonify
from app.api import bp from app.api import bp
from app.api.errors import error_response from app.api.errors import error_response
from app.api.auth import token_auth, token_permission_required from app.api.auth import token_auth, token_permission_required
from app.models import Identite from app.models import Identite, FormSemestre
from app.scodoc import notesdb as ndb from app.scodoc import notesdb as ndb
from app.scodoc import sco_abs 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_groups import get_group_members
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
@ -172,3 +173,92 @@ def abs_groupe_etat(group_id: int, date_debut=None, date_fin=None):
data.append(abs) data.append(abs)
return jsonify(data) 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 API : accès aux étudiants
""" """
from flask import jsonify from flask import jsonify, make_response
import app import app
from app.api import bp 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.models import Departement, FormSemestreInscription, FormSemestre, Identite
from app.scodoc import sco_bulletins from app.scodoc import sco_bulletins
from app.scodoc import sco_groups from app.scodoc import sco_groups
from app.scodoc.sco_bulletins_pdf import get_bulletin_etud_formsemestre_pdf from app.scodoc.sco_bulletins import do_formsemestre_bulletinetud
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
@ -464,8 +464,11 @@ def etudiant_bulletin_semestre( # XXX TODO Ajouter la possibilité de retourner
app.set_sco_dept(dept.acronym) app.set_sco_dept(dept.acronym)
if pdf: if pdf:
return get_bulletin_etud_formsemestre_pdf(etudid, formsemestre_id, version) response = make_response(
do_formsemestre_bulletinetud(formsemestre, etudid, version, "pdf")
)
response.headers["Content-Type"] = "application/json"
return response
return sco_bulletins.get_formsemestre_bulletin_etud_json( return sco_bulletins.get_formsemestre_bulletin_etud_json(
formsemestre, etud, version formsemestre, etud, version

View File

@ -271,59 +271,6 @@ def get_etud_bulletins_pdf(etudid, version="selectedevals"):
return pdfdoc, filename 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: def get_filigranne(etud_etat: str, prefs, decision_sem=None) -> str:
"""Texte à placer en "filigranne" sur le bulletin pdf""" """Texte à placer en "filigranne" sur le bulletin pdf"""
if etud_etat == scu.DEMISSION: if etud_etat == scu.DEMISSION: