forked from ScoDoc/ScoDoc
Assiduites : fix user_id justi + fix scodoc_dept dans cache
This commit is contained in:
parent
21eeff90aa
commit
4b304c559b
@ -434,6 +434,14 @@ class Justificatif(ScoDocModel):
|
|||||||
etudiant = db.relationship(
|
etudiant = db.relationship(
|
||||||
"Identite", back_populates="justificatifs", lazy="joined"
|
"Identite", back_populates="justificatifs", lazy="joined"
|
||||||
)
|
)
|
||||||
|
# En revanche, user est rarement accédé:
|
||||||
|
user = db.relationship(
|
||||||
|
"User",
|
||||||
|
backref=db.backref(
|
||||||
|
"justificatifs", lazy="select", order_by="Justificatif.entry_date"
|
||||||
|
),
|
||||||
|
lazy="select",
|
||||||
|
)
|
||||||
|
|
||||||
external_data = db.Column(db.JSON, nullable=True)
|
external_data = db.Column(db.JSON, nullable=True)
|
||||||
|
|
||||||
@ -449,16 +457,10 @@ class Justificatif(ScoDocModel):
|
|||||||
"""transformation de l'objet en dictionnaire sérialisable"""
|
"""transformation de l'objet en dictionnaire sérialisable"""
|
||||||
|
|
||||||
etat = self.etat
|
etat = self.etat
|
||||||
username = self.user_id
|
user: User = self.user if self.user_id is not None else None
|
||||||
|
|
||||||
if format_api:
|
if format_api:
|
||||||
etat = EtatJustificatif.inverse().get(self.etat).name
|
etat = EtatJustificatif.inverse().get(self.etat).name
|
||||||
if self.user_id is not None:
|
|
||||||
user: User = db.session.get(User, self.user_id)
|
|
||||||
if user is None:
|
|
||||||
username = "Non renseigné"
|
|
||||||
else:
|
|
||||||
username = user.get_prenomnom()
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"justif_id": self.justif_id,
|
"justif_id": self.justif_id,
|
||||||
@ -470,7 +472,9 @@ class Justificatif(ScoDocModel):
|
|||||||
"raison": self.raison,
|
"raison": self.raison,
|
||||||
"fichier": self.fichier,
|
"fichier": self.fichier,
|
||||||
"entry_date": self.entry_date,
|
"entry_date": self.entry_date,
|
||||||
"user_id": username,
|
"user_id": None if user is None else user.id, # l'uid
|
||||||
|
"user_name": None if user is None else user.user_name, # le login
|
||||||
|
"user_nom_complet": None if user is None else user.get_nomcomplet(),
|
||||||
"external_data": self.external_data,
|
"external_data": self.external_data,
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
@ -6,7 +6,7 @@ from pytz import UTC
|
|||||||
|
|
||||||
from flask_sqlalchemy.query import Query
|
from flask_sqlalchemy.query import Query
|
||||||
|
|
||||||
from app import log, db
|
from app import log, db, set_sco_dept
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
from app.models.assiduites import Assiduite, Justificatif, compute_assiduites_justified
|
from app.models.assiduites import Assiduite, Justificatif, compute_assiduites_justified
|
||||||
from app.models.etudiants import Identite
|
from app.models.etudiants import Identite
|
||||||
@ -756,6 +756,10 @@ def simple_invalidate_cache(obj: dict, etudid: str | int = None):
|
|||||||
invalidate_assiduites_etud_date(etudid, date_debut)
|
invalidate_assiduites_etud_date(etudid, date_debut)
|
||||||
invalidate_assiduites_etud_date(etudid, date_fin)
|
invalidate_assiduites_etud_date(etudid, date_fin)
|
||||||
|
|
||||||
|
# mettre à jour le scodoc_dept en fonction de l'étudiant
|
||||||
|
etud = Identite.query.filter_by(etudid=etudid).first_or_404()
|
||||||
|
set_sco_dept(etud.departement.acronym)
|
||||||
|
|
||||||
# Invalide les caches des tableaux de l'étudiant
|
# Invalide les caches des tableaux de l'étudiant
|
||||||
sco_cache.RequeteTableauAssiduiteCache.delete_pattern(
|
sco_cache.RequeteTableauAssiduiteCache.delete_pattern(
|
||||||
pattern=f"tableau-etud-{etudid}:*"
|
pattern=f"tableau-etud-{etudid}:*"
|
||||||
|
@ -529,9 +529,13 @@ class RowAssiJusti(tb.Row):
|
|||||||
)
|
)
|
||||||
html.append(f'<a title="Supprimer" href="{url}">❌</a>') # utiliser url_for
|
html.append(f'<a title="Supprimer" href="{url}">❌</a>') # utiliser url_for
|
||||||
|
|
||||||
# Justifier (si type Assiduité et est_just faux)
|
# Justifier (si type Assiduité, etat != Présent et est_just faux)
|
||||||
|
|
||||||
if self.ligne["type"] == "assiduite" and not self.ligne["est_just"]:
|
if (
|
||||||
|
self.ligne["type"] == "assiduite"
|
||||||
|
and self.ligne["etat"] != EtatAssiduite.PRESENT
|
||||||
|
and not self.ligne["est_just"]
|
||||||
|
):
|
||||||
url = url_for(
|
url = url_for(
|
||||||
"assiduites.tableau_assiduite_actions",
|
"assiduites.tableau_assiduite_actions",
|
||||||
type=self.ligne["type"],
|
type=self.ligne["type"],
|
||||||
|
@ -32,7 +32,9 @@ JUSTIFICATIFS_FIELDS = {
|
|||||||
"raison": str,
|
"raison": str,
|
||||||
"entry_date": str,
|
"entry_date": str,
|
||||||
"fichier": str,
|
"fichier": str,
|
||||||
"user_id": int,
|
"user_id": int | None,
|
||||||
|
"user_name": int | None,
|
||||||
|
"user_nom_complet": int | None,
|
||||||
"external_data": dict,
|
"external_data": dict,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user