1
0
forked from ScoDoc/ScoDoc

ajout de la route 'set_formsemestre_etud_abs' pour pouvoir set une liste d'absence d'un étudiant sur tout un semestre

This commit is contained in:
leonard_montalbano 2022-05-23 15:47:51 +02:00
parent f4aa04bb76
commit e6ee7802d6

View File

@ -5,10 +5,11 @@ 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
from app.models import Identite, FormSemestre
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
@ -172,3 +173,92 @@ 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)