Compare commits

...

4 Commits

Author SHA1 Message Date
leonard_montalbano
0b792d5af4 correction conflits avec origin/master 2022-05-16 16:00:24 +02:00
leonard_montalbano
ffcc0897f2 mise à jour de la fonction renvoyant un étudiant suivant son etudid, nip ou ine pour renvoyer la dernière instance de celui si 2022-05-16 15:45:11 +02:00
leonard_montalbano
8c481bd0d1 ajout du code de abs_groupe_etat 2022-05-16 15:15:33 +02:00
leonard_montalbano
53f3ec7294 correction des pluriels dans les routes 2022-05-16 15:14:51 +02:00
7 changed files with 146 additions and 80 deletions

View File

@ -9,6 +9,7 @@ from app.models import Identite
from app.scodoc import notesdb as ndb from app.scodoc import notesdb as ndb
from app.scodoc import sco_abs from app.scodoc import sco_abs
from app.scodoc.sco_groups import get_group_members
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
@ -106,40 +107,68 @@ def absences_just(etudid: int = None):
return jsonify(abs_just) return jsonify(abs_just)
# XXX TODO INACHEVEE @bp.route(
# @bp.route( "/absences/abs_group_etat/<int:group_id>",
# "/absences/abs_group_etat/<int:group_id>", methods=["GET"],
# methods=["GET"], )
# ) @bp.route(
# @bp.route( "/absences/abs_group_etat/group_id/<int:group_id>/date_debut/<string:date_debut>/date_fin/<string:date_fin>",
# "/absences/abs_group_etat/group_id/<int:group_id>/date_debut/<string:date_debut>/date_fin/<string:date_fin>", methods=["GET"],
# methods=["GET"], )
# ) @token_auth.login_required
# @token_auth.login_required @token_permission_required(Permission.APIView)
# @token_permission_required(Permission.APIView) def abs_groupe_etat(group_id: int, date_debut=None, date_fin=None):
# 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 groupe (possibilité de choisir entre deux dates)
# ):
# """
# 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() 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
# try: Exemple de résultat :
# # Utilisation de la fonction get_group_members [
# members = get_group_members(group_id) {
# except ValueError: "etudid": 1,
# return error_response( "list_abs": []
# 404, message="La requête ne peut être traitée en létat actuel" },
# ) {
"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()
# data = [] # Utilisation de la fonction get_group_members
# # Filtre entre les deux dates renseignées members = get_group_members(group_id)
# 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) data = []
# return error_response(501, message="Not implemented") # Filtre entre les deux dates renseignées
for member in members:
abs = {
"etudid": member["etudid"],
"list_abs": sco_abs.list_abs_date(member["etudid"], date_debut, date_fin),
}
data.append(abs)
return jsonify(data)

View File

