WIP: API absences

This commit is contained in:
Emmanuel Viennet 2022-04-27 05:28:08 +02:00
parent 62c65176b6
commit 5df1d90101
2 changed files with 11 additions and 13 deletions

View File

@ -1,20 +1,14 @@
#################################################### Absences #########################################################
from datetime import datetime
from flask import jsonify
from app import models
from app.api import bp
from app.api.errors import error_response
from app.api.auth import token_permission_required
from app.api.tools import get_etu_from_etudid_or_nip_or_ine
from app.scodoc import ndb
from app.scodoc import notesdb as ndb
from app.scodoc import sco_abs
from app.scodoc.sco_abs import (
annule_absence,
annule_justif,
list_abs_date,
)
from app.scodoc.sco_groups import get_group_members
from app.scodoc.sco_permissions import Permission
@ -208,7 +202,7 @@ def abs_groupe_etat( # XXX A REVOIR XXX
data = []
# Filtre entre les deux dates renseignées
for member in members:
abs = list_abs_date(member.id, date_debut, date_fin)
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)

View File

@ -425,16 +425,20 @@ def list_abs_date(etudid, beg_date=None, end_date=None):
cursor.execute(
"""SELECT jour, matin, estabs, estjust, description FROM ABSENCES A
WHERE A.ETUDID = %(etudid)s"""
+ ("" if beg_date is None else """
+ (
""
if beg_date is None
else """
AND A.jour >= %(beg_date)s
AND A.jour <= %(end_date)s
""",
vars(),
)
Abs = cursor.dictfetchall()
)
absences = cursor.dictfetchall()
# remove duplicates
A = {} # { (jour, matin) : abs }
for a in Abs:
for a in absences:
jour, matin = a["jour"], a["matin"]
if (jour, matin) in A:
# garde toujours la description