1
0
forked from ScoDoc/ScoDoc

API: modif résultat de /etudiant(s)

This commit is contained in:
Emmanuel Viennet 2022-07-31 21:44:39 +02:00
parent a27fb9f3ef
commit bd718d456d
4 changed files with 18 additions and 104 deletions

View File

@ -71,34 +71,8 @@ def etudiants_courants(long=False):
...
]
En format "long":
{
"boursier": True,
"civilite": "F",
"code_ine": "AP987654",
"code_nip": "1234567",
"codepostaldomicile": "92800",
"date_naissance": "21/06/2000",
"dept_acronym": "CJ",
"dept_id": 1,
"dept_naissance": "092",
"description": "infos portail",
"domicile": "Plaza Condell",
"email": "jeanne.dupont@xxx.fr",
"emailperso": "",
"etudid": 4853,
"id": 4863,
"lieu_naissance": "SEVRES",
"nationalite": "",
"nom": "DUPONT",
"nomprenom": "Mme Jeanne Dupont",
"paysdomicile": "FRANCE",
"prenom": "JEANNE",
"telephone": "0102030405",
"telephonemobile": "",
"typeadresse": "domicile",
"villedomicile": "VALPARAISO",
}
En format "long": voir documentation.
"""
allowed_depts = current_user.get_depts_with_permission(Permission.ScoView)
etuds = Identite.query.filter(
@ -113,7 +87,7 @@ def etudiants_courants(long=False):
or_(Departement.acronym == acronym for acronym in allowed_depts)
)
if long:
data = [etud.to_dict_bul(include_urls=False) for etud in etuds]
data = [etud.to_dict_api() for etud in etuds]
else:
data = [etud.to_dict_short() for etud in etuds]
return jsonify(data)
@ -138,34 +112,6 @@ def etudiant(etudid: int = None, nip: str = None, ine: str = None):
Les codes INE et NIP sont uniques au sein d'un département.
Si plusieurs objets ont le même code, on ramène le plus récemment inscrit.
Exemple de résultat :
{
"civilite": "X",
"code_ine": "1",
"code_nip": "1",
"date_naissance": "",
"email": "SACHA.COSTA@example.com",
"emailperso": "",
"etudid": 1,
"nom": "COSTA",
"prenom": "SACHA",
"nomprenom": "Sacha COSTA",
"lieu_naissance": "",
"dept_naissance": "",
"nationalite": "",
"boursier": "",
"id": 1,
"codepostaldomicile": "",
"paysdomicile": "",
"telephonemobile": "",
"typeadresse": "domicile",
"domicile": "",
"villedomicile": "",
"telephone": "",
"fax": "",
"description": ""
}
"""
etud = tools.get_etud(etudid, nip, ine)
@ -175,7 +121,7 @@ def etudiant(etudid: int = None, nip: str = None, ine: str = None):
message="étudiant inconnu",
)
return jsonify(etud.to_dict_bul(include_urls=False))
return jsonify(etud.to_dict_api())
@bp.route("/etudiants/etudid/<int:etudid>", methods=["GET"])
@ -211,7 +157,7 @@ def etudiants(etudid: int = None, nip: str = None, ine: str = None):
etuds = etuds.join(Departement).filter(
or_(Departement.acronym == acronym for acronym in allowed_depts)
)
return jsonify([etud.to_dict_bul(include_urls=False) for etud in query])
return jsonify([etud.to_dict_api() for etud in query])
@bp.route("/etudiant/etudid/<int:etudid>/formsemestres")
@ -231,38 +177,6 @@ def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None)
différents (si l'étudiant a changé de département). L'id du département est `dept_id`.
Si accès par département, ne retourne que les formsemestre suivis dans le département.
Exemple de résultat :
[
{
"block_moyennes": false,
"bul_bgcolor": "white",
"bul_hide_xml": false,
"date_debut_iso": "2021-09-01",
"date_debut": "01/09/2021",
"date_fin_iso": "2022-08-31",
"date_fin": "31/08/2022",
"dept_id": 1,
"elt_annee_apo": null,
"elt_sem_apo": null,
"ens_can_edit_eval": false,
"etat": true,
"formation_id": 1,
"formsemestre_id": 1,
"gestion_compensation": false,
"gestion_semestrielle": false,
"id": 1,
"modalite": "FI",
"resp_can_change_ens": true,
"resp_can_edit": false,
"responsables": []
"scodoc7_id": null,
"semestre_id": 1,
"titre_num": "Semestre test semestre 1",
"titre": "Semestre test",
},
...
]
"""
if etudid is not None:
q_etud = Identite.query.filter_by(id=etudid)

View File

@ -207,6 +207,17 @@ class Identite(db.Model):
d["id"] = self.id # a été écrasé par l'id de adresse
return d
def to_dict_api(self) -> dict:
"""Représentation dictionnaire pour export API, avec adresses et admission."""
e = dict(self.__dict__)
e.pop("_sa_instance_state", None)
admission = self.admission.first()
e["admission"] = admission.to_dict() if admission is not None else None
e["adresses"] = [adr.to_dict() for adr in self.adresses]
e["dept_acronym"] = self.departement.acronym
e.pop("departement", None)
return e
def inscriptions(self) -> list["FormSemestreInscription"]:
"Liste des inscriptions à des formsemestres, triée, la plus récente en tête"
from app.models.formsemestre import FormSemestre, FormSemestreInscription

View File

@ -138,7 +138,6 @@ def test_etudiant(api_headers):
)
assert r.status_code == 200
etud_ine = r.json()
assert len(etud) == 26
fields_ok = verify_fields(etud, ETUD_FIELDS)
assert fields_ok is True

View File

@ -45,31 +45,21 @@ DEPARTEMENT_FIELDS = [
]
ETUD_FIELDS = {
"admission",
"adresses",
"boursier",
"civilite",
"code_ine",
"code_nip",
"codepostaldomicile",
"date_naissance",
"dept_acronym",
"dept_id",
"dept_naissance",
"description",
"domicile",
"email",
"emailperso",
"etudid",
"id",
"lieu_naissance",
"nationalite",
"nom",
"nomprenom",
"paysdomicile",
"prenom",
"telephone",
"telephonemobile",
"typeadresse",
"villedomicile",
}
FORMATION_FIELDS = {