2022-03-02 16:45:47 +01:00
|
|
|
|
#################################################### Absences #########################################################
|
|
|
|
|
|
|
|
|
|
from flask import jsonify
|
|
|
|
|
|
|
|
|
|
from app.api import bp
|
|
|
|
|
from app.api.errors import error_response
|
2022-04-25 15:25:45 +02:00
|
|
|
|
from app.api.auth import token_permission_required
|
2022-04-26 17:12:30 +02:00
|
|
|
|
from app.api.tools import get_etu_from_etudid_or_nip_or_ine
|
2022-04-27 05:28:08 +02:00
|
|
|
|
from app.scodoc import notesdb as ndb
|
|
|
|
|
|
2022-04-27 05:19:13 +02:00
|
|
|
|
from app.scodoc import sco_abs
|
2022-03-02 16:45:47 +01:00
|
|
|
|
from app.scodoc.sco_groups import get_group_members
|
2022-03-04 17:16:08 +01:00
|
|
|
|
from app.scodoc.sco_permissions import Permission
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/absences/etudid/<int:etudid>", methods=["GET"])
|
|
|
|
|
@bp.route("/absences/nip/<int:nip>", methods=["GET"])
|
|
|
|
|
@bp.route("/absences/ine/<int:ine>", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def absences(etudid: int = None, nip: int = None, ine: int = None):
|
|
|
|
|
"""
|
|
|
|
|
Retourne la liste des absences d'un étudiant donné
|
|
|
|
|
|
|
|
|
|
etudid : l'etudid d'un étudiant
|
|
|
|
|
nip: le code nip d'un étudiant
|
|
|
|
|
ine : le code ine d'un étudiant
|
2022-04-27 14:11:06 +02:00
|
|
|
|
|
|
|
|
|
Exemple de résultat:
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
"jour": "2022-04-15",
|
|
|
|
|
"matin": true,
|
|
|
|
|
"estabs": true,
|
|
|
|
|
"estjust": true,
|
|
|
|
|
"description": "",
|
|
|
|
|
"begin": "2022-04-15 08:00:00",
|
|
|
|
|
"end": "2022-04-15 11:59:59"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"jour": "2022-04-15",
|
|
|
|
|
"matin": false,
|
|
|
|
|
"estabs": true,
|
|
|
|
|
"estjust": false,
|
|
|
|
|
"description": "",
|
|
|
|
|
"begin": "2022-04-15 12:00:00",
|
|
|
|
|
"end": "2022-04-15 17:59:59"
|
|
|
|
|
}
|
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
"""
|
2022-04-25 15:25:45 +02:00
|
|
|
|
if etudid is None:
|
|
|
|
|
# Récupération de l'étudiant
|
2022-04-27 05:19:13 +02:00
|
|
|
|
etud = get_etu_from_etudid_or_nip_or_ine(etudid, nip, ine)
|
|
|
|
|
if etud is None:
|
2022-04-25 15:25:45 +02:00
|
|
|
|
return error_response(
|
|
|
|
|
409,
|
|
|
|
|
message="La requête ne peut être traitée en l’état actuel.\n "
|
2022-04-27 05:19:13 +02:00
|
|
|
|
"Veuillez vérifier que l'id de l'étudiant (etudid, nip, ine) est valide",
|
2022-04-25 15:25:45 +02:00
|
|
|
|
)
|
2022-04-27 05:19:13 +02:00
|
|
|
|
etudid = etud.etudid
|
2022-04-25 15:25:45 +02:00
|
|
|
|
|
|
|
|
|
# Récupération des absences de l'étudiant
|
2022-04-27 05:19:13 +02:00
|
|
|
|
ndb.open_db_connection()
|
|
|
|
|
absences = sco_abs.list_abs_date(etudid)
|
|
|
|
|
for absence in absences:
|
|
|
|
|
absence["jour"] = absence["jour"].isoformat()
|
|
|
|
|
return jsonify(absences)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
2022-04-25 15:25:45 +02:00
|
|
|
|
|
2022-04-27 05:19:13 +02:00
|
|
|
|
@bp.route("/absences/etudid/<int:etudid>/just", methods=["GET"])
|
|
|
|
|
@bp.route("/absences/nip/<int:nip>/just", methods=["GET"])
|
|
|
|
|
@bp.route("/absences/ine/<int:ine>/just", methods=["GET"])
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
def absences_justify(etudid: int = None, nip: int = None, ine: int = None):
|
|
|
|
|
"""
|
|
|
|
|
Retourne la liste des absences justifiées d'un étudiant donné
|
|
|
|
|
|
|
|
|
|
etudid : l'etudid d'un étudiant
|
|
|
|
|
nip: le code nip d'un étudiant
|
|
|
|
|
ine : le code ine d'un étudiant
|
2022-04-27 14:11:06 +02:00
|
|
|
|
|
|
|
|
|
Exemple de résultat :
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
"jour": "2022-04-15",
|
|
|
|
|
"matin": true,
|
|
|
|
|
"estabs": true,
|
|
|
|
|
"estjust": true,
|
|
|
|
|
"description": "",
|
|
|
|
|
"begin": "2022-04-15 08:00:00",
|
|
|
|
|
"end": "2022-04-15 11:59:59"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"jour": "Fri, 15 Apr 2022 00:00:00 GMT",
|
|
|
|
|
"matin": false,
|
|
|
|
|
"estabs": true,
|
|
|
|
|
"estjust": false,
|
|
|
|
|
"description": "",
|
|
|
|
|
"begin": "2022-04-15 12:00:00",
|
|
|
|
|
"end": "2022-04-15 17:59:59"
|
|
|
|
|
}
|
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
"""
|
2022-04-25 15:25:45 +02:00
|
|
|
|
if etudid is None:
|
|
|
|
|
# Récupération de l'étudiant
|
|
|
|
|
try:
|
2022-04-26 17:12:30 +02:00
|
|
|
|
etu = get_etu_from_etudid_or_nip_or_ine(etudid, nip, ine)
|
2022-04-25 15:25:45 +02:00
|
|
|
|
etudid = etu.etudid
|
|
|
|
|
except AttributeError:
|
|
|
|
|
return error_response(
|
|
|
|
|
409,
|
|
|
|
|
message="La requête ne peut être traitée en l’état actuel.\n "
|
2022-04-27 05:19:13 +02:00
|
|
|
|
"Veuillez vérifier que l'id de l'étudiant (etudid, nip, ine) est valide",
|
2022-04-25 15:25:45 +02:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Récupération des absences justifiées de l'étudiant
|
2022-04-27 05:19:13 +02:00
|
|
|
|
absences = sco_abs.list_abs_date(etudid)
|
|
|
|
|
for absence in [absence for absence in absences if absence["estjust"]]:
|
|
|
|
|
absence["jour"] = absence["jour"].isoformat()
|
|
|
|
|
return jsonify(absences)
|
|
|
|
|
|
|
|
|
|
|
2022-04-25 15:25:45 +02:00
|
|
|
|
@bp.route(
|
|
|
|
|
"/absences/abs_group_etat/?group_id=<int:group_id>&date_debut=date_debut&date_fin=date_fin",
|
|
|
|
|
methods=["GET"],
|
|
|
|
|
)
|
2022-04-14 14:56:36 +02:00
|
|
|
|
@token_permission_required(Permission.APIView)
|
2022-04-27 05:19:13 +02:00
|
|
|
|
def abs_groupe_etat( # XXX A REVOIR XXX
|
2022-04-25 15:25:45 +02:00
|
|
|
|
group_id: int, date_debut, date_fin, with_boursier=True, format="html"
|
|
|
|
|
):
|
2022-03-02 16:45:47 +01:00
|
|
|
|
"""
|
|
|
|
|
Retoune la liste des absences d'un ou plusieurs groupes entre deux dates
|
|
|
|
|
"""
|
|
|
|
|
# Fonction utilisée : app.scodoc.sco_groups.get_group_members() et app.scodoc.sco_abs.list_abs_date()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# Utilisation de la fonction get_group_members
|
|
|
|
|
members = get_group_members(group_id)
|
|
|
|
|
except ValueError:
|
2022-04-25 15:25:45 +02:00
|
|
|
|
return error_response(
|
|
|
|
|
409, message="La requête ne peut être traitée en l’état actuel"
|
|
|
|
|
)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
|
data = []
|
|
|
|
|
# Filtre entre les deux dates renseignées
|
|
|
|
|
for member in members:
|
2022-04-27 05:28:08 +02:00
|
|
|
|
abs = sco_abs.list_abs_date(member.id, date_debut, date_fin)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
data.append(abs)
|
|
|
|
|
|
|
|
|
|
# return jsonify(data) # XXX TODO faire en sorte de pouvoir renvoyer sa (ex to_dict() dans absences)
|
2022-04-25 15:25:45 +02:00
|
|
|
|
return error_response(501, message="Not implemented")
|