Update opolka/ScoDoc from ScoDoc/ScoDoc #2

Merged
opolka merged 1272 commits from ScoDoc/ScoDoc:master into master 2024-05-27 09:11:04 +02:00
2 changed files with 15 additions and 10 deletions
Showing only changes of commit dbd0124c2c - Show all commits

View File

@ -105,7 +105,9 @@ def etudiants_courants(long=False):
) )
if long: if long:
restrict = not current_user.has_permission(Permission.ViewEtudData) restrict = not current_user.has_permission(Permission.ViewEtudData)
data = [etud.to_dict_api(restrict=restrict) for etud in etuds] data = [
etud.to_dict_api(restrict=restrict, with_annotations=True) for etud in etuds
]
else: else:
data = [etud.to_dict_short() for etud in etuds] data = [etud.to_dict_short() for etud in etuds]
return data return data
@ -140,7 +142,7 @@ def etudiant(etudid: int = None, nip: str = None, ine: str = None):
message="étudiant inconnu", message="étudiant inconnu",
) )
restrict = not current_user.has_permission(Permission.ViewEtudData) restrict = not current_user.has_permission(Permission.ViewEtudData)
return etud.to_dict_api(restrict=restrict) return etud.to_dict_api(restrict=restrict, with_annotations=True)
@bp.route("/etudiant/etudid/<int:etudid>/photo") @bp.route("/etudiant/etudid/<int:etudid>/photo")
@ -253,7 +255,9 @@ def etudiants(etudid: int = None, nip: str = None, ine: str = None):
or_(Departement.acronym == acronym for acronym in allowed_depts) or_(Departement.acronym == acronym for acronym in allowed_depts)
) )
restrict = not current_user.has_permission(Permission.ViewEtudData) restrict = not current_user.has_permission(Permission.ViewEtudData)
return [etud.to_dict_api(restrict=restrict) for etud in query] return [
etud.to_dict_api(restrict=restrict, with_annotations=True) for etud in query
]
@bp.route("/etudiants/name/<string:start>") @bp.route("/etudiants/name/<string:start>")

View File

@ -506,7 +506,7 @@ class Identite(models.ScoDocModel):
d["id"] = self.id # a été écrasé par l'id de adresse d["id"] = self.id # a été écrasé par l'id de adresse
return d return d
def to_dict_api(self, restrict=False) -> dict: def to_dict_api(self, restrict=False, with_annotations=False) -> dict:
"""Représentation dictionnaire pour export API, avec adresses et admission. """Représentation dictionnaire pour export API, avec adresses et admission.
Si restrict, supprime les infos "personnelles" (boursier) Si restrict, supprime les infos "personnelles" (boursier)
""" """
@ -518,12 +518,13 @@ class Identite(models.ScoDocModel):
e["dept_acronym"] = self.departement.acronym e["dept_acronym"] = self.departement.acronym
e.pop("departement", None) e.pop("departement", None)
e["sort_key"] = self.sort_key e["sort_key"] = self.sort_key
e["annotations"] = [ if with_annotations:
annot.to_dict(restrict=restrict) e["annotations"] = [
for annot in EtudAnnotation.query.filter_by(etudid=self.id).order_by( annot.to_dict(restrict=restrict)
desc(EtudAnnotation.date) for annot in EtudAnnotation.query.filter_by(etudid=self.id).order_by(
) desc(EtudAnnotation.date)
] )
]
if restrict: if restrict:
# Met à None les attributs protégés: # Met à None les attributs protégés:
for attr in self.protected_attrs: for attr in self.protected_attrs: