From e6ee7802d62b930759b50ae5f9162093b7c45254 Mon Sep 17 00:00:00 2001 From: leonard_montalbano Date: Mon, 23 May 2022 15:47:51 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20de=20la=20route=20'set=5Fformsemestre?= =?UTF-8?q?=5Fetud=5Fabs'=20pour=20pouvoir=20set=20une=20liste=20d'absence?= =?UTF-8?q?=20d'un=20=C3=A9tudiant=20sur=20tout=20un=20semestre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/absences.py | 92 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/app/api/absences.py b/app/api/absences.py index 16a3e751b..b231575bf 100644 --- a/app/api/absences.py +++ b/app/api/absences.py @@ -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//etudid//set_etud_abs", + methods=["GET"], + defaults={"just_or_not": 0}, +) +@bp.route( + "/absences/formsemestre//etudid//set_etud_abs/only_not_just", + methods=["GET"], + defaults={"just_or_not": 1}, +) +@bp.route( + "/absences/formsemestre//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)