@ -14,17 +14,18 @@ import app
from app.api import bp from app.api import bp
from app.api.errors import error_response from app.api.errors import error_response
from app.api.auth import token_auth, token_permission_required from app.api.auth import token_auth, token_permission_required
from app.api.tools import get_last_instance_etud_from_etudid_or_nip_or_ine
from app.models import Departement, FormSemestreInscription, FormSemestre, Identite from app.models import Departement, FormSemestreInscription, FormSemestre, Identite
from app.scodoc import sco_bulletins from app.scodoc import sco_bulletins
from app.scodoc import sco_groups from app.scodoc import sco_groups
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
@bp.route("/etudiants/courant", defaults={"long": False}) @bp.route("/etudiants/courants", defaults={"long": False})
@bp.route("/etudiants/courant/long", defaults={"long": True}) @bp.route("/etudiants/courants/long", defaults={"long": True})
@token_auth.login_required @token_auth.login_required
@token_permission_required(Permission.APIView) @token_permission_required(Permission.APIView)
def etudiants_courant(long=False): def etudiants_courants(long=False):
""" """
Liste des étudiants inscrits dans un formsemestre actuellement en cours. Liste des étudiants inscrits dans un formsemestre actuellement en cours.
@ -104,27 +105,7 @@ def etudiant(etudid: int = None, nip: str = None, ine: str = None):
"description": "" "description": ""
} }
""" """
if etudid is not None: etud = get_last_instance_etud_from_etudid_or_nip_or_ine(etudid, nip, ine)
etud = Identite.query.get(etudid)
else:
if nip is not None:
query = Identite.query.filter_by(code_nip=nip)
elif ine is not None:
query = Identite.query.filter_by(code_ine=ine)
else:
return error_response(
404,
message="parametre manquant",
)
if query.count() > 1: # cas rare d'un étudiant présent dans plusieurs depts
etuds = []
for e in query:
admission = e.admission.first()
etuds.append((((admission.annee or 0) if admission else 0), e))
etuds.sort()
etud = etuds[-1][1]
else:
etud = query.first()
if etud is None: if etud is None:
return error_response( return error_response(
@ -236,41 +217,74 @@ def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None)
@bp.route( @bp.route(
"/etudiant/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/bulletin", "/etudiant/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/bulletin",
methods=["GET"], methods=["GET"],
defaults={"version": "long"}, defaults={"version": "long", "pdf": False},
) )
@bp.route( @bp.route(
"/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/bulletin", "/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/bulletin",
methods=["GET"], methods=["GET"],
defaults={"version": "long"}, defaults={"version": "long", "pdf": False},
) )
@bp.route( @bp.route(
"/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/bulletin", "/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/bulletin",
methods=["GET"], methods=["GET"],
defaults={"version": "long"}, defaults={"version": "long", "pdf": False},
) )
# Version PDF non fonctionnelle
# @bp.route(
# "/etudiant/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/bulletin/pdf",
# methods=["GET"],
# defaults={"version": "long", "pdf": True},
# )
# @bp.route(
# "/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/bulletin/pdf",
# methods=["GET"],
# defaults={"version": "long", "pdf": True},
# )
# @bp.route(
# "/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/bulletin/pdf",
# methods=["GET"],
# defaults={"version": "long", "pdf": True},
# )
@bp.route( @bp.route(
"/etudiant/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/bulletin/short", "/etudiant/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/bulletin/short",
methods=["GET"], methods=["GET"],
defaults={"version": "short"}, defaults={"version": "short", "pdf": False},
) )
@bp.route( @bp.route(
"/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/bulletin/short", "/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/bulletin/short",
methods=["GET"], methods=["GET"],
defaults={"version": "short"}, defaults={"version": "short", "pdf": False},
) )
@bp.route( @bp.route(
"/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/bulletin/short", "/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/bulletin/short",
methods=["GET"], methods=["GET"],
defaults={"version": "short"}, defaults={"version": "short", "pdf": False},
) )
# Version PDF non fonctionnelle
# @bp.route(
# "/etudiant/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/bulletin/short/pdf",
# methods=["GET"],
# defaults={"version": "short", "pdf": True},
# )
# @bp.route(
# "/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/bulletin/short/pdf",
# methods=["GET"],
# defaults={"version": "short", "pdf": True},
# )
# @bp.route(
# "/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/bulletin/short/pdf",
# methods=["GET"],
# defaults={"version": "short", "pdf": True},
# )
@token_auth.login_required @token_auth.login_required
@token_permission_required(Permission.APIView) @token_permission_required(Permission.APIView)
def etudiant_bulletin_semestre( def etudiant_bulletin_semestre( # XXX TODO Ajouter la possibilité de retourner en version pdf
formsemestre_id, formsemestre_id,
etudid: int = None, etudid: int = None,
nip: str = None, nip: str = None,
ine: str = None, ine: str = None,
version="long", version="long",
# pdf: bool = False,
): ):
""" """
Retourne le bulletin d'un étudiant en fonction de son id et d'un semestre donné Retourne le bulletin d'un étudiant en fonction de son id et d'un semestre donné

View File

@ -7,6 +7,7 @@ from app import models
from app.api import bp from app.api import bp
from app.api.auth import token_auth, token_permission_required from app.api.auth import token_auth, token_permission_required
from app.api.errors import error_response from app.api.errors import error_response
from app.models import Evaluation
from app.scodoc.sco_evaluation_db import do_evaluation_get_all_notes from app.scodoc.sco_evaluation_db import do_evaluation_get_all_notes
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
@ -46,7 +47,7 @@ def evaluations(moduleimpl_id: int):
] ]
""" """
# Récupération de toutes les évaluations # Récupération de toutes les évaluations
evals = models.Evaluation.query.filter_by(id=moduleimpl_id) evals = Evaluation.query.filter_by(id=moduleimpl_id)
# Mise en forme des données # Mise en forme des données
data = [d.to_dict() for d in evals] data = [d.to_dict() for d in evals]

View File

@ -52,8 +52,8 @@ def partition(formsemestre_id: int):
return jsonify(data) return jsonify(data)
@bp.route("/partitions/groups/<int:group_id>", methods=["GET"]) @bp.route("/partition/group/<int:group_id>", methods=["GET"])
@bp.route("/partitions/groups/<int:group_id>/etat/<string:etat>", methods=["GET"]) @bp.route("/partition/group/<int:group_id>/etat/<string:etat>", methods=["GET"])
@token_auth.login_required @token_auth.login_required
@token_permission_required(Permission.APIView) @token_permission_required(Permission.APIView)
def etud_in_group(group_id: int, etat=None): def etud_in_group(group_id: int, etat=None):

