forked from ScoDoc/ScoDoc
remove all Model.query.get() [tests not OK] WIP
This commit is contained in:
parent
6eb3921774
commit
055839757b
@ -195,7 +195,7 @@ def justificatifs_dept(dept_id: int = None, with_query: bool = False):
|
||||
"""
|
||||
|
||||
# Récupération du département et des étudiants du département
|
||||
dept: Departement = Departement.query.get(dept_id)
|
||||
dept: Departement = db.session.get(Departement, dept_id)
|
||||
if dept is None:
|
||||
return json_error(404, "Assiduité non existante")
|
||||
etuds: list[int] = [etud.id for etud in dept.etudiants]
|
||||
|
@ -44,7 +44,9 @@ def formation_change_referentiel(
|
||||
ue.niveau_competence_id = niveaux_map[ue.niveau_competence_id]
|
||||
db.session.add(ue)
|
||||
if ue.parcours:
|
||||
new_list = [ApcParcours.query.get(parcours_map[p.id]) for p in ue.parcours]
|
||||
new_list = [
|
||||
db.session.get(ApcParcours, parcours_map[p.id]) for p in ue.parcours
|
||||
]
|
||||
ue.parcours.clear()
|
||||
ue.parcours.extend(new_list)
|
||||
db.session.add(ue)
|
||||
@ -52,7 +54,7 @@ def formation_change_referentiel(
|
||||
for module in formation.modules:
|
||||
if module.parcours:
|
||||
new_list = [
|
||||
ApcParcours.query.get(parcours_map[p.id]) for p in module.parcours
|
||||
db.session.get(ApcParcours, parcours_map[p.id]) for p in module.parcours
|
||||
]
|
||||
module.parcours.clear()
|
||||
module.parcours.extend(new_list)
|
||||
@ -76,7 +78,8 @@ def formation_change_referentiel(
|
||||
# FormSemestre / parcours_formsemestre
|
||||
for formsemestre in formation.formsemestres:
|
||||
new_list = [
|
||||
ApcParcours.query.get(parcours_map[p.id]) for p in formsemestre.parcours
|
||||
db.session.get(ApcParcours, parcours_map[p.id])
|
||||
for p in formsemestre.parcours
|
||||
]
|
||||
formsemestre.parcours.clear()
|
||||
formsemestre.parcours.extend(new_list)
|
||||
|
@ -178,7 +178,7 @@ def notes_sem_assemble_cube(modimpls_notes: list[pd.DataFrame]) -> np.ndarray:
|
||||
except ValueError:
|
||||
app.critical_error(
|
||||
f"""notes_sem_assemble_cube: shapes {
|
||||
", ".join([x.shape for x in modimpls_notes_arr])}"""
|
||||
", ".join([str(x.shape) for x in modimpls_notes_arr])}"""
|
||||
)
|
||||
return modimpls_notes.swapaxes(0, 1)
|
||||
|
||||
|
@ -297,7 +297,7 @@ class Assiduite(ScoDocModel):
|
||||
moduleimpl_id = int(moduleimpl_id)
|
||||
except ValueError as exc:
|
||||
raise ScoValueError("Module non reconnu") from exc
|
||||
moduleimpl: ModuleImpl = ModuleImpl.query.get(moduleimpl_id)
|
||||
moduleimpl: ModuleImpl = db.session.get(ModuleImpl, moduleimpl_id)
|
||||
|
||||
# ici moduleimpl est None si non spécifié
|
||||
|
||||
@ -352,8 +352,8 @@ class Assiduite(ScoDocModel):
|
||||
"""
|
||||
|
||||
if self.moduleimpl_id is not None:
|
||||
modimpl: ModuleImpl = ModuleImpl.query.get(self.moduleimpl_id)
|
||||
mod: Module = Module.query.get(modimpl.module_id)
|
||||
modimpl: ModuleImpl = db.session.get(ModuleImpl, self.moduleimpl_id)
|
||||
mod: Module = db.session.get(Module, modimpl.module_id)
|
||||
if traduire:
|
||||
return f"{mod.code} {mod.titre}"
|
||||
return mod
|
||||
|
@ -196,7 +196,7 @@ def check_if_has_decision_jury(
|
||||
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
||||
for etudid in etudids:
|
||||
if nt.etud_has_decision(etudid):
|
||||
etud = Identite.query.get(etudid)
|
||||
etud = db.session.get(Identite, etudid)
|
||||
raise ScoValueError(
|
||||
f"""désinscription impossible: l'étudiant {etud.nomprenom} a
|
||||
une décision de jury (la supprimer avant si nécessaire)"""
|
||||
|
@ -376,7 +376,7 @@ def formsemestre_inscr_passage(
|
||||
if a_desinscrire:
|
||||
H.append("<h3>Étudiants à désinscrire</h3><ol>")
|
||||
a_desinscrire_ident = sorted(
|
||||
(Identite.query.get(eid) for eid in a_desinscrire),
|
||||
(db.session.get(Identite, eid) for eid in a_desinscrire),
|
||||
key=lambda x: x.sort_key,
|
||||
)
|
||||
for etud in a_desinscrire_ident:
|
||||
|
@ -292,7 +292,7 @@ def _descr_decisions_ues(nt, etudid, decisions_ue, decision_sem) -> list[dict]:
|
||||
)
|
||||
)
|
||||
):
|
||||
ue = UniteEns.query.get(ue_id)
|
||||
ue = db.session.get(UniteEns, ue_id)
|
||||
assert ue
|
||||
# note modernisation code: on utilise des dict tant que get_etud_ue_status renvoie des dicts
|
||||
uelist.append(ue.to_dict())
|
||||
|
@ -408,7 +408,7 @@ def _check_inscription(
|
||||
elif etudid not in etudids_inscrits_mod:
|
||||
msg_err = "non inscrit au module"
|
||||
if msg_err:
|
||||
etud = Identite.query.get(etudid) if isinstance(etudid, int) else None
|
||||
etud = db.session.get(Identite, etudid) if isinstance(etudid, int) else None
|
||||
msg = f"étudiant {etud.nomprenom if etud else etudid} {msg_err}"
|
||||
log(f"notes_add: {etudid} {msg}: aborting")
|
||||
raise NoteProcessError(msg)
|
||||
@ -454,7 +454,7 @@ def notes_add(
|
||||
|
||||
if (value is not None) and not isinstance(value, float):
|
||||
log(f"notes_add: {etudid} valeur de note invalide ({value}): aborting")
|
||||
etud = Identite.query.get(etudid) if isinstance(etudid, int) else None
|
||||
etud = db.session.get(Identite, etudid) if isinstance(etudid, int) else None
|
||||
raise NoteProcessError(
|
||||
f"etudiant {etud.nomprenom if etud else etudid}: valeur de note invalide ({value})"
|
||||
)
|
||||
@ -491,7 +491,9 @@ def notes_add(
|
||||
# si change sur DEM/DEF ajoute message warning aux messages
|
||||
if etudid not in etudids_actifs: # DEM ou DEF
|
||||
etud = (
|
||||
Identite.query.get(etudid) if isinstance(etudid, int) else None
|
||||
db.session.get(Identite, etudid)
|
||||
if isinstance(etudid, int)
|
||||
else None
|
||||
)
|
||||
messages.append(
|
||||
f"""étudiant {etud.nomprenom if etud else etudid
|
||||
@ -801,7 +803,7 @@ def get_sorted_etuds_notes(
|
||||
notes_db[etudid]["value"], fixed_precision_str=False
|
||||
)
|
||||
user = (
|
||||
User.query.get(notes_db[etudid]["uid"])
|
||||
db.session.get(User, notes_db[etudid]["uid"])
|
||||
if notes_db[etudid]["uid"]
|
||||
else None
|
||||
)
|
||||
|
@ -144,7 +144,7 @@ def external_ue_create(
|
||||
),
|
||||
},
|
||||
)
|
||||
modimpl = ModuleImpl.query.get(moduleimpl_id)
|
||||
modimpl = db.session.get(ModuleImpl, moduleimpl_id)
|
||||
assert modimpl
|
||||
return modimpl
|
||||
|
||||
@ -206,7 +206,7 @@ def get_external_moduleimpl(formsemestre_id: int, ue_id: int) -> ModuleImpl:
|
||||
)
|
||||
if r:
|
||||
modimpl_id = r[0]["moduleimpl_id"]
|
||||
modimpl = ModuleImpl.query.get(modimpl_id)
|
||||
modimpl = db.session.get(ModuleImpl, modimpl_id)
|
||||
assert modimpl
|
||||
return modimpl
|
||||
else:
|
||||
|
@ -553,7 +553,7 @@ class RowAssiJusti(tb.Row):
|
||||
)
|
||||
if self.table.options.show_module:
|
||||
if self.ligne["type"] == "assiduite":
|
||||
assi: Assiduite = Assiduite.query.get(self.ligne["obj_id"])
|
||||
assi: Assiduite = db.session.get(Assiduite, self.ligne["obj_id"])
|
||||
# Gestion des colonnes concernant le module
|
||||
mod: Module = assi.get_module(False)
|
||||
code = mod.code if isinstance(mod, Module) else ""
|
||||
@ -607,7 +607,9 @@ class RowAssiJusti(tb.Row):
|
||||
|
||||
def _utilisateur(self) -> None:
|
||||
utilisateur: User = (
|
||||
User.query.get(self.ligne["user_id"]) if self.ligne["user_id"] else None
|
||||
db.session.get(User, self.ligne["user_id"])
|
||||
if self.ligne["user_id"] is not None
|
||||
else None
|
||||
)
|
||||
|
||||
self.add_cell(
|
||||
|
@ -24,6 +24,9 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
"""Vues assiduité
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import re
|
||||
@ -508,7 +511,7 @@ def _record_assiduite_etud(
|
||||
case None:
|
||||
moduleimpl = None
|
||||
case _:
|
||||
moduleimpl = ModuleImpl.query.get(moduleimpl_id)
|
||||
moduleimpl = db.session.get(ModuleImpl, moduleimpl_id)
|
||||
try:
|
||||
assi_etat: scu.EtatAssiduite = scu.EtatAssiduite.get(form.assi_etat.data)
|
||||
|
||||
@ -1678,7 +1681,7 @@ def _preparer_objet(
|
||||
if not sans_gros_objet:
|
||||
justificatifs: list[int] = get_assiduites_justif(objet.assiduite_id, False)
|
||||
for justi_id in justificatifs:
|
||||
justi: Justificatif = Justificatif.query.get(justi_id)
|
||||
justi: Justificatif = db.session.get(Justificatif, justi_id)
|
||||
objet_prepare["justification"]["justificatifs"].append(
|
||||
_preparer_objet("justificatif", justi, sans_gros_objet=True)
|
||||
)
|
||||
@ -1717,7 +1720,7 @@ def _preparer_objet(
|
||||
objet_prepare["etud_nom"] = objet.etudiant.nomprenom
|
||||
|
||||
if objet.user_id is not None:
|
||||
user: User = User.query.get(objet.user_id)
|
||||
user: User = db.session.get(User, objet.user_id)
|
||||
objet_prepare["saisie_par"] = user.get_nomprenom()
|
||||
else:
|
||||
objet_prepare["saisie_par"] = "Inconnu"
|
||||
@ -2925,7 +2928,7 @@ def _module_selector_multiple(
|
||||
)
|
||||
choices = OrderedDict()
|
||||
for formsemestre_id in modimpls_by_formsemestre:
|
||||
formsemestre: FormSemestre = FormSemestre.query.get(formsemestre_id)
|
||||
formsemestre: FormSemestre = db.session.get(FormSemestre, formsemestre_id)
|
||||
if only_form is not None and formsemestre != only_form:
|
||||
continue
|
||||
# indique le nom du semestre dans le menu (optgroup)
|
||||
|
@ -2112,7 +2112,7 @@ def check_group_apogee(group_id, etat=None, fix=False, fixmail=False):
|
||||
def export_etudiants_courants():
|
||||
"""Table export de tous les étudiants des formsemestres en cours."""
|
||||
fmt = request.args.get("fmt", "html")
|
||||
departement = Departement.query.get(g.scodoc_dept_id)
|
||||
departement = db.session.get(Departement, g.scodoc_dept_id)
|
||||
if not departement:
|
||||
raise ScoValueError("département invalide")
|
||||
formsemestres = FormSemestre.get_dept_formsemestres_courants(departement).all()
|
||||
@ -2462,7 +2462,7 @@ def formsemestre_import_etud_admission(
|
||||
Si tous_courants, le fait pour tous les formsemestres courants du département
|
||||
"""
|
||||
if tous_courants:
|
||||
departement = Departement.query.get(g.scodoc_dept_id)
|
||||
departement = db.session.get(Departement, g.scodoc_dept_id)
|
||||
formsemestres = FormSemestre.get_dept_formsemestres_courants(departement)
|
||||
else:
|
||||
formsemestres = [FormSemestre.get_formsemestre(formsemestre_id)]
|
||||
@ -2557,13 +2557,9 @@ def sco_dump_and_send_db(message="", request_url="", traceback_str_base64=""):
|
||||
try:
|
||||
r_msg = r.json()["message"]
|
||||
except (requests.exceptions.JSONDecodeError, KeyError):
|
||||
r_msg = "Erreur: code <tt>"
|
||||
+status_code
|
||||
+'</tt> Merci de contacter <a href="mailto:'
|
||||
+scu.SCO_DEV_MAIL
|
||||
+'">'
|
||||
+scu.SCO_DEV_MAIL
|
||||
+"</a>"
|
||||
r_msg = f"""Erreur: code <tt>{status_code}</tt>
|
||||
Merci de contacter <a href="mailto:{scu.SCO_DEV_MAIL}">{scu.SCO_DEV_MAIL}</a>
|
||||
"""
|
||||
|
||||
H = [html_sco_header.sco_header(page_title="Assistance technique")]
|
||||
if status_code == requests.codes.OK: # pylint: disable=no-member
|
||||
|
@ -4,10 +4,10 @@ Tableau de bord utilisateur
|
||||
Emmanuel Viennet, 2023
|
||||
"""
|
||||
|
||||
|
||||
from flask import flash, redirect, render_template, url_for
|
||||
from flask import g, request
|
||||
from flask_login import login_required
|
||||
from app import db
|
||||
from app.auth.models import User
|
||||
from app.decorators import (
|
||||
scodoc,
|
||||
@ -31,7 +31,8 @@ def user_board(user_name: str):
|
||||
modimpls_by_formsemestre,
|
||||
) = FormSemestre.get_user_formsemestres_annee_by_dept(user)
|
||||
depts = {
|
||||
dept_id: Departement.query.get(dept_id) for dept_id in formsemestres_by_dept
|
||||
dept_id: db.session.get(Departement, dept_id)
|
||||
for dept_id in formsemestres_by_dept
|
||||
}
|
||||
dept_names = {
|
||||
dept_id: sco_preferences.get_preference("DeptName", dept_id=dept_id)
|
||||
|
@ -250,7 +250,7 @@ def run_sco_basic(verbose=False, dept=None) -> FormSemestre:
|
||||
|
||||
|
||||
def _signal_absences_justificatifs(etudid: int):
|
||||
etud: Identite = Identite.query.get(etudid)
|
||||
etud: Identite = db.session.get(Identite, etudid)
|
||||
db.session.commit()
|
||||
for i in range(15, 18):
|
||||
db.session.add(
|
||||
|
Loading…
Reference in New Issue
Block a user