forked from ScoDoc/ScoDoc
Compare commits
4 Commits
8637c81f78
...
0b792d5af4
Author | SHA1 | Date | |
---|---|---|---|
|
0b792d5af4 | ||
|
ffcc0897f2 | ||
|
8c481bd0d1 | ||
|
53f3ec7294 |
@ -9,6 +9,7 @@ from app.models import Identite
|
||||
|
||||
from app.scodoc import notesdb as ndb
|
||||
from app.scodoc import sco_abs
|
||||
from app.scodoc.sco_groups import get_group_members
|
||||
from app.scodoc.sco_permissions import Permission
|
||||
|
||||
|
||||
@ -106,40 +107,68 @@ def absences_just(etudid: int = None):
|
||||
return jsonify(abs_just)
|
||||
|
||||
|
||||
# XXX TODO INACHEVEE
|
||||
# @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( # XXX A REVOIR XXX
|
||||
# group_id: int, date_debut, date_fin, with_boursier=True, format="html"
|
||||
# ):
|
||||
# """
|
||||
# Liste des absences d'un ou plusieurs groupes entre deux dates
|
||||
# """
|
||||
# return error_response(501, message="Not implemented")
|
||||
@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)
|
||||
|
||||
# # 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:
|
||||
# # Utilisation de la fonction get_group_members
|
||||
# members = get_group_members(group_id)
|
||||
# except ValueError:
|
||||
# return error_response(
|
||||
# 404, message="La requête ne peut être traitée en l’état actuel"
|
||||
# )
|
||||
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()
|
||||
|
||||
# data = []
|
||||
# # Filtre entre les deux dates renseignées
|
||||
# for member in members:
|
||||
# abs = sco_abs.list_abs_date(member.id, date_debut, date_fin)
|
||||
# data.append(abs)
|
||||
# Utilisation de la fonction get_group_members
|
||||
members = get_group_members(group_id)
|
||||
|
||||
# # return jsonify(data) # XXX TODO faire en sorte de pouvoir renvoyer sa (ex to_dict() dans absences)
|
||||
# return error_response(501, message="Not implemented")
|
||||
data = []
|
||||
# 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)
|
||||
|
@ -14,17 +14,18 @@ import app
|
||||
from app.api import bp
|
||||
from app.api.errors import error_response
|
||||
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.scodoc import sco_bulletins
|
||||
from app.scodoc import sco_groups
|
||||
from app.scodoc.sco_permissions import Permission
|
||||
|
||||
|
||||
@bp.route("/etudiants/courant", defaults={"long": False})
|
||||
@bp.route("/etudiants/courant/long", defaults={"long": True})
|
||||
@bp.route("/etudiants/courants", defaults={"long": False})
|
||||
@bp.route("/etudiants/courants/long", defaults={"long": True})
|
||||
@token_auth.login_required
|
||||
@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.
|
||||
|
||||
@ -104,27 +105,7 @@ def etudiant(etudid: int = None, nip: str = None, ine: str = None):
|
||||
"description": ""
|
||||
}
|
||||
"""
|
||||
if etudid is not None:
|
||||
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()
|
||||
etud = get_last_instance_etud_from_etudid_or_nip_or_ine(etudid, nip, ine)
|
||||
|
||||
if etud is None:
|
||||
return error_response(
|
||||
@ -236,41 +217,74 @@ def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None)
|
||||
@bp.route(
|
||||
"/etudiant/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/bulletin",
|
||||
methods=["GET"],
|
||||
defaults={"version": "long"},
|
||||
defaults={"version": "long", "pdf": False},
|
||||
)
|
||||
@bp.route(
|
||||
"/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/bulletin",
|
||||
methods=["GET"],
|
||||
defaults={"version": "long"},
|
||||
defaults={"version": "long", "pdf": False},
|
||||
)
|
||||
@bp.route(
|
||||
"/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/bulletin",
|
||||
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(
|
||||
"/etudiant/etudid/<int:etudid>/formsemestre/<int:formsemestre_id>/bulletin/short",
|
||||
methods=["GET"],
|
||||
defaults={"version": "short"},
|
||||
defaults={"version": "short", "pdf": False},
|
||||
)
|
||||
@bp.route(
|
||||
"/etudiant/nip/<string:nip>/formsemestre/<int:formsemestre_id>/bulletin/short",
|
||||
methods=["GET"],
|
||||
defaults={"version": "short"},
|
||||
defaults={"version": "short", "pdf": False},
|
||||
)
|
||||
@bp.route(
|
||||
"/etudiant/ine/<string:ine>/formsemestre/<int:formsemestre_id>/bulletin/short",
|
||||
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_permission_required(Permission.APIView)
|
||||
def etudiant_bulletin_semestre(
|
||||
def etudiant_bulletin_semestre( # XXX TODO Ajouter la possibilité de retourner en version pdf
|
||||
formsemestre_id,
|
||||
etudid: int = None,
|
||||
nip: str = None,
|
||||
ine: str = None,
|
||||
version="long",
|
||||
# pdf: bool = False,
|
||||
):
|
||||
"""
|
||||
Retourne le bulletin d'un étudiant en fonction de son id et d'un semestre donné
|
||||
|
@ -7,6 +7,7 @@ from app import models
|
||||
from app.api import bp
|
||||
from app.api.auth import token_auth, token_permission_required
|
||||
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_permissions import Permission
|
||||
|
||||
@ -46,7 +47,7 @@ def evaluations(moduleimpl_id: int):
|
||||
]
|
||||
"""
|
||||
# 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
|
||||
data = [d.to_dict() for d in evals]
|
||||
|
@ -52,8 +52,8 @@ def partition(formsemestre_id: int):
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
@bp.route("/partitions/groups/<int:group_id>", methods=["GET"])
|
||||
@bp.route("/partitions/groups/<int:group_id>/etat/<string:etat>", methods=["GET"])
|
||||
@bp.route("/partition/group/<int:group_id>", methods=["GET"])
|
||||
@bp.route("/partition/group/<int:group_id>/etat/<string:etat>", methods=["GET"])
|
||||
@token_auth.login_required
|
||||
@token_permission_required(Permission.APIView)
|
||||
def etud_in_group(group_id: int, etat=None):
|
||||
|
@ -1,11 +1,14 @@
|
||||
from app import models
|
||||
|
||||
### TODO Faire en sorte de renvoyer l'étudiant qui a son inscription la plus récente
|
||||
def get_etud_from_etudid_or_nip_or_ine(
|
||||
from app.api.errors import error_response
|
||||
from app.models import Identite
|
||||
|
||||
|
||||
def get_last_instance_etud_from_etudid_or_nip_or_ine(
|
||||
etudid=None, nip=None, ine=None
|
||||
) -> 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
|
||||
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.
|
||||
"""
|
||||
if etudid is None:
|
||||
if nip is None: # si ine
|
||||
etud = models.Identite.query.filter_by(code_ine=str(ine)).first()
|
||||
else: # si nip
|
||||
etud = models.Identite.query.filter_by(code_nip=str(nip)).first()
|
||||
else: # si etudid
|
||||
etud = models.Identite.query.filter_by(id=etudid).first()
|
||||
if etudid is not None:
|
||||
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()
|
||||
|
||||
return etud
|
||||
|
||||
|
@ -171,7 +171,6 @@ class Identite(db.Model):
|
||||
"""
|
||||
from app.scodoc import sco_photos
|
||||
|
||||
dept = models.Departement.query.filter_by(id=self.dept_id).first_or_404()
|
||||
d = {
|
||||
"civilite": self.civilite,
|
||||
"code_ine": self.code_ine or "",
|
||||
@ -180,7 +179,7 @@ class Identite(db.Model):
|
||||
if self.date_naissance
|
||||
else "",
|
||||
"dept_id": self.dept_id,
|
||||
"dept_acronym": dept.acronym,
|
||||
"dept_acronym": self.departement.acronym,
|
||||
"email": self.get_first_email() or "",
|
||||
"emailperso": self.get_first_email("emailperso"),
|
||||
"etudid": self.id,
|
||||
|
@ -54,7 +54,12 @@ class Evaluation(db.Model):
|
||||
# ScoDoc7 output_formators
|
||||
e["evaluation_id"] = self.id
|
||||
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["poids"] = self.get_ue_poids_dict() # { ue_id : poids }
|
||||
return evaluation_enrich_dict(e)
|
||||
|
||||
def from_dict(self, data):
|
||||
@ -153,7 +158,7 @@ class EvaluationUEPoids(db.Model):
|
||||
|
||||
# Fonction héritée de ScoDoc7 à refactorer
|
||||
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
|
||||
heure_debut_dt = e["heure_debut"] or datetime.time(
|
||||
8, 00
|
||||
|
Loading…
Reference in New Issue
Block a user