2022-07-19 22:17:10 +02:00
|
|
|
##############################################################################
|
|
|
|
# ScoDoc
|
|
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
|
|
|
# See LICENSE
|
|
|
|
##############################################################################
|
|
|
|
"""ScoDoc 9 API : Absences
|
|
|
|
"""
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
from flask import jsonify
|
|
|
|
|
2022-07-27 16:03:14 +02:00
|
|
|
from app.api import api_bp as bp
|
2022-08-07 19:56:25 +02:00
|
|
|
from app.scodoc.sco_utils import json_error
|
2022-07-27 16:03:14 +02:00
|
|
|
from app.decorators import scodoc, permission_required
|
2022-07-19 22:17:10 +02:00
|
|
|
from app.models import Identite
|
2022-04-27 05:28:08 +02:00
|
|
|
|
2022-05-11 00:59:51 +02:00
|
|
|
from app.scodoc import notesdb as ndb
|
2022-04-27 05:19:13 +02:00
|
|
|
from app.scodoc import sco_abs
|
2022-07-19 22:17:10 +02:00
|
|
|
|
2022-05-16 15:15:33 +02: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
|
|
|
|
2022-08-08 10:06:42 +02:00
|
|
|
# TODO XXX revoir routes web API et calcul des droits
|
2022-03-02 16:45:47 +01:00
|
|
|
@bp.route("/absences/etudid/<int:etudid>", methods=["GET"])
|
2022-07-27 16:03:14 +02:00
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2022-05-11 00:59:51 +02:00
|
|
|
def absences(etudid: int = None):
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-08-08 10:06:42 +02:00
|
|
|
Liste des absences de cet étudiant
|
2022-04-27 14:11:06 +02:00
|
|
|
|
|
|
|
Exemple de résultat:
|
2022-05-11 00:59:51 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
"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-05-11 00:59:51 +02:00
|
|
|
etud = Identite.query.get(etudid)
|
|
|
|
if etud is None:
|
2022-08-07 19:56:25 +02:00
|
|
|
return json_error(404, message="etudiant inexistant")
|
2022-05-11 00:59:51 +02:00
|
|
|
# Absences de l'étudiant
|
2022-04-27 05:19:13 +02:00
|
|
|
ndb.open_db_connection()
|
2022-07-19 22:17:10 +02:00
|
|
|
abs_list = sco_abs.list_abs_date(etud.id)
|
|
|
|
for absence in abs_list:
|
2022-04-27 05:19:13 +02:00
|
|
|
absence["jour"] = absence["jour"].isoformat()
|
2022-07-19 22:17:10 +02:00
|
|
|
return jsonify(abs_list)
|
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"])
|
2022-07-27 16:03:14 +02:00
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2022-05-11 00:59:51 +02:00
|
|
|
def absences_just(etudid: 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 :
|
2022-05-11 00:59:51 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
"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"
|
|
|
|
}
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-05-11 00:59:51 +02:00
|
|
|
etud = Identite.query.get(etudid)
|
|
|
|
if etud is None:
|
2022-08-07 19:56:25 +02:00
|
|
|
return json_error(404, message="etudiant inexistant")
|
2022-04-25 15:25:45 +02:00
|
|
|
|
2022-05-11 00:59:51 +02:00
|
|
|
# Absences justifiées de l'étudiant
|
2022-05-03 13:35:17 +02:00
|
|
|
abs_just = [
|
2022-05-11 00:59:51 +02:00
|
|
|
absence for absence in sco_abs.list_abs_date(etud.id) if absence["estjust"]
|
2022-05-03 13:35:17 +02:00
|
|
|
]
|
|
|
|
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-16 15:15:33 +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"],
|
|
|
|
)
|
2022-07-27 16:03:14 +02:00
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2022-05-16 15:15:33 +02:00
|
|
|
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"
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
"""
|
|
|
|
members = get_group_members(group_id)
|
|
|
|
|
|
|
|
data = []
|
|
|
|
# Filtre entre les deux dates renseignées
|
|
|
|
for member in members:
|
2022-07-22 16:39:21 +02:00
|
|
|
absence = {
|
2022-05-16 15:15:33 +02:00
|
|
|
"etudid": member["etudid"],
|
|
|
|
"list_abs": sco_abs.list_abs_date(member["etudid"], date_debut, date_fin),
|
|
|
|
}
|
2022-07-22 16:39:21 +02:00
|
|
|
data.append(absence)
|
2022-05-16 15:15:33 +02:00
|
|
|
|
|
|
|
return jsonify(data)
|
2022-05-23 15:47:51 +02:00
|
|
|
|
|
|
|
|
2022-07-19 22:17:10 +02:00
|
|
|
# XXX TODO EV: A REVOIR (data json dans le POST + modifier les routes)
|
|
|
|
# @bp.route(
|
|
|
|
# "/absences/etudid/<int:etudid>/list_abs/<string:list_abs>/reset_etud_abs",
|
|
|
|
# methods=["POST"],
|
|
|
|
# defaults={"just_or_not": 0},
|
|
|
|
# )
|
|
|
|
# @bp.route(
|
|
|
|
# "/absences/etudid/<int:etudid>/list_abs/<string:list_abs>/reset_etud_abs/only_not_just",
|
|
|
|
# methods=["POST"],
|
|
|
|
# defaults={"just_or_not": 1},
|
|
|
|
# )
|
|
|
|
# @bp.route(
|
|
|
|
# "/absences/etudid/<int:etudid>/list_abs/<string:list_abs>/reset_etud_abs/only_just",
|
|
|
|
# methods=["POST"],
|
|
|
|
# defaults={"just_or_not": 2},
|
|
|
|
# )
|
|
|
|
# @token_auth.login_required
|
|
|
|
# @token_permission_required(Permission.APIAbsChange)
|
|
|
|
# def reset_etud_abs(etudid: int, list_abs: str, 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)
|
2022-05-23 15:47:51 +02:00
|
|
|
|
2022-07-19 22:17:10 +02:00
|
|
|
# etudid : l'id d'un étudiant
|
|
|
|
# list_abs : json d'absences
|
|
|
|
# just_or_not : 0 (pour les absences justifiées et non justifiées),
|
|
|
|
# 1 (pour les absences justifiées),
|
|
|
|
# 2 (pour les absences non justifiées)
|
|
|
|
# """
|
|
|
|
# # Toutes les absences
|
|
|
|
# if just_or_not == 0:
|
|
|
|
# # suppression des absences et justificatif déjà existant pour éviter les doublons
|
|
|
|
# for abs in list_abs:
|
|
|
|
# # Récupération de la date au format iso
|
|
|
|
# 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)
|
2022-05-24 12:12:39 +02:00
|
|
|
|
2022-07-19 22:17:10 +02:00
|
|
|
# # Ajout de la liste d'absences en base
|
|
|
|
# add_abslist(list_abs)
|
2022-05-23 15:47:51 +02:00
|
|
|
|
2022-07-19 22:17:10 +02:00
|
|
|
# # Uniquement les absences justifiées
|
|
|
|
# elif just_or_not == 1:
|
|
|
|
# list_abs_not_just = []
|
|
|
|
# # Trie des absences justifiées
|
|
|
|
# for abs in list_abs:
|
|
|
|
# if abs["estjust"] is False:
|
|
|
|
# list_abs_not_just.append(abs)
|
|
|
|
# # suppression des absences et justificatif déjà existant pour éviter les doublons
|
|
|
|
# for abs in list_abs:
|
|
|
|
# # Récupération de la date au format iso
|
|
|
|
# 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)
|
2022-05-24 12:12:39 +02:00
|
|
|
|
2022-07-19 22:17:10 +02:00
|
|
|
# # Ajout de la liste d'absences en base
|
|
|
|
# add_abslist(list_abs_not_just)
|
2022-05-23 15:47:51 +02:00
|
|
|
|
2022-07-19 22:17:10 +02:00
|
|
|
# # Uniquement les absences non justifiées
|
|
|
|
# elif just_or_not == 2:
|
|
|
|
# list_abs_just = []
|
|
|
|
# # Trie des absences non justifiées
|
|
|
|
# for abs in list_abs:
|
|
|
|
# if abs["estjust"] is True:
|
|
|
|
# list_abs_just.append(abs)
|
|
|
|
# # suppression des absences et justificatif déjà existant pour éviter les doublons
|
|
|
|
# for abs in list_abs:
|
|
|
|
# # Récupération de la date au format iso
|
|
|
|
# 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)
|
2022-05-24 12:12:39 +02:00
|
|
|
|
2022-07-19 22:17:10 +02:00
|
|
|
# # Ajout de la liste d'absences en base
|
|
|
|
# add_abslist(list_abs_just)
|