1
0
forked from ScoDoc/ScoDoc

Assiduites : fix user_id justi + fix scodoc_dept dans cache

This commit is contained in:
Iziram 2024-01-18 09:04:25 +01:00
parent 21eeff90aa
commit 4b304c559b
4 changed files with 26 additions and 12 deletions

View File

@ -434,6 +434,14 @@ class Justificatif(ScoDocModel):
etudiant = db.relationship(
"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)
@ -449,16 +457,10 @@ class Justificatif(ScoDocModel):
"""transformation de l'objet en dictionnaire sérialisable"""
etat = self.etat
username = self.user_id
user: User = self.user if self.user_id is not None else None
if format_api:
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 = {
"justif_id": self.justif_id,
@ -470,7 +472,9 @@ class Justificatif(ScoDocModel):
"raison": self.raison,
"fichier": self.fichier,
"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,
}
return data

View File

@ -6,7 +6,7 @@ from pytz import UTC
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
from app.models.assiduites import Assiduite, Justificatif, compute_assiduites_justified
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_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
sco_cache.RequeteTableauAssiduiteCache.delete_pattern(
pattern=f"tableau-etud-{etudid}:*"

View File

@ -529,9 +529,13 @@ class RowAssiJusti(tb.Row):
)
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(
"assiduites.tableau_assiduite_actions",
type=self.ligne["type"],

View File

@ -32,7 +32,9 @@ JUSTIFICATIFS_FIELDS = {
"raison": str,
"entry_date": str,
"fichier": str,
"user_id": int,
"user_id": int | None,
"user_name": int | None,
"user_nom_complet": int | None,
"external_data": dict,
}