forked from ScoDoc/ScoDoc
159 lines
5.1 KiB
Python
159 lines
5.1 KiB
Python
#################################################### Absences #########################################################
|
||
|
||
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.api.tools import get_etud_from_etudid_or_nip_or_ine
|
||
from app.scodoc import notesdb as ndb
|
||
|
||
from app.scodoc import sco_abs
|
||
from app.scodoc.sco_groups import get_group_members
|
||
from app.scodoc.sco_permissions import Permission
|
||
|
||
|
||
@bp.route("/absences/etudid/<int:etudid>", methods=["GET"])
|
||
@bp.route("/absences/nip/<int:nip>", methods=["GET"])
|
||
@bp.route("/absences/ine/<int:ine>", methods=["GET"])
|
||
@token_auth.login_required
|
||
@token_permission_required(Permission.APIView)
|
||
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
|
||
|
||
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"
|
||
}
|
||
]
|
||
"""
|
||
if etudid is None:
|
||
# Récupération de l'étudiant
|
||
etud = get_etud_from_etudid_or_nip_or_ine(etudid, nip, ine)
|
||
if etud is None:
|
||
return error_response(
|
||
404,
|
||
message="id de l'étudiant (etudid, nip, ine) inconnu",
|
||
)
|
||
etudid = etud.etudid
|
||
|
||
# Récupération des absences de l'étudiant
|
||
ndb.open_db_connection()
|
||
absences = sco_abs.list_abs_date(etudid)
|
||
for absence in absences:
|
||
absence["jour"] = absence["jour"].isoformat()
|
||
return jsonify(absences)
|
||
|
||
|
||
@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"])
|
||
@token_auth.login_required
|
||
@token_permission_required(Permission.APIView)
|
||
def absences_just(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
|
||
|
||
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": true,
|
||
"description": "",
|
||
"begin": "2022-04-15 12:00:00",
|
||
"end": "2022-04-15 17:59:59"
|
||
}
|
||
]
|
||
"""
|
||
if etudid is None:
|
||
etud = get_etud_from_etudid_or_nip_or_ine(etudid, nip, ine)
|
||
if etud is None:
|
||
return error_response(
|
||
404,
|
||
message="id de l'étudiant (etudid, nip, ine) inconnu",
|
||
)
|
||
etudid = etud.etudid
|
||
|
||
# Récupération des absences justifiées de l'étudiant
|
||
abs_just = [
|
||
absence for absence in sco_abs.list_abs_date(etudid) if absence["estjust"]
|
||
]
|
||
for absence in abs_just:
|
||
absence["jour"] = absence["jour"].isoformat()
|
||
return jsonify(abs_just)
|
||
|
||
|
||
# XXX TODO INACHEVEE
|
||
# @bp.route(
|
||
# "/absences/abs_group_etat/<int:group_id>",
|
||
# methods=["GET"],
|
||
# )
|
||
# @bp.route(
|
||
# "/absences/abs_group_etat/group_id/<int:group_id>/date_debut/<string:date_debut>/date_fin/<string:date_fin>",
|
||
# methods=["GET"],
|
||
# )
|
||
# @token_auth.login_required
|
||
# @token_permission_required(Permission.APIView)
|
||
# def abs_groupe_etat( # XXX A REVOIR XXX
|
||
# group_id: int, date_debut, date_fin, with_boursier=True, format="html"
|
||
# ):
|
||
# """
|
||
# Liste des absences d'un ou plusieurs groupes entre deux dates
|
||
# """
|
||
# return error_response(501, message="Not implemented")
|
||
|
||
# # 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:
|
||
# return error_response(
|
||
# 404, message="La requête ne peut être traitée en l’état actuel"
|
||
# )
|
||
|
||
# data = []
|
||
# # Filtre entre les deux dates renseignées
|
||
# for member in members:
|
||
# abs = sco_abs.list_abs_date(member.id, date_debut, date_fin)
|
||
# data.append(abs)
|
||
|
||
# # return jsonify(data) # XXX TODO faire en sorte de pouvoir renvoyer sa (ex to_dict() dans absences)
|
||
# return error_response(501, message="Not implemented")
|