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-05-03 13:35:17 +02:00
|
|
|
from app.api.auth import token_auth, token_permission_required
|
2022-05-09 16:26:23 +02:00
|
|
|
from app.api.tools import get_etud_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-05-03 13:35:17 +02:00
|
|
|
@token_auth.login_required
|
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-05-09 16:26:23 +02:00
|
|
|
etud = get_etud_from_etudid_or_nip_or_ine(etudid, nip, ine)
|
2022-04-27 05:19:13 +02:00
|
|
|
if etud is None:
|
2022-04-25 15:25:45 +02:00
|
|
|
return error_response(
|
2022-05-09 16:26:23 +02:00
|
|
|
404,
|
|
|
|
message="id de l'étudiant (etudid, nip, ine) inconnu",
|
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-05-03 13:35:17 +02:00
|
|
|
@token_auth.login_required
|
2022-04-14 14:56:36 +02:00
|
|
|
@token_permission_required(Permission.APIView)
|
2022-04-27 15:29:09 +02:00
|
|
|
def absences_just(etudid: int = None, nip: int = None, ine: int = None):
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
|
|
|
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,
|
2022-04-28 16:12:15 +02:00
|
|
|
"estjust": true,
|
2022-04-27 14:11:06 +02:00
|
|
|
"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:
|
2022-05-09 16:26:23 +02:00
|
|
|
etud = get_etud_from_etudid_or_nip_or_ine(etudid, nip, ine)
|
|
|
|
if etud is None:
|
2022-04-25 15:25:45 +02:00
|
|
|
return error_response(
|
2022-05-09 16:26:23 +02:00
|
|
|
404,
|
|
|
|
message="id de l'étudiant (etudid, nip, ine) inconnu",
|
2022-04-25 15:25:45 +02:00
|
|
|
)
|
2022-05-09 16:26:23 +02:00
|
|
|
etudid = etud.etudid
|
2022-04-25 15:25:45 +02:00
|
|
|
|
|
|
|
# Récupération des absences justifiées de l'étudiant
|
2022-05-03 13:35:17 +02:00
|
|
|
abs_just = [
|
|
|
|
absence for absence in sco_abs.list_abs_date(etudid) if absence["estjust"]
|
|
|
|
]
|
|
|
|
for absence in abs_just:
|
2022-04-27 05:19:13 +02:00
|
|
|
absence["jour"] = absence["jour"].isoformat()
|
2022-05-03 13:35:17 +02:00
|
|
|
return jsonify(abs_just)
|
2022-04-27 05:19:13 +02:00
|
|
|
|
|
|
|
|
2022-05-06 12:17:01 +02:00
|
|
|
@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(group_id: int, date_debut=None, date_fin=None):
|
|
|
|
"""
|
|
|
|
Liste des absences d'un groupe (possibilité de choisir entre deux dates)
|
|
|
|
|
|
|
|
group_id = l'id du groupe
|
|
|
|
date_debut = None par défaut, sinon la date ISO du début de notre filtre
|
|
|
|
date_fin = None par défaut, sinon la date ISO de la fin de notre filtre
|
|
|
|
|
|
|
|
Exemple de résultat :
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"etudid": 1,
|
|
|
|
"list_abs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"etudid": 2,
|
|
|
|
"list_abs": [
|
|
|
|
{
|
|
|
|
"jour": "Fri, 15 Apr 2022 00:00:00 GMT",
|
|
|
|
"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"
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
"""
|
|
|
|
# Fonction utilisée : app.scodoc.sco_groups.get_group_members() et app.scodoc.sco_abs.list_abs_date()
|
|
|
|
|
|
|
|
# Utilisation de la fonction get_group_members
|
|
|
|
members = get_group_members(group_id)
|
|
|
|
|
|
|
|
data = []
|
|
|
|
# Filtre entre les deux dates renseignées
|
|
|
|
for member in members:
|
|
|
|
print(member)
|
|
|
|
abs = {
|
|
|
|
"etudid": member["etudid"],
|
|
|
|
"list_abs": sco_abs.list_abs_date(member["etudid"], date_debut, date_fin),
|
|
|
|
}
|
|
|
|
data.append(abs)
|
|
|
|
|
|
|
|
return jsonify(data)
|