View File

@ -1,11 +1,14 @@
from app import models from app import models
### TODO Faire en sorte de renvoyer l'étudiant qui a son inscription la plus récente from app.api.errors import error_response
def get_etud_from_etudid_or_nip_or_ine( from app.models import Identite
def get_last_instance_etud_from_etudid_or_nip_or_ine(
etudid=None, nip=None, ine=None etudid=None, nip=None, ine=None
) -> models.Identite: ) -> models.Identite:
""" """
etudiant en fonction de l'etudid, code nip et code ine rentré en paramètres Retourne l'instance de l'etudiant la plus récente en fonction de l'etudid, code nip et code ine rentré en paramètres
etudid : None ou un int etudid etudid : None ou un int etudid
nip : None ou un int code_nip nip : None ou un int code_nip
@ -13,12 +16,27 @@ def get_etud_from_etudid_or_nip_or_ine(
Return None si étudiant inexistant. Return None si étudiant inexistant.
""" """
if etudid is None: if etudid is not None:
if nip is None: # si ine etud = Identite.query.get(etudid)
etud = models.Identite.query.filter_by(code_ine=str(ine)).first() else:
else: # si nip if nip is not None:
etud = models.Identite.query.filter_by(code_nip=str(nip)).first() query = Identite.query.filter_by(code_nip=nip)
else: # si etudid elif ine is not None:
etud = models.Identite.query.filter_by(id=etudid).first() query = Identite.query.filter_by(code_ine=ine)
else:
return error_response(
404,
message="parametre manquant",
)
if query.count() > 1: # cas rare d'un étudiant présent dans plusieurs depts
etuds = []
for e in query:
admission = e.admission.first()
etuds.append((((admission.annee or 0) if admission else 0), e))
etuds.sort()
etud = etuds[-1][1]
else:
etud = query.first()
return etud return etud

View File

@ -171,7 +171,6 @@ class Identite(db.Model):
""" """
from app.scodoc import sco_photos from app.scodoc import sco_photos
dept = models.Departement.query.filter_by(id=self.dept_id).first_or_404()
d = { d = {
"civilite": self.civilite, "civilite": self.civilite,
"code_ine": self.code_ine or "", "code_ine": self.code_ine or "",
@ -180,7 +179,7 @@ class Identite(db.Model):
if self.date_naissance if self.date_naissance
else "", else "",
"dept_id": self.dept_id, "dept_id": self.dept_id,
"dept_acronym": dept.acronym, "dept_acronym": self.departement.acronym,
"email": self.get_first_email() or "", "email": self.get_first_email() or "",
"emailperso": self.get_first_email("emailperso"), "emailperso": self.get_first_email("emailperso"),
"etudid": self.id, "etudid": self.id,

View File

@ -54,7 +54,12 @@ class Evaluation(db.Model):
# ScoDoc7 output_formators # ScoDoc7 output_formators
e["evaluation_id"] = self.id e["evaluation_id"] = self.id
e["jour"] = ndb.DateISOtoDMY(e["jour"]) e["jour"] = ndb.DateISOtoDMY(e["jour"])
e["date_debut"] = datetime.datetime.combine(
self.jour, self.heure_debut
).isoformat()
e["date_fin"] = datetime.datetime.combine(self.jour, self.heure_fin).isoformat()
e["numero"] = ndb.int_null_is_zero(e["numero"]) e["numero"] = ndb.int_null_is_zero(e["numero"])
e["poids"] = self.get_ue_poids_dict() # { ue_id : poids }
return evaluation_enrich_dict(e) return evaluation_enrich_dict(e)
def from_dict(self, data): def from_dict(self, data):
@ -153,7 +158,7 @@ class EvaluationUEPoids(db.Model):
# Fonction héritée de ScoDoc7 à refactorer # Fonction héritée de ScoDoc7 à refactorer
def evaluation_enrich_dict(e): def evaluation_enrich_dict(e):
"""add or convert some fileds in an evaluation dict""" """add or convert some fields in an evaluation dict"""
# For ScoDoc7 compat # For ScoDoc7 compat
heure_debut_dt = e["heure_debut"] or datetime.time( heure_debut_dt = e["heure_debut"] or datetime.time(
8, 00 8, 00