From 9bfebfc8a2192020b9baa9eaeeedecc595a470da Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 11 Jul 2023 06:57:38 +0200 Subject: [PATCH] =?UTF-8?q?Modifs=20pour=20SA=202.0=20(=C3=A0=20reporter?= =?UTF-8?q?=20en=209.5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 38f93cae99e4d3cc7eaac4fd2384728fb705aadb) --- app/api/absences.py | 5 +-- app/api/jury.py | 2 +- app/api/users.py | 2 +- app/auth/logic.py | 4 +-- app/auth/models.py | 6 ++-- app/but/bulletin_but.py | 3 +- app/but/cursus_but.py | 6 ++-- app/comp/moy_mod.py | 12 +++---- app/comp/moy_sem.py | 9 +++-- app/comp/res_but.py | 4 +-- app/comp/res_common.py | 8 +++-- app/comp/res_compat.py | 7 ++-- app/entreprises/forms.py | 9 +++-- app/models/evaluations.py | 8 +++-- app/models/events.py | 4 +-- app/models/formsemestre.py | 2 +- app/models/groups.py | 2 +- app/models/modules.py | 4 +-- app/models/notes.py | 2 +- app/pe/pe_semestretag.py | 4 +-- app/scodoc/sco_bulletins.py | 12 ++++--- app/scodoc/sco_bulletins_json.py | 4 +-- app/scodoc/sco_cache.py | 4 +-- app/scodoc/sco_edit_formation.py | 2 +- app/scodoc/sco_edit_matiere.py | 15 ++++---- app/scodoc/sco_edit_module.py | 16 ++++----- app/scodoc/sco_edit_ue.py | 17 +++++----- app/scodoc/sco_etud.py | 2 +- app/scodoc/sco_evaluation_db.py | 2 +- app/scodoc/sco_evaluation_edit.py | 11 +++--- app/scodoc/sco_evaluation_recap.py | 3 +- app/scodoc/sco_formation_recap.py | 5 ++- app/scodoc/sco_formation_versions.py | 8 ++--- app/scodoc/sco_formations.py | 6 ++-- app/scodoc/sco_formsemestre_edit.py | 6 ++-- app/scodoc/sco_formsemestre_status.py | 20 +++++++---- app/scodoc/sco_formsemestre_validation.py | 3 +- app/scodoc/sco_groups.py | 8 ++--- app/scodoc/sco_import_etuds.py | 18 +++++----- app/scodoc/sco_inscr_passage.py | 10 +++--- app/scodoc/sco_liste_notes.py | 8 ++--- app/scodoc/sco_moduleimpl.py | 13 +++---- app/scodoc/sco_moduleimpl_inscriptions.py | 9 +++-- app/scodoc/sco_moduleimpl_status.py | 6 ++-- app/scodoc/sco_page_etud.py | 10 +++--- app/scodoc/sco_permissions_check.py | 6 +++- app/scodoc/sco_preferences.py | 4 +-- app/scodoc/sco_pv_dict.py | 4 +-- app/scodoc/sco_pv_lettres_inviduelles.py | 3 +- app/scodoc/sco_report_but.py | 6 ++-- app/scodoc/sco_saisie_notes.py | 6 ++-- app/scodoc/sco_semset.py | 4 +-- app/scodoc/sco_ue_external.py | 9 ++--- app/tables/recap.py | 3 +- app/views/notes.py | 6 ++-- app/views/pn_modules.py | 4 +-- app/views/refcomp.py | 9 +++-- app/views/scodoc.py | 2 +- app/views/scolar.py | 2 +- scodoc.py | 2 +- tests/unit/sco_fake_gen.py | 2 +- tests/unit/setup.py | 12 +++---- tests/unit/test_abs_demijournee.py | 3 +- tests/unit/test_but_modules.py | 34 ++++++++----------- tests/unit/test_but_ues.py | 4 +-- tests/unit/test_formations.py | 9 ++--- tests/unit/test_notes_rattrapage.py | 6 ++-- tests/unit/test_refcomp.py | 11 +++--- tests/unit/yaml_setup.py | 6 ++-- .../fakedatabase/create_test_api_database.py | 2 +- 70 files changed, 251 insertions(+), 229 deletions(-) diff --git a/app/api/absences.py b/app/api/absences.py index b2d332676..acd690ffc 100644 --- a/app/api/absences.py +++ b/app/api/absences.py @@ -8,6 +8,7 @@ from flask_json import as_json +from app import db from app.api import api_bp as bp, API_CLIENT_ERROR from app.scodoc.sco_utils import json_error from app.decorators import scodoc, permission_required @@ -51,7 +52,7 @@ def absences(etudid: int = None): } ] """ - etud = Identite.query.get(etudid) + etud = db.session.get(Identite, etudid) if etud is None: return json_error(404, message="etudiant inexistant") # Absences de l'étudiant @@ -96,7 +97,7 @@ def absences_just(etudid: int = None): } ] """ - etud = Identite.query.get(etudid) + etud = db.session.get(Identite, etudid) if etud is None: return json_error(404, message="etudiant inexistant") diff --git a/app/api/jury.py b/app/api/jury.py index 6f0710770..2a86766c9 100644 --- a/app/api/jury.py +++ b/app/api/jury.py @@ -41,7 +41,7 @@ from app.scodoc.sco_utils import json_error def decisions_jury(formsemestre_id: int): """Décisions du jury des étudiants du formsemestre.""" # APC, pair: - formsemestre: FormSemestre = FormSemestre.query.get(formsemestre_id) + formsemestre: FormSemestre = db.session.get(FormSemestre, formsemestre_id) if formsemestre.formation.is_apc(): app.set_sco_dept(formsemestre.departement.acronym) rows = jury_but_results.get_jury_but_results(formsemestre) diff --git a/app/api/users.py b/app/api/users.py index 5cb3af446..32abccf25 100644 --- a/app/api/users.py +++ b/app/api/users.py @@ -35,7 +35,7 @@ def user_info(uid: int): """ Info sur un compte utilisateur scodoc """ - user: User = User.query.get(uid) + user: User = db.session.get(User, uid) if user is None: return json_error(404, "user not found") if g.scodoc_dept: diff --git a/app/auth/logic.py b/app/auth/logic.py index fc4ee02b4..496aea1d6 100644 --- a/app/auth/logic.py +++ b/app/auth/logic.py @@ -9,7 +9,7 @@ from flask import current_app, g, redirect, request, url_for from flask_httpauth import HTTPBasicAuth, HTTPTokenAuth import flask_login -from app import login +from app import db, login from app.auth.models import User from app.models.config import ScoDocSiteConfig from app.scodoc.sco_utils import json_error @@ -39,7 +39,7 @@ def basic_auth_error(status): @login.user_loader def load_user(uid: str) -> User: "flask-login: accès à un utilisateur" - return User.query.get(int(uid)) + return db.session.get(User, int(uid)) @token_auth.verify_token diff --git a/app/auth/models.py b/app/auth/models.py index 37bbf9868..a293685ee 100644 --- a/app/auth/models.py +++ b/app/auth/models.py @@ -225,7 +225,7 @@ class User(UserMixin, db.Model): return None except (TypeError, KeyError): return None - return User.query.get(user_id) + return db.session.get(User, user_id) def to_dict(self, include_email=True): """l'utilisateur comme un dict, avec des champs supplémentaires""" @@ -376,7 +376,9 @@ class User(UserMixin, db.Model): """ if not isinstance(role, Role): raise ScoValueError("add_role: rôle invalide") - self.user_roles.append(UserRole(user=self, role=role, dept=dept)) + user_role = UserRole(user=self, role=role, dept=dept) + db.session.add(user_role) + self.user_roles.append(user_role) def add_roles(self, roles: "list[Role]", dept: str): """Add roles to this user. diff --git a/app/but/bulletin_but.py b/app/but/bulletin_but.py index fc680dbc7..9bac0703a 100644 --- a/app/but/bulletin_but.py +++ b/app/but/bulletin_but.py @@ -12,6 +12,7 @@ import datetime import numpy as np from flask import g, has_request_context, url_for +from app import db from app.comp.res_but import ResultatsSemestreBUT from app.models import Evaluation, FormSemestre, Identite from app.models.groups import GroupDescr @@ -158,7 +159,7 @@ class BulletinBUT: [etud.id] ].iterrows(): if codes_cursus.code_ue_validant(ue_capitalisee.code): - ue = UniteEns.query.get(ue_capitalisee.ue_id) # XXX cacher ? + ue = db.session.get(UniteEns, ue_capitalisee.ue_id) # XXX cacher ? # déjà capitalisé ? montre la meilleure if ue.acronyme in d: moy_cap = d[ue.acronyme]["moyenne_num"] or 0.0 diff --git a/app/but/cursus_but.py b/app/but/cursus_but.py index 97a555ca6..748908be7 100644 --- a/app/but/cursus_but.py +++ b/app/but/cursus_but.py @@ -15,12 +15,10 @@ Classe raccordant avec ScoDoc 7: """ import collections from operator import attrgetter -from typing import Union from flask import g, url_for from app import db -from app import log from app.comp.res_but import ResultatsSemestreBUT from app.comp.res_compat import NotesTableCompat @@ -252,7 +250,9 @@ class FormSemestreCursusBUT: parcour = None else: if parcour_id not in self.parcours_by_id: - self.parcours_by_id[parcour_id] = ApcParcours.query.get(parcour_id) + self.parcours_by_id[parcour_id] = db.session.get( + ApcParcours, parcour_id + ) parcour = self.parcours_by_id[parcour_id] return self.get_niveaux_parcours_by_annee(parcour) diff --git a/app/comp/moy_mod.py b/app/comp/moy_mod.py index f69999a72..11dd05f62 100644 --- a/app/comp/moy_mod.py +++ b/app/comp/moy_mod.py @@ -134,7 +134,7 @@ class ModuleImplResults: manque des notes) ssi il y a des étudiants inscrits au semestre et au module qui ont des notes ATT. """ - moduleimpl = ModuleImpl.query.get(self.moduleimpl_id) + moduleimpl = db.session.get(ModuleImpl, self.moduleimpl_id) self.etudids = self._etudids() # --- Calcul nombre d'inscrits pour déterminer les évaluations "completes": @@ -225,8 +225,8 @@ class ModuleImplResults: """ return [ inscr.etudid - for inscr in ModuleImpl.query.get( - self.moduleimpl_id + for inscr in db.session.get( + ModuleImpl, self.moduleimpl_id ).formsemestre.inscriptions ] @@ -319,7 +319,7 @@ class ModuleImplResultsAPC(ModuleImplResults): ou NaN si les évaluations (dans lesquelles l'étudiant a des notes) ne donnent pas de coef vers cette UE. """ - modimpl = ModuleImpl.query.get(self.moduleimpl_id) + modimpl = db.session.get(ModuleImpl, self.moduleimpl_id) nb_etuds, nb_evals = self.evals_notes.shape nb_ues = evals_poids_df.shape[1] if evals_poids_df.shape[0] != nb_evals: @@ -419,7 +419,7 @@ def load_evaluations_poids(moduleimpl_id: int) -> tuple[pd.DataFrame, list]: Résultat: (evals_poids, liste de UEs du semestre sauf le sport) """ - modimpl: ModuleImpl = ModuleImpl.query.get(moduleimpl_id) + modimpl: ModuleImpl = db.session.get(ModuleImpl, moduleimpl_id) evaluations = Evaluation.query.filter_by(moduleimpl_id=moduleimpl_id).all() ues = modimpl.formsemestre.get_ues(with_sport=False) ue_ids = [ue.id for ue in ues] @@ -498,7 +498,7 @@ class ModuleImplResultsClassic(ModuleImplResults): ou NaN si les évaluations (dans lesquelles l'étudiant a des notes) ne donnent pas de coef. """ - modimpl = ModuleImpl.query.get(self.moduleimpl_id) + modimpl = db.session.get(ModuleImpl, self.moduleimpl_id) nb_etuds, nb_evals = self.evals_notes.shape if nb_etuds == 0: return pd.Series() diff --git a/app/comp/moy_sem.py b/app/comp/moy_sem.py index 089cc68a3..a1fe0104a 100644 --- a/app/comp/moy_sem.py +++ b/app/comp/moy_sem.py @@ -30,7 +30,10 @@ import numpy as np import pandas as pd -from flask import flash, g, Markup, url_for +from flask import flash, g, url_for +from markupsafe import Markup + +from app import db from app.models.formations import Formation @@ -78,7 +81,7 @@ def compute_sem_moys_apc_using_ects( moy_gen = (etud_moy_ue_df * ects).sum(axis=1) / ects.sum(axis=1) except TypeError: if None in ects: - formation = Formation.query.get(formation_id) + formation = db.session.get(Formation, formation_id) flash( Markup( f"""Calcul moyenne générale impossible: ECTS des UE manquants !
@@ -92,7 +95,7 @@ def compute_sem_moys_apc_using_ects( return moy_gen -def comp_ranks_series(notes: pd.Series) -> (pd.Series, pd.Series): +def comp_ranks_series(notes: pd.Series) -> tuple[pd.Series, pd.Series]: """Calcul rangs à partir d'une séries ("vecteur") de notes (index etudid, valeur numérique) en tenant compte des ex-aequos. diff --git a/app/comp/res_but.py b/app/comp/res_but.py index b2ba3eb5c..f79341725 100644 --- a/app/comp/res_but.py +++ b/app/comp/res_but.py @@ -14,7 +14,7 @@ from app import db, log from app.comp import moy_ue, moy_sem, inscr_mod from app.comp.res_compat import NotesTableCompat from app.comp.bonus_spo import BonusSport -from app.models import Formation, FormSemestreInscription, ScoDocSiteConfig +from app.models import FormSemestreInscription, ScoDocSiteConfig from app.models.moduleimpls import ModuleImpl from app.models.but_refcomp import ApcParcours, ApcNiveau from app.models.ues import DispenseUE, UniteEns @@ -291,7 +291,7 @@ class ResultatsSemestreBUT(NotesTableCompat): if parcour_id is None: ues_ids = {ue.id for ue in self.ues if ue.type != UE_SPORT} else: - parcour: ApcParcours = ApcParcours.query.get(parcour_id) + parcour: ApcParcours = db.session.get(ApcParcours, parcour_id) annee = (self.formsemestre.semestre_id + 1) // 2 niveaux = ApcNiveau.niveaux_annee_de_parcours(parcour, annee, ref_comp) # Les UEs du formsemestre associées à ces niveaux: diff --git a/app/comp/res_common.py b/app/comp/res_common.py index 54fd0de03..03b91e0cc 100644 --- a/app/comp/res_common.py +++ b/app/comp/res_common.py @@ -17,6 +17,7 @@ import pandas as pd from flask import g, url_for +from app import db from app.comp import res_sem from app.comp.res_cache import ResultatsCache from app.comp.jury import ValidationsSemestre @@ -31,6 +32,7 @@ from app.scodoc.codes_cursus import UE_SPORT from app.scodoc.sco_exceptions import ScoValueError from app.scodoc import sco_utils as scu + # Il faut bien distinguer # - ce qui est caché de façon persistente (via redis): # ce sont les attributs listés dans `_cached_attrs` @@ -137,7 +139,7 @@ class ResultatsSemestre(ResultatsCache): def etud_ues(self, etudid: int) -> Generator[UniteEns]: """Liste des UE auxquelles l'étudiant est inscrit (sans bonus, en BUT prend en compte le parcours de l'étudiant).""" - return (UniteEns.query.get(ue_id) for ue_id in self.etud_ues_ids(etudid)) + return (db.session.get(UniteEns, ue_id) for ue_id in self.etud_ues_ids(etudid)) def etud_ects_tot_sem(self, etudid: int) -> float: """Le total des ECTS associées à ce semestre (que l'étudiant peut ou non valider)""" @@ -351,7 +353,7 @@ class ResultatsSemestre(ResultatsCache): """L'état de l'UE pour cet étudiant. Result: dict, ou None si l'UE n'est pas dans ce semestre. """ - ue: UniteEns = UniteEns.query.get(ue_id) + ue: UniteEns = db.session.get(UniteEns, ue_id) ue_dict = ue.to_dict() if ue.type == UE_SPORT: @@ -401,7 +403,7 @@ class ResultatsSemestre(ResultatsCache): if (not coef_ue) and is_capitalized: # étudiant non inscrit dans l'UE courante if self.is_apc: # Coefs de l'UE capitalisée en formation APC: donné par ses ECTS - ue_capitalized = UniteEns.query.get(ue_cap["ue_id"]) + ue_capitalized = db.session.get(UniteEns, ue_cap["ue_id"]) coef_ue = ue_capitalized.ects if coef_ue is None: orig_sem = FormSemestre.get_formsemestre(ue_cap["formsemestre_id"]) diff --git a/app/comp/res_compat.py b/app/comp/res_compat.py index d5e85d99d..88fcd095f 100644 --- a/app/comp/res_compat.py +++ b/app/comp/res_compat.py @@ -9,9 +9,10 @@ from functools import cached_property import pandas as pd -from flask import flash, g, Markup, url_for +from flask import flash, g, url_for +from markupsafe import Markup -from app import log +from app import db, log from app.comp import moy_sem from app.comp.aux_stats import StatsMoyenne from app.comp.res_common import ResultatsSemestre @@ -393,7 +394,7 @@ class NotesTableCompat(ResultatsSemestre): de ce module. Évaluation "complete" ssi toutes notes saisies ou en attente. """ - modimpl = ModuleImpl.query.get(moduleimpl_id) + modimpl = db.session.get(ModuleImpl, moduleimpl_id) modimpl_results = self.modimpls_results.get(moduleimpl_id) if not modimpl_results: return [] # safeguard diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index 5bf3e03b7..c39ac7504 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -36,7 +36,6 @@ from sqlalchemy import text from wtforms import ( BooleanField, DateField, - DecimalField, FieldList, FormField, HiddenField, @@ -56,6 +55,9 @@ from wtforms.validators import ( ) from wtforms.widgets import ListWidget, CheckboxInput +from app import db +from app.auth.models import User +from app.entreprises import SIRET_PROVISOIRE_START from app.entreprises.models import ( Entreprise, EntrepriseCorrespondant, @@ -63,9 +65,6 @@ from app.entreprises.models import ( EntrepriseSite, EntrepriseTaxeApprentissage, ) -from app import db -from app.auth.models import User -from app.entreprises import SIRET_PROVISOIRE_START from app.models import Identite, Departement from app.scodoc import sco_utils as scu @@ -651,7 +650,7 @@ class StageApprentissageCreationForm(FlaskForm): def validate_etudid(self, field): "L'etudid doit avoit été placé par le JS" etudid = int(field.data) if field.data else None - etudiant = Identite.query.get(etudid) if etudid is not None else None + etudiant = db.session.get(Identite, etudid) if etudid is not None else None if etudiant is None: raise ValidationError("Étudiant introuvable (sélectionnez dans la liste)") diff --git a/app/models/evaluations.py b/app/models/evaluations.py index fd777b1c2..987b51706 100644 --- a/app/models/evaluations.py +++ b/app/models/evaluations.py @@ -190,8 +190,10 @@ class Evaluation(db.Model): """ L = [] for ue_id, poids in ue_poids_dict.items(): - ue = UniteEns.query.get(ue_id) - L.append(EvaluationUEPoids(evaluation=self, ue=ue, poids=poids)) + ue = db.session.get(UniteEns, ue_id) + ue_poids = EvaluationUEPoids(evaluation=self, ue=ue, poids=poids) + L.append(ue_poids) + db.session.add(ue_poids) self.ue_poids = L # backref # pylint:disable=attribute-defined-outside-init self.moduleimpl.invalidate_evaluations_poids() # inval cache @@ -338,7 +340,7 @@ def check_evaluation_args(args): jour = args.get("jour", None) args["jour"] = jour if jour: - modimpl = ModuleImpl.query.get(moduleimpl_id) + modimpl = db.session.get(ModuleImpl, moduleimpl_id) formsemestre = modimpl.formsemestre y, m, d = [int(x) for x in ndb.DateDMYtoISO(jour).split("-")] jour = datetime.date(y, m, d) diff --git a/app/models/events.py b/app/models/events.py index de93a24c0..74583b8a4 100644 --- a/app/models/events.py +++ b/app/models/events.py @@ -187,14 +187,14 @@ class ScolarNews(db.Model): elif self.type == self.NEWS_NOTE: moduleimpl_id = self.object if moduleimpl_id: - modimpl = ModuleImpl.query.get(moduleimpl_id) + modimpl = db.session.get(ModuleImpl, moduleimpl_id) if modimpl is None: return None # module does not exists anymore formsemestre_id = modimpl.formsemestre_id if not formsemestre_id: return None - formsemestre = FormSemestre.query.get(formsemestre_id) + formsemestre = db.session.get(FormSemestre, formsemestre_id) return formsemestre def notify_by_mail(self): diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index 8ab323cee..bac99fdf8 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -382,7 +382,7 @@ class FormSemestre(db.Model): ), {"formsemestre_id": self.id, "parcours_id": parcours.id}, ) - return [ModuleImpl.query.get(modimpl_id) for modimpl_id in cursor] + return [db.session.get(ModuleImpl, modimpl_id) for modimpl_id in cursor] def can_be_edited_by(self, user): """Vrai si user peut modifier ce semestre (est chef ou l'un des responsables)""" diff --git a/app/models/groups.py b/app/models/groups.py index 8e9d5b620..f2982cf42 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -149,7 +149,7 @@ class Partition(db.Model): if group.id == existing_group_id: return False # Fait le changement avec l'ORM sinon risque élevé de blocage - existing_group = GroupDescr.query.get(existing_group_id) + existing_group = db.session.get(GroupDescr, existing_group_id) db.session.commit() group.etuds.append(etud) existing_group.etuds.remove(etud) diff --git a/app/models/modules.py b/app/models/modules.py index 8295eedad..6aaaef198 100644 --- a/app/models/modules.py +++ b/app/models/modules.py @@ -198,7 +198,7 @@ class Module(db.Model): else: # crée nouveau coef: if coef != 0.0: - ue = UniteEns.query.get(ue_id) + ue = db.session.get(UniteEns, ue_id) ue_coef = ModuleUECoef(module=self, ue=ue, coef=coef) db.session.add(ue_coef) self.ue_coefs.append(ue_coef) @@ -232,7 +232,7 @@ class Module(db.Model): "delete_ue_coef: locked formation, ignoring request" ) raise ScoValueError("Formation verrouillée") - ue_coef = ModuleUECoef.query.get((self.id, ue.id)) + ue_coef = db.session.get(ModuleUECoef, (self.id, ue.id)) if ue_coef: db.session.delete(ue_coef) self.formation.invalidate_module_coefs() diff --git a/app/models/notes.py b/app/models/notes.py index 04ceb1c0f..2024a4368 100644 --- a/app/models/notes.py +++ b/app/models/notes.py @@ -57,7 +57,7 @@ class NotesNotes(db.Model): from app.models.evaluations import Evaluation return f"""<{self.__class__.__name__} {self.id} etudid={self.etudid} v={self.value} {self.date.isoformat() - } {Evaluation.query.get(self.evaluation_id) if self.evaluation_id else "X" }>""" + } {db.session.get(Evaluation, self.evaluation_id) if self.evaluation_id else "X" }>""" class NotesNotesLog(db.Model): diff --git a/app/pe/pe_semestretag.py b/app/pe/pe_semestretag.py index ee9535934..9e2d9b455 100644 --- a/app/pe/pe_semestretag.py +++ b/app/pe/pe_semestretag.py @@ -36,7 +36,7 @@ Created on Fri Sep 9 09:15:05 2016 @author: barasc """ -from app import log +from app import db, log from app.comp import res_sem from app.comp.res_compat import NotesTableCompat from app.models import FormSemestre @@ -487,7 +487,7 @@ def comp_coeff_pond(coeffs, ponderations): # ----------------------------------------------------------------------------- def get_moduleimpl(modimpl_id) -> dict: """Renvoie l'objet modimpl dont l'id est modimpl_id""" - modimpl = ModuleImpl.query.get(modimpl_id) + modimpl = db.session.get(ModuleImpl, modimpl_id) if modimpl: return modimpl if SemestreTag.DEBUG: diff --git a/app/scodoc/sco_bulletins.py b/app/scodoc/sco_bulletins.py index ca6b6fb8d..8a4d465c9 100644 --- a/app/scodoc/sco_bulletins.py +++ b/app/scodoc/sco_bulletins.py @@ -38,7 +38,7 @@ from flask import flash, render_template, url_for from flask_json import json_response from flask_login import current_user -from app import email +from app import db, email from app import log from app.scodoc.sco_utils import json_error from app.but import bulletin_but @@ -354,7 +354,7 @@ def formsemestre_bulletinetud_dict(formsemestre_id, etudid, version="long"): "modules_capitalized" ] = [] # modules de l'UE capitalisée (liste vide si pas capitalisée) if ue_status["is_capitalized"] and ue_status["formsemestre_id"] is not None: - sem_origin = FormSemestre.query.get(ue_status["formsemestre_id"]) + sem_origin = db.session.get(FormSemestre, ue_status["formsemestre_id"]) u[ "ue_descr_txt" ] = f'capitalisée le {ndb.DateISOtoDMY(ue_status["event_date"])}' @@ -369,7 +369,9 @@ def formsemestre_bulletinetud_dict(formsemestre_id, etudid, version="long"): ) if ue_status["moy"] != "NA": # détail des modules de l'UE capitalisée - formsemestre_cap = FormSemestre.query.get(ue_status["formsemestre_id"]) + formsemestre_cap = db.session.get( + FormSemestre, ue_status["formsemestre_id"] + ) nt_cap: NotesTableCompat = res_sem.load_formsemestre_results( formsemestre_cap ) @@ -749,7 +751,7 @@ def etud_descr_situation_semestre( res: ResultatsSemestreBUT = res_sem.load_formsemestre_results(formsemestre) parcour_id = res.etuds_parcour_id[etudid] parcour: ApcParcours = ( - ApcParcours.query.get(parcour_id) if parcour_id is not None else None + db.session.get(ApcParcours, parcour_id) if parcour_id is not None else None ) if parcour: infos["parcours_titre"] = parcour.libelle or "" @@ -928,7 +930,7 @@ def formsemestre_bulletinetud( """ format = format or "html" - formsemestre: FormSemestre = FormSemestre.query.get(formsemestre_id) + formsemestre: FormSemestre = db.session.get(FormSemestre, formsemestre_id) if not formsemestre: raise ScoValueError(f"semestre {formsemestre_id} inconnu !") diff --git a/app/scodoc/sco_bulletins_json.py b/app/scodoc/sco_bulletins_json.py index a93f4392e..85d4f60b0 100644 --- a/app/scodoc/sco_bulletins_json.py +++ b/app/scodoc/sco_bulletins_json.py @@ -33,7 +33,7 @@ import json from flask import abort -from app import ScoDocJSONEncoder +from app import db, ScoDocJSONEncoder from app.comp import res_sem from app.comp.res_compat import NotesTableCompat from app.models import but_validations @@ -245,7 +245,7 @@ def formsemestre_bulletinetud_published_dict( u["module"] = [] # Structure UE/Matière/Module # Recodé en 2022 - ue = UniteEns.query.get(ue_id) + ue = db.session.get(UniteEns, ue_id) u["matiere"] = [ { "matiere_id": mat.id, diff --git a/app/scodoc/sco_cache.py b/app/scodoc/sco_cache.py index 36b8db30b..31af42ebd 100644 --- a/app/scodoc/sco_cache.py +++ b/app/scodoc/sco_cache.py @@ -54,7 +54,7 @@ import traceback from flask import g import app -from app import log +from app import db, log from app.scodoc import notesdb as ndb from app.scodoc import sco_utils as scu from app.scodoc.sco_exceptions import ScoException @@ -266,7 +266,7 @@ def invalidate_formsemestre( # was inval_cache(formsemestre_id=None, pdfonly=Fa # appel via API ou tests sans dept: formsemestre = None if formsemestre_id: - formsemestre = FormSemestre.query.get(formsemestre_id) + formsemestre = db.session.get(FormSemestre, formsemestre_id) if formsemestre is None: raise ScoException("invalidate_formsemestre: departement must be set") app.set_sco_dept(formsemestre.departement.acronym, open_cnx=False) diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index a3ce002a0..2327071ba 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -103,7 +103,7 @@ def do_formation_delete(formation_id): """delete a formation (and all its UE, matieres, modules) Warning: delete all ues, will ask if there are validations ! """ - formation: Formation = Formation.query.get(formation_id) + formation: Formation = db.session.get(Formation, formation_id) if formation is None: return acronyme = formation.acronyme diff --git a/app/scodoc/sco_edit_matiere.py b/app/scodoc/sco_edit_matiere.py index 360e02fc2..614113fdf 100644 --- a/app/scodoc/sco_edit_matiere.py +++ b/app/scodoc/sco_edit_matiere.py @@ -30,14 +30,13 @@ """ import flask from flask import g, url_for, request -from app.models.events import ScolarNews -from app.models.formations import Matiere -from app.models.ues import UniteEns + +from app import db, log +from app.models import Formation, Matiere, UniteEns, ScolarNews import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu -from app import log -from app.models import Formation + from app.scodoc.TrivialFormulator import TrivialFormulator, tf_error_message from app.scodoc.sco_exceptions import ( ScoValueError, @@ -74,7 +73,7 @@ def do_matiere_edit(*args, **kw): # edit _matiereEditor.edit(cnx, *args, **kw) formation_id = sco_edit_ue.ue_list({"ue_id": mat["ue_id"]})[0]["formation_id"] - Formation.query.get(formation_id).invalidate_cached_sems() + db.session.get(Formation, formation_id).invalidate_cached_sems() def do_matiere_create(args): @@ -89,7 +88,7 @@ def do_matiere_create(args): r = _matiereEditor.create(cnx, args) # news - formation = Formation.query.get(ue["formation_id"]) + formation = db.session.get(Formation, ue["formation_id"]) ScolarNews.add( typ=ScolarNews.NEWS_FORM, obj=ue["formation_id"], @@ -201,7 +200,7 @@ def do_matiere_delete(oid): _matiereEditor.delete(cnx, oid) # news - formation = Formation.query.get(ue["formation_id"]) + formation = db.session.get(Formation, ue["formation_id"]) ScolarNews.add( typ=ScolarNews.NEWS_FORM, obj=ue["formation_id"], diff --git a/app/scodoc/sco_edit_module.py b/app/scodoc/sco_edit_module.py index 83476eb10..31148e0aa 100644 --- a/app/scodoc/sco_edit_module.py +++ b/app/scodoc/sco_edit_module.py @@ -98,10 +98,10 @@ def module_list(*args, **kw): def do_module_create(args) -> int: "Create a module. Returns id of new object." - formation = Formation.query.get(args["formation_id"]) + formation = db.session.get(Formation, args["formation_id"]) # refuse de créer un module APC avec semestres incohérents: if formation.is_apc(): - ue = UniteEns.query.get(args["ue_id"]) + ue = db.session.get(UniteEns, args["ue_id"]) if int(args.get("semestre_id", 0)) != ue.semestre_idx: raise ScoValueError("Formation incompatible: contacter le support ScoDoc") # create @@ -248,7 +248,7 @@ def do_module_edit(vals: dict) -> None: # edit cnx = ndb.GetDBConnexion() _moduleEditor.edit(cnx, vals) - Formation.query.get(mod["formation_id"]).invalidate_cached_sems() + db.session.get(Formation, mod["formation_id"]).invalidate_cached_sems() def check_module_code_unicity(code, field, formation_id, module_id=None): @@ -805,7 +805,7 @@ def module_edit( if create: if not matiere_id: # formulaire avec choix UE de rattachement - ue = UniteEns.query.get(tf[2]["ue_id"]) + ue = db.session.get(UniteEns, tf[2]["ue_id"]) if ue is None: raise ValueError("UE invalide") matiere = ue.matieres.first() @@ -819,7 +819,7 @@ def module_edit( tf[2]["semestre_id"] = ue.semestre_idx module_id = do_module_create(tf[2]) - module = Module.query.get(module_id) + module = db.session.get(Module, module_id) else: # EDITION MODULE # l'UE de rattachement peut changer tf[2]["ue_id"], tf[2]["matiere_id"] = tf[2]["ue_matiere_id"].split("!") @@ -837,7 +837,7 @@ def module_edit( ) # En APC, force le semestre égal à celui de l'UE if is_apc: - selected_ue = UniteEns.query.get(tf[2]["ue_id"]) + selected_ue = db.session.get(UniteEns, tf[2]["ue_id"]) if selected_ue is None: raise ValueError("UE invalide") tf[2]["semestre_id"] = selected_ue.semestre_idx @@ -853,13 +853,13 @@ def module_edit( module.parcours = formation.referentiel_competence.parcours.all() else: module.parcours = [ - ApcParcours.query.get(int(parcour_id_str)) + db.session.get(ApcParcours, int(parcour_id_str)) for parcour_id_str in tf[2]["parcours"] ] # Modifie les AC if "app_critiques" in tf[2]: module.app_critiques = [ - ApcAppCritique.query.get(int(ac_id_str)) + db.session.get(ApcAppCritique, int(ac_id_str)) for ac_id_str in tf[2]["app_critiques"] ] db.session.add(module) diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index 4d7aa131b..73bcd1002 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -36,8 +36,7 @@ from flask import flash, render_template, url_for from flask import g, request from flask_login import current_user -from app import db -from app import log +from app import db, log from app.but import apc_edit_ue from app.models import APO_CODE_STR_LEN, SHORT_STR_LEN from app.models import ( @@ -137,10 +136,10 @@ def do_ue_create(args): ue_id = _ueEditor.create(cnx, args) log(f"do_ue_create: created {ue_id} with {args}") - formation: Formation = Formation.query.get(args["formation_id"]) + formation: Formation = db.session.get(Formation, args["formation_id"]) formation.invalidate_module_coefs() # news - formation = Formation.query.get(args["formation_id"]) + formation = db.session.get(Formation, args["formation_id"]) ScolarNews.add( typ=ScolarNews.NEWS_FORM, obj=args["formation_id"], @@ -284,7 +283,7 @@ def ue_edit(ue_id=None, create=False, formation_id=None, default_semestre_idx=No } submitlabel = "Créer cette UE" can_change_semestre_id = True - formation = Formation.query.get(formation_id) + formation = db.session.get(Formation, formation_id) if not formation: raise ScoValueError(f"Formation inexistante ! (id={formation_id})") cursus = formation.get_cursus() @@ -543,7 +542,7 @@ def ue_edit(ue_id=None, create=False, formation_id=None, default_semestre_idx=No "semestre_id": tf[2]["semestre_idx"], }, ) - ue = UniteEns.query.get(ue_id) + ue = db.session.get(UniteEns, ue_id) flash(f"UE créée (code {ue.ue_code})") else: if not tf[2]["numero"]: @@ -597,7 +596,7 @@ def next_ue_numero(formation_id, semestre_id=None): """Numero d'une nouvelle UE dans cette formation. Si le semestre est specifie, cherche les UE ayant des modules de ce semestre """ - formation = Formation.query.get(formation_id) + formation = db.session.get(Formation, formation_id) ues = ue_list(args={"formation_id": formation_id}) if not ues: return 0 @@ -661,7 +660,7 @@ def ue_table(formation_id=None, semestre_idx=1, msg=""): # was ue_list """ from app.scodoc import sco_formsemestre_validation - formation: Formation = Formation.query.get(formation_id) + formation: Formation = db.session.get(Formation, formation_id) if not formation: raise ScoValueError("invalid formation_id") parcours = formation.get_cursus() @@ -1462,7 +1461,7 @@ def do_ue_edit(args, bypass_lock=False, dont_invalidate_cache=False): cnx = ndb.GetDBConnexion() _ueEditor.edit(cnx, args) - formation = Formation.query.get(ue["formation_id"]) + formation = db.session.get(Formation, ue["formation_id"]) if not dont_invalidate_cache: # Invalide les semestres utilisant cette formation # ainsi que les poids et coefs diff --git a/app/scodoc/sco_etud.py b/app/scodoc/sco_etud.py index 827363c89..2fb1f52da 100644 --- a/app/scodoc/sco_etud.py +++ b/app/scodoc/sco_etud.py @@ -262,7 +262,7 @@ def identite_list(cnx, *a, **kw): def identite_edit_nocheck(cnx, args): """Modifie les champs mentionnes dans args, sans verification ni notification.""" - etud = Identite.query.get(args["etudid"]) + etud = db.session.get(Identite, args["etudid"]) etud.from_dict(args) db.session.commit() diff --git a/app/scodoc/sco_evaluation_db.py b/app/scodoc/sco_evaluation_db.py index 7cbc32331..260481b99 100644 --- a/app/scodoc/sco_evaluation_db.py +++ b/app/scodoc/sco_evaluation_db.py @@ -129,7 +129,7 @@ def do_evaluation_create( ) args = locals() log("do_evaluation_create: args=" + str(args)) - modimpl: ModuleImpl = ModuleImpl.query.get(moduleimpl_id) + modimpl: ModuleImpl = db.session.get(ModuleImpl, moduleimpl_id) if modimpl is None: raise ValueError("module not found") check_evaluation_args(args) diff --git a/app/scodoc/sco_evaluation_edit.py b/app/scodoc/sco_evaluation_edit.py index a4b4414c4..ac9f6e2fa 100644 --- a/app/scodoc/sco_evaluation_edit.py +++ b/app/scodoc/sco_evaluation_edit.py @@ -37,11 +37,8 @@ from flask_login import current_user from flask import request from app import db -from app import log -from app import models -from app.models.evaluations import Evaluation -from app.models.formsemestre import FormSemestre -from app.models.moduleimpls import ModuleImpl +from app.models import Evaluation, FormSemestre, ModuleImpl + import app.scodoc.sco_utils as scu from app.scodoc.sco_utils import ModuleType from app.scodoc.sco_exceptions import ScoValueError @@ -62,7 +59,7 @@ def evaluation_create_form( ): "Formulaire création/édition d'une évaluation (pas de ses notes)" if evaluation_id is not None: - evaluation: Evaluation = models.Evaluation.query.get(evaluation_id) + evaluation: Evaluation = db.session.get(Evaluation, evaluation_id) if evaluation is None: raise ScoValueError("Cette évaluation n'existe pas ou plus !") moduleimpl_id = evaluation.moduleimpl_id @@ -363,7 +360,7 @@ def evaluation_create_form( evaluation_id = sco_evaluation_db.do_evaluation_create(**tf[2]) if is_apc: # Set poids - evaluation = models.Evaluation.query.get(evaluation_id) + evaluation = db.session.get(Evaluation, evaluation_id) for ue in sem_ues: evaluation.set_ue_poids(ue, tf[2][f"poids_{ue.id}"]) db.session.add(evaluation) diff --git a/app/scodoc/sco_evaluation_recap.py b/app/scodoc/sco_evaluation_recap.py index 635d6e8d1..c55843ca6 100644 --- a/app/scodoc/sco_evaluation_recap.py +++ b/app/scodoc/sco_evaluation_recap.py @@ -12,6 +12,7 @@ Sur une idée de Pascal Bouron, de Lyon. import time from flask import g, url_for +from app import db from app.models import Evaluation, FormSemestre from app.comp import res_sem from app.comp.res_compat import NotesTableCompat @@ -113,7 +114,7 @@ def evaluations_recap_table(formsemestre: FormSemestre) -> list[dict]: rows.append(row) line_idx += 1 for evaluation_id in modimpl_results.evals_notes: - e = Evaluation.query.get(evaluation_id) + e = db.session.get(Evaluation, evaluation_id) eval_etat = modimpl_results.evaluations_etat[evaluation_id] row = { "type": "", diff --git a/app/scodoc/sco_formation_recap.py b/app/scodoc/sco_formation_recap.py index e9ae85a31..c940b76e1 100644 --- a/app/scodoc/sco_formation_recap.py +++ b/app/scodoc/sco_formation_recap.py @@ -35,8 +35,7 @@ from flask import send_file, url_for from flask import g, request from flask_login import current_user -from app.models import Formation, FormSemestre, UniteEns, Module -from app.models.formations import Matiere +from app.models import Formation, FormSemestre, Matiere, Module, UniteEns from app.scodoc.gen_tables import GenTable from app.scodoc.sco_permissions import Permission @@ -178,7 +177,7 @@ def export_recap_formations_annee_scolaire(annee_scolaire): ) formation_ids = {formsemestre.formation.id for formsemestre in formsemestres} for formation_id in formation_ids: - formation = Formation.query.get(formation_id) + formation = db.session.get(Formation, formation_id) xls = formation_table_recap(formation_id, format="xlsx").data filename = ( scu.sanitize_filename(formation.get_titre_version()) + scu.XLSX_SUFFIX diff --git a/app/scodoc/sco_formation_versions.py b/app/scodoc/sco_formation_versions.py index 50d7c849a..9cce0c3ae 100644 --- a/app/scodoc/sco_formation_versions.py +++ b/app/scodoc/sco_formation_versions.py @@ -206,14 +206,14 @@ def do_formsemestres_associate_new_version( ) = sco_formations.formation_create_new_version(formation_id, redirect=False) # Log new ues: for ue_id in ues_old2new: - ue = UniteEns.query.get(ue_id) - new_ue = UniteEns.query.get(ues_old2new[ue_id]) + ue = db.session.get(UniteEns, ue_id) + new_ue = db.session.get(UniteEns, ues_old2new[ue_id]) assert ue.semestre_idx == new_ue.semestre_idx log(f"{ue} -> {new_ue}") # Log new modules for module_id in modules_old2new: - mod = Module.query.get(module_id) - new_mod = Module.query.get(modules_old2new[module_id]) + mod = db.session.get(Module, module_id) + new_mod = db.session.get(Module, modules_old2new[module_id]) assert mod.semestre_id == new_mod.semestre_id log(f"{mod} -> {new_mod}") # re-associate diff --git a/app/scodoc/sco_formations.py b/app/scodoc/sco_formations.py index 398ed7d47..d0c8b6884 100644 --- a/app/scodoc/sco_formations.py +++ b/app/scodoc/sco_formations.py @@ -163,7 +163,7 @@ def formation_export_dict( if tags: mod["tags"] = [{"name": x} for x in tags] # - module: Module = Module.query.get(module_id) + module: Module = db.session.get(Module, module_id) if module.is_apc(): # Exporte les coefficients if ue_reference_style == "id": @@ -359,7 +359,7 @@ def formation_import_xml(doc: str, import_tags=True, use_local_refcomp=False): referentiel_competence_id, ue_info[1] ) ue_id = sco_edit_ue.do_ue_create(ue_info[1]) - ue: UniteEns = UniteEns.query.get(ue_id) + ue: UniteEns = db.session.get(UniteEns, ue_id) assert ue if xml_ue_id: ues_old2new[xml_ue_id] = ue_id @@ -424,7 +424,7 @@ def formation_import_xml(doc: str, import_tags=True, use_local_refcomp=False): if xml_module_id: modules_old2new[int(xml_module_id)] = mod_id if len(mod_info) > 2: - module: Module = Module.query.get(mod_id) + module: Module = db.session.get(Module, mod_id) tag_names = [] ue_coef_dict = {} for child in mod_info[2]: diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index 9c8466ed2..41347f2d6 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -950,7 +950,7 @@ def do_formsemestre_createwithmodules(edit=False, formsemestre: FormSemestre = N formsemestre = FormSemestre.get_formsemestre(formsemestre_id) if "parcours" in tf[2]: formsemestre.parcours = [ - ApcParcours.query.get(int(parcour_id_str)) + db.session.get(ApcParcours, int(parcour_id_str)) for parcour_id_str in tf[2]["parcours"] ] db.session.add(formsemestre) @@ -1044,7 +1044,7 @@ def formsemestre_delete_moduleimpls(formsemestre_id, module_ids_to_del): ok = True msg = [] for module_id in module_ids_to_del: - module = Module.query.get(module_id) + module = db.session.get(Module, module_id) if module is None: continue # ignore invalid ids modimpls = ModuleImpl.query.filter_by( @@ -1224,7 +1224,7 @@ def do_formsemestre_clone( args["etat"] = 1 # non verrouillé formsemestre_id = sco_formsemestre.do_formsemestre_create(args) log(f"created formsemestre {formsemestre_id}") - formsemestre: FormSemestre = FormSemestre.query.get(formsemestre_id) + formsemestre: FormSemestre = db.session.get(FormSemestre, formsemestre_id) # 2- create moduleimpls mods_orig = sco_moduleimpl.moduleimpl_list(formsemestre_id=orig_formsemestre_id) for mod_orig in mods_orig: diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 94bbd766d..c1d15bfe3 100644 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -36,14 +36,20 @@ from flask import request from flask import flash, redirect, render_template, url_for from flask_login import current_user -from app import log +from app import db, log from app.but.cursus_but import formsemestre_warning_apc_setup from app.comp import res_sem from app.comp.res_common import ResultatsSemestre from app.comp.res_compat import NotesTableCompat -from app.models import Evaluation, Formation, Module, ModuleImpl, NotesNotes -from app.models.etudiants import Identite -from app.models.formsemestre import FormSemestre +from app.models import ( + Evaluation, + Formation, + FormSemestre, + Identite, + Module, + ModuleImpl, + NotesNotes, +) import app.scodoc.sco_utils as scu from app.scodoc.sco_utils import ModuleType from app.scodoc.sco_permissions import Permission @@ -753,7 +759,7 @@ def formsemestre_description_table( e["publish_incomplete_str"] = "Non" e["_publish_incomplete_str_td_attrs"] = 'style="color: red;"' # Poids vers UEs (en APC) - evaluation: Evaluation = Evaluation.query.get(e["evaluation_id"]) + evaluation: Evaluation = db.session.get(Evaluation, e["evaluation_id"]) for ue_id, poids in evaluation.get_ue_poids_dict().items(): e[f"ue_{ue_id}"] = poids or "" e[f"_ue_{ue_id}_class"] = "poids" @@ -974,7 +980,7 @@ def html_expr_diagnostic(diagnostics): def formsemestre_status_head(formsemestre_id: int = None, page_title: str = None): """En-tête HTML des pages "semestre" """ - sem: FormSemestre = FormSemestre.query.get(formsemestre_id) + sem: FormSemestre = db.session.get(FormSemestre, formsemestre_id) if not sem: raise ScoValueError("Semestre inexistant (il a peut être été supprimé ?)") formation: Formation = sem.formation @@ -1225,7 +1231,7 @@ def formsemestre_tableau_modules( H = [] prev_ue_id = None for modimpl in modimpls: - mod: Module = Module.query.get(modimpl["module_id"]) + mod: Module = db.session.get(Module, modimpl["module_id"]) moduleimpl_status_url = url_for( "notes.moduleimpl_status", scodoc_dept=g.scodoc_dept, diff --git a/app/scodoc/sco_formsemestre_validation.py b/app/scodoc/sco_formsemestre_validation.py index 6460fb4f9..e7bfecddd 100644 --- a/app/scodoc/sco_formsemestre_validation.py +++ b/app/scodoc/sco_formsemestre_validation.py @@ -69,6 +69,7 @@ from app.scodoc import sco_preferences from app.scodoc import sco_pv_dict from app.scodoc.sco_permissions import Permission + # ------------------------------------------------------------------------------------ def formsemestre_validation_etud_form( formsemestre_id=None, # required @@ -575,7 +576,7 @@ def formsemestre_recap_parcours_table( else: ass = "" - formsemestre = FormSemestre.query.get(sem["formsemestre_id"]) + formsemestre = db.session.get(FormSemestre, sem["formsemestre_id"]) nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) if is_cur: type_sem = "*" # now unused diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index ab3e014d5..e25601457 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -450,7 +450,7 @@ def get_etud_formsemestre_groups( ), {"etudid": etud.id, "formsemestre_id": formsemestre.id}, ) - return [GroupDescr.query.get(group_id) for group_id in cursor] + return [db.session.get(GroupDescr, group_id) for group_id in cursor] # Ancienne fonction: @@ -714,7 +714,7 @@ def setGroups( response.headers["Content-Type"] = scu.XML_MIMETYPE return response - partition: Partition = Partition.query.get(partition_id) + partition: Partition = db.session.get(Partition, partition_id) if not partition.groups_editable and (groupsToCreate or groupsToDelete): msg = "setGroups: partition non editable" log(msg) @@ -1484,7 +1484,7 @@ def _get_prev_moy(etudid, formsemestre_id): etud = info[0] Se = sco_cursus.get_situation_etud_cursus(etud, formsemestre_id) if Se.prev: - prev_sem = FormSemestre.query.get(Se.prev["formsemestre_id"]) + prev_sem = db.session.get(FormSemestre, Se.prev["formsemestre_id"]) nt: NotesTableCompat = res_sem.load_formsemestre_results(prev_sem) return nt.get_etud_moy_gen(etudid) else: @@ -1521,7 +1521,7 @@ def create_etapes_partition(formsemestre_id, partition_name="apo_etapes"): pid = partition_create( formsemestre_id, partition_name=partition_name, redirect=False ) - partition: Partition = Partition.query.get(pid) + partition: Partition = db.session.get(Partition, pid) groups = partition.groups groups_by_names = {g["group_name"]: g for g in groups} for etape in etapes: diff --git a/app/scodoc/sco_import_etuds.py b/app/scodoc/sco_import_etuds.py index 3141c412f..c2b3b8096 100644 --- a/app/scodoc/sco_import_etuds.py +++ b/app/scodoc/sco_import_etuds.py @@ -36,16 +36,12 @@ import time from flask import g, url_for -import app.scodoc.sco_utils as scu -import app.scodoc.notesdb as ndb -from app import log +from app import db, log from app.models import ScolarNews, GroupDescr from app.models.etudiants import input_civilite -from app.scodoc.sco_excel import COLORS -from app.scodoc.sco_formsemestre_inscriptions import ( - do_formsemestre_inscription_with_modules, -) + from app.scodoc.gen_tables import GenTable +from app.scodoc.sco_excel import COLORS from app.scodoc.sco_exceptions import ( AccessDenied, ScoFormatError, @@ -55,7 +51,6 @@ from app.scodoc.sco_exceptions import ( ScoLockedFormError, ScoGenError, ) - from app.scodoc import html_sco_header from app.scodoc import sco_cache from app.scodoc import sco_etud @@ -63,6 +58,11 @@ from app.scodoc import sco_groups from app.scodoc import sco_excel from app.scodoc import sco_groups_view from app.scodoc import sco_preferences +import app.scodoc.notesdb as ndb +from app.scodoc.sco_formsemestre_inscriptions import ( + do_formsemestre_inscription_with_modules, +) +import app.scodoc.sco_utils as scu # format description (in tools/) FORMAT_FILE = "format_import_etudiants.txt" @@ -719,7 +719,7 @@ def scolars_import_admission(datafile, formsemestre_id=None, type_admission=None ) for group_id in group_ids: - group = GroupDescr.query.get(group_id) + group = db.session.get(GroupDescr, group_id) if group.partition.groups_editable: sco_groups.change_etud_group_in_partition( args["etudid"], group diff --git a/app/scodoc/sco_inscr_passage.py b/app/scodoc/sco_inscr_passage.py index 50260e270..854e8c22a 100644 --- a/app/scodoc/sco_inscr_passage.py +++ b/app/scodoc/sco_inscr_passage.py @@ -35,7 +35,7 @@ from flask import url_for, g, request import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu -from app import log +from app import db, log from app.models import Formation, FormSemestre, GroupDescr from app.scodoc.gen_tables import GenTable from app.scodoc import html_sco_header @@ -177,7 +177,7 @@ def do_inscrit(sem, etudids, inscrit_groupes=False): En option: inscrit aux mêmes groupes que dans le semestre origine """ # TODO à ré-écrire pour utiliser le smodèle, notamment GroupDescr - formsemestre: FormSemestre = FormSemestre.query.get(sem["formsemestre_id"]) + formsemestre: FormSemestre = db.session.get(FormSemestre, sem["formsemestre_id"]) formsemestre.setup_parcours_groups() log(f"do_inscrit (inscrit_groupes={inscrit_groupes}): {etudids}") for etudid in etudids: @@ -220,7 +220,9 @@ def do_inscrit(sem, etudids, inscrit_groupes=False): # Inscrit aux groupes for partition_group in partition_groups: - group: GroupDescr = GroupDescr.query.get(partition_group["group_id"]) + group: GroupDescr = db.session.get( + GroupDescr, partition_group["group_id"] + ) sco_groups.change_etud_group_in_partition(etudid, group) @@ -433,7 +435,7 @@ def _build_page( inscrit_groupes=False, ignore_jury=False, ): - formsemestre: FormSemestre = FormSemestre.query.get(sem["formsemestre_id"]) + formsemestre: FormSemestre = db.session.get(FormSemestre, sem["formsemestre_id"]) inscrit_groupes = int(inscrit_groupes) ignore_jury = int(ignore_jury) if inscrit_groupes: diff --git a/app/scodoc/sco_liste_notes.py b/app/scodoc/sco_liste_notes.py index c54436806..9be70378c 100644 --- a/app/scodoc/sco_liste_notes.py +++ b/app/scodoc/sco_liste_notes.py @@ -33,7 +33,7 @@ import numpy as np import flask from flask import url_for, g, request -from app import log +from app import db, log from app import models from app.comp import res_sem from app.comp import moy_mod @@ -79,7 +79,7 @@ def do_evaluation_listenotes( return "

Aucune évaluation !

", "ScoDoc" E = evals[0] # il y a au moins une evaluation - modimpl = ModuleImpl.query.get(E["moduleimpl_id"]) + modimpl = db.session.get(ModuleImpl, E["moduleimpl_id"]) # description de l'evaluation if mode == "eval": H = [sco_evaluations.evaluation_describe(evaluation_id=evaluation_id)] @@ -624,7 +624,7 @@ def _make_table_notes( ] commentkeys = list(key_mgr.items()) # [ (comment, key), ... ] commentkeys.sort(key=lambda x: int(x[1])) - for (comment, key) in commentkeys: + for comment, key in commentkeys: C.append( '(%s) %s
' % (key, comment) ) @@ -673,7 +673,7 @@ def _add_eval_columns( sum_notes = 0 notes = [] # liste des notes numeriques, pour calcul histogramme uniquement evaluation_id = e["evaluation_id"] - e_o = Evaluation.query.get(evaluation_id) # XXX en attendant ré-écriture + e_o = db.session.get(Evaluation, evaluation_id) # XXX en attendant ré-écriture inscrits = e_o.moduleimpl.formsemestre.etudids_actifs # set d'etudids notes_db = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id) diff --git a/app/scodoc/sco_moduleimpl.py b/app/scodoc/sco_moduleimpl.py index 052512b0e..64ea3eb03 100644 --- a/app/scodoc/sco_moduleimpl.py +++ b/app/scodoc/sco_moduleimpl.py @@ -31,15 +31,16 @@ from flask_login import current_user import psycopg2 +from app import db + +from app.models import Formation +from app.scodoc import scolog +from app.scodoc import sco_formsemestre +from app.scodoc import sco_cache import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb from app.scodoc.sco_permissions import Permission from app.scodoc.sco_exceptions import ScoValueError, AccessDenied -from app import log -from app import models -from app.scodoc import scolog -from app.scodoc import sco_formsemestre -from app.scodoc import sco_cache # --- Gestion des "Implémentations de Modules" # Un "moduleimpl" correspond a la mise en oeuvre d'un module @@ -170,7 +171,7 @@ def moduleimpl_withmodule_list( mi["matiere"] = matieres[matiere_id] mod = modimpls[0]["module"] - formation = models.Formation.query.get(mod["formation_id"]) + formation = db.session.get(Formation, mod["formation_id"]) if formation.is_apc(): # tri par numero_module diff --git a/app/scodoc/sco_moduleimpl_inscriptions.py b/app/scodoc/sco_moduleimpl_inscriptions.py index 9cb7bf69b..0f12d38a0 100644 --- a/app/scodoc/sco_moduleimpl_inscriptions.py +++ b/app/scodoc/sco_moduleimpl_inscriptions.py @@ -34,6 +34,7 @@ import flask from flask import url_for, g, request from flask_login import current_user +from app import db, log from app.comp import res_sem from app.comp.res_compat import NotesTableCompat from app.models import ( @@ -43,9 +44,6 @@ from app.models import ( ScolarFormSemestreValidation, UniteEns, ) - -from app import log -from app.tables import list_etuds from app.scodoc.scolog import logdb from app.scodoc import html_sco_header from app.scodoc import htmlutils @@ -62,6 +60,7 @@ import app.scodoc.notesdb as ndb from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_permissions import Permission import app.scodoc.sco_utils as scu +from app.tables import list_etuds def moduleimpl_inscriptions_edit(moduleimpl_id, etuds=[], submitted=False): @@ -520,7 +519,7 @@ def _list_but_ue_inscriptions(res: NotesTableCompat, read_only: bool = True) -> else set() ) ues = sorted( - (UniteEns.query.get(ue_id) for ue_id in ue_ids), + (db.session.get(UniteEns, ue_id) for ue_id in ue_ids), key=lambda u: (u.numero or 0, u.acronyme), ) H.append( @@ -690,7 +689,7 @@ def _fmt_etud_set(etudids, max_list_size=7) -> str: return f"{len(etudids)} étudiants" etuds = [] for etudid in etudids: - etud = Identite.query.get(etudid) + etud = db.session.get(Identite, etudid) if etud: etuds.append(etud) diff --git a/app/scodoc/sco_moduleimpl_status.py b/app/scodoc/sco_moduleimpl_status.py index 838da20ac..55813afcf 100644 --- a/app/scodoc/sco_moduleimpl_status.py +++ b/app/scodoc/sco_moduleimpl_status.py @@ -227,7 +227,7 @@ def moduleimpl_status(moduleimpl_id=None, partition_id=None): ) arrow_up, arrow_down, arrow_none = sco_groups.get_arrow_icons_tags() # - module_resp = User.query.get(modimpl.responsable_id) + module_resp = db.session.get(User, modimpl.responsable_id) mod_type_name = scu.MODULE_TYPE_NAMES[module.module_type] H = [ html_sco_header.sco_header( @@ -529,7 +529,7 @@ def _ligne_evaluation( ) -> str: """Ligne décrivant une évaluation dans le tableau de bord moduleimpl.""" H = [] - # evaluation: Evaluation = Evaluation.query.get(eval_dict["evaluation_id"]) + # evaluation: Evaluation = db.session.get(Evaluation, eval_dict["evaluation_id"]) etat = sco_evaluations.do_evaluation_etat( evaluation.id, partition_id=partition_id, @@ -838,7 +838,7 @@ def _evaluation_poids_html(evaluation: Evaluation, max_poids: float = 0.0) -> st "> """ for ue, poids in ( - (UniteEns.query.get(ue_id), poids) + (db.session.get(UniteEns, ue_id), poids) for ue_id, poids in ue_poids.items() ) ] diff --git a/app/scodoc/sco_page_etud.py b/app/scodoc/sco_page_etud.py index cbb26f08f..fee4064f4 100644 --- a/app/scodoc/sco_page_etud.py +++ b/app/scodoc/sco_page_etud.py @@ -33,9 +33,7 @@ from flask import abort, url_for, g, render_template, request from flask_login import current_user -import app.scodoc.sco_utils as scu -import app.scodoc.notesdb as ndb -from app import log +from app import db, log from app.but import cursus_but from app.models.etudiants import Identite, make_etud_args from app.models.formsemestre import FormSemestre @@ -57,6 +55,8 @@ from app.scodoc.sco_bulletins import etud_descr_situation_semestre from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_formsemestre_validation import formsemestre_recap_parcours_table from app.scodoc.sco_permissions import Permission +import app.scodoc.sco_utils as scu +import app.scodoc.notesdb as ndb def _menu_scolarite( @@ -258,7 +258,9 @@ def ficheEtud(etudid=None): info["last_formsemestre_id"] = "" sem_info = {} for sem in info["sems"]: - formsemestre: FormSemestre = FormSemestre.query.get(sem["formsemestre_id"]) + formsemestre: FormSemestre = db.session.get( + FormSemestre, sem["formsemestre_id"] + ) if sem["ins"]["etat"] != scu.INSCRIT: descr, _ = etud_descr_situation_semestre( etudid, diff --git a/app/scodoc/sco_permissions_check.py b/app/scodoc/sco_permissions_check.py index dcc19f455..3ff5d3a3d 100644 --- a/app/scodoc/sco_permissions_check.py +++ b/app/scodoc/sco_permissions_check.py @@ -6,6 +6,7 @@ from flask import g from flask_login import current_user +from app import db from app.auth.models import User from app.models import FormSemestre import app.scodoc.notesdb as ndb @@ -131,7 +132,10 @@ def check_access_diretud(formsemestre_id, required_permission=Permission.ScoImpl "

Opération non autorisée pour %s

" % current_user, "

Responsable de ce semestre : %s

" % ", ".join( - [User.query.get(i).get_prenomnom() for i in sem["responsables"]] + [ + db.session.get(User, i).get_prenomnom() + for i in sem["responsables"] + ] ), footer, ] diff --git a/app/scodoc/sco_preferences.py b/app/scodoc/sco_preferences.py index 8c9bf5547..fd49ff670 100644 --- a/app/scodoc/sco_preferences.py +++ b/app/scodoc/sco_preferences.py @@ -113,9 +113,9 @@ get_base_preferences(formsemestre_id) import flask from flask import current_app, flash, g, request, url_for +from app import db, log from app.models import Departement from app.scodoc import sco_cache -from app import log from app.scodoc.sco_exceptions import ScoValueError, ScoException from app.scodoc.TrivialFormulator import TrivialFormulator import app.scodoc.notesdb as ndb @@ -272,7 +272,7 @@ class BasePreferences(object): ) def __init__(self, dept_id: int): - dept = Departement.query.get(dept_id) + dept = db.session.get(Departement, dept_id) if not dept: raise ScoValueError(f"BasePreferences: Invalid departement: {dept_id}") self.dept_id = dept.id diff --git a/app/scodoc/sco_pv_dict.py b/app/scodoc/sco_pv_dict.py index c48aa5f0b..f9861f54f 100644 --- a/app/scodoc/sco_pv_dict.py +++ b/app/scodoc/sco_pv_dict.py @@ -30,7 +30,7 @@ """ from operator import itemgetter -from app import log +from app import db from app.comp import res_sem from app.comp.res_compat import NotesTableCompat from app.models import ( @@ -253,7 +253,7 @@ def _comp_ects_by_ue_code(nt, decisions_ue): ects_by_ue_code = {} for ue_id in decisions_ue: d = decisions_ue[ue_id] - ue = UniteEns.query.get(ue_id) + ue = db.session.get(UniteEns, ue_id) ects_by_ue_code[ue.ue_code] = d["ects"] return ects_by_ue_code diff --git a/app/scodoc/sco_pv_lettres_inviduelles.py b/app/scodoc/sco_pv_lettres_inviduelles.py index 997645cac..747a0da75 100644 --- a/app/scodoc/sco_pv_lettres_inviduelles.py +++ b/app/scodoc/sco_pv_lettres_inviduelles.py @@ -42,6 +42,7 @@ from reportlab.platypus import PageBreak, Table, Image from reportlab.platypus.doctemplate import BaseDocTemplate from reportlab.lib import styles +from app import db from app.models import FormSemestre, Identite import app.scodoc.sco_utils as scu @@ -70,7 +71,7 @@ def pdf_lettres_individuelles( if not dpv: return "" # - formsemestre: FormSemestre = FormSemestre.query.get(formsemestre_id) + formsemestre: FormSemestre = db.session.get(FormSemestre, formsemestre_id) prefs = sco_preferences.SemPreferences(formsemestre_id) params = { "date_jury": date_jury, diff --git a/app/scodoc/sco_report_but.py b/app/scodoc/sco_report_but.py index 1aad34d59..5cfaa99e5 100644 --- a/app/scodoc/sco_report_but.py +++ b/app/scodoc/sco_report_but.py @@ -33,11 +33,9 @@ from collections import defaultdict from flask import request +from app import db from app.but import jury_but -from app.comp import res_sem -from app.comp.res_compat import NotesTableCompat from app.models import FormSemestre -from app.models.etudiants import Identite from app.models.formsemestre import FormSemestreInscription import app.scodoc.sco_utils as scu @@ -170,7 +168,7 @@ def but_indicateurs_by_bac(formsemestre: FormSemestre) -> dict[str:dict]: if deca and deca.formsemestre_impair } for formsemestre_id_precedent in formsemestre_id_precedents: - formsemestre_impair = FormSemestre.query.get(formsemestre_id_precedent) + formsemestre_impair = db.session.get(FormSemestre, formsemestre_id_precedent) suffix = ( f"S{formsemestre_impair.semestre_id}" if len(formsemestre_id_precedents) == 1 diff --git a/app/scodoc/sco_saisie_notes.py b/app/scodoc/sco_saisie_notes.py index 6e9084d0c..4838745ca 100644 --- a/app/scodoc/sco_saisie_notes.py +++ b/app/scodoc/sco_saisie_notes.py @@ -36,7 +36,7 @@ import flask from flask import g, url_for, request from flask_login import current_user -from app import log +from app import db, log from app.auth.models import User from app.comp import res_sem from app.comp.res_compat import NotesTableCompat @@ -878,7 +878,7 @@ def saisie_notes_tableur(evaluation_id, group_ids=()): def feuille_saisie_notes(evaluation_id, group_ids=[]): """Document Excel pour saisie notes dans l'évaluation et les groupes indiqués""" - evaluation: Evaluation = Evaluation.query.get(evaluation_id) + evaluation: Evaluation = db.session.get(Evaluation, evaluation_id) if not evaluation: raise ScoValueError("invalid evaluation_id") modimpl = evaluation.moduleimpl @@ -958,7 +958,7 @@ def saisie_notes(evaluation_id: int, group_ids: list = None): if not isinstance(evaluation_id, int): raise ScoInvalidParamError() group_ids = [int(group_id) for group_id in (group_ids or [])] - evaluation: Evaluation = Evaluation.query.get(evaluation_id) + evaluation: Evaluation = db.session.get(Evaluation, evaluation_id) if evaluation is None: raise ScoValueError("évaluation inexistante") modimpl = evaluation.moduleimpl diff --git a/app/scodoc/sco_semset.py b/app/scodoc/sco_semset.py index 251d0468b..49ec35e08 100644 --- a/app/scodoc/sco_semset.py +++ b/app/scodoc/sco_semset.py @@ -42,7 +42,7 @@ sem_set_list() import flask from flask import g, url_for -from app import log +from app import db, log from app.comp import res_sem from app.comp.res_compat import NotesTableCompat from app.models import FormSemestre @@ -127,7 +127,7 @@ class SemSet(dict): self.sems = [] self.formsemestres = [] for formsemestre_id in self.formsemestre_ids: - formsemestre: FormSemestre = FormSemestre.query.get(formsemestre_id) + formsemestre: FormSemestre = db.session.get(FormSemestre, formsemestre_id) self.formsemestres.append(formsemestre) sem = sco_formsemestre.get_formsemestre(formsemestre_id) self.sems.append(sem) diff --git a/app/scodoc/sco_ue_external.py b/app/scodoc/sco_ue_external.py index 55d2e289b..22471d3c4 100644 --- a/app/scodoc/sco_ue_external.py +++ b/app/scodoc/sco_ue_external.py @@ -58,9 +58,8 @@ from flask import flash, g, request, url_for from flask_login import current_user from app.models.formsemestre import FormSemestre -import app.scodoc.notesdb as ndb -import app.scodoc.sco_utils as scu -from app import log + +from app import db, log from app.models import UniteEns from app.scodoc import html_sco_header from app.scodoc import codes_cursus @@ -74,6 +73,8 @@ from app.scodoc import sco_etud from app.scodoc.sco_exceptions import AccessDenied, ScoValueError from app.scodoc.sco_permissions import Permission from app.scodoc.TrivialFormulator import TrivialFormulator, tf_error_message +import app.scodoc.notesdb as ndb +import app.scodoc.sco_utils as scu def external_ue_create( @@ -114,7 +115,7 @@ def external_ue_create( "is_external": True, }, ) - ue = UniteEns.query.get(ue_id) + ue = db.session.get(UniteEns, ue_id) flash(f"UE créée (code {ue.ue_code})") matiere_id = sco_edit_matiere.do_matiere_create( {"ue_id": ue_id, "titre": titre or acronyme, "numero": 1} diff --git a/app/tables/recap.py b/app/tables/recap.py index 09aae9188..30bc3d964 100644 --- a/app/tables/recap.py +++ b/app/tables/recap.py @@ -10,6 +10,7 @@ from flask import g, url_for import numpy as np +from app import db from app.auth.models import User from app.comp.res_common import ResultatsSemestre from app.models import Identite, FormSemestre, UniteEns @@ -802,7 +803,7 @@ class RowRecap(tb.Row): nom_resp = table.cache_nomcomplet.get(modimpl.responsable_id) if nom_resp is None: - user = User.query.get(modimpl.responsable_id) + user = db.session.get(User, modimpl.responsable_id) nom_resp = user.get_nomcomplet() if user else "" table.cache_nomcomplet[modimpl.responsable_id] = nom_resp table.foot_title_row.cells[col_id].target_attrs[ diff --git a/app/views/notes.py b/app/views/notes.py index 4ee25a900..da80388a3 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -472,7 +472,7 @@ def ue_infos(ue_id): @scodoc7func def ue_set_internal(ue_id): """""" - ue = models.UniteEns.query.get(ue_id) + ue = db.session.get(UniteEns, ue_id) if not ue: raise ScoValueError("invalid ue_id") ue.is_external = False @@ -927,7 +927,7 @@ def edit_enseignants_form(moduleimpl_id): % uid2display.get(M["responsable_id"], M["responsable_id"]) ] for ens in M["ens"]: - u = User.query.get(ens["ens_id"]) + u = db.session.get(User, ens["ens_id"]) if u: nom = u.get_nomcomplet() else: @@ -1823,7 +1823,7 @@ def evaluation_edit(evaluation_id): @scodoc7func def evaluation_create(moduleimpl_id): "form create evaluation" - modimpl = ModuleImpl.query.get(moduleimpl_id) + modimpl = db.session.get(ModuleImpl, moduleimpl_id) if modimpl is None: raise ScoValueError("Ce module n'existe pas ou plus !") return sco_evaluation_edit.evaluation_create_form( diff --git a/app/views/pn_modules.py b/app/views/pn_modules.py index e18e707e3..b3d302847 100644 --- a/app/views/pn_modules.py +++ b/app/views/pn_modules.py @@ -164,10 +164,10 @@ def set_module_ue_coef(): coef = float(request.form["coef"].replace(",", ".")) except ValueError: return scu.json_error(404, "invalid coef") - module: Module = models.Module.query.get(module_id) + module: Module = db.session.get(Module, module_id) if module is None: return scu.json_error(404, f"module not found ({module_id})") - ue = models.UniteEns.query.get(ue_id) + ue = db.session.get(models.UniteEns, ue_id) if not ue: return scu.json_error(404, f"UE not found ({ue_id})") module.set_ue_coef(ue, coef) diff --git a/app/views/refcomp.py b/app/views/refcomp.py index 83f6645f9..830968887 100644 --- a/app/views/refcomp.py +++ b/app/views/refcomp.py @@ -7,17 +7,15 @@ from pathlib import Path import re from flask import flash, url_for -from flask import Markup from flask import current_app, g, request from flask.templating import render_template from flask_json import as_json from flask_login import current_user +from markupsafe import Markup from werkzeug.utils import redirect from werkzeug.utils import secure_filename -from app import db -from app import log - +from app import db, log from app.decorators import scodoc, permission_required from app.models import Formation from app.models.but_refcomp import ApcReferentielCompetences @@ -148,7 +146,8 @@ def refcomp_assoc_formation(formation_id: int): if form.validate_on_submit(): referentiel_competence_id = form.referentiel_competence.data assert ( - ApcReferentielCompetences.query.get(referentiel_competence_id) is not None + db.session.get(ApcReferentielCompetences, referentiel_competence_id) + is not None ) formation.referentiel_competence_id = referentiel_competence_id db.session.add(formation) diff --git a/app/views/scodoc.py b/app/views/scodoc.py index 02369be60..c4c124752 100644 --- a/app/views/scodoc.py +++ b/app/views/scodoc.py @@ -248,7 +248,7 @@ def get_etud_dept(): for etud in etuds: inscriptions = FormSemestreInscription.query.filter_by(etudid=etud.id).all() for ins in inscriptions: - date_fin = FormSemestre.query.get(ins.formsemestre_id).date_fin + date_fin = db.session.get(FormSemestre, ins.formsemestre_id).date_fin if (last_date is None) or date_fin > last_date: last_date = date_fin last_etud = etud diff --git a/app/views/scolar.py b/app/views/scolar.py index 19ec1c7d2..b8f103232 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -1744,7 +1744,7 @@ def _etudident_create_or_edit_form(edit): etudid = etud["etudid"] else: # modif d'un etudiant - etud_o = Identite.query.get(tf[2]["etudid"]) + etud_o = db.session.get(Identite, tf[2]["etudid"]) etud_o.from_dict(tf[2]) db.session.add(etud_o) admission = etud_o.admission.first() diff --git a/scodoc.py b/scodoc.py index 2fd0f9a2e..f541cce66 100755 --- a/scodoc.py +++ b/scodoc.py @@ -525,7 +525,7 @@ def photos_import_files(formsemestre_id: int, xlsfile: str, zipfile: str): from app.scodoc import sco_trombino, sco_photos from app.auth.models import get_super_admin - formsemestre = FormSemestre.query.get(formsemestre_id) + formsemestre = db.session.get(FormSemestre, formsemestre_id) if not formsemestre: sys.stderr.write("photos-import-files: formsemestre_id invalide\n") return 2 diff --git a/tests/unit/sco_fake_gen.py b/tests/unit/sco_fake_gen.py index 8ca26fe01..93508c7b3 100644 --- a/tests/unit/sco_fake_gen.py +++ b/tests/unit/sco_fake_gen.py @@ -224,7 +224,7 @@ class ScoFake(object): code_apogee=None, module_type=scu.ModuleType.STANDARD, ) -> int: - matiere = Matiere.query.get(matiere_id) + matiere = db.session.get(Matiere, matiere_id) ue_id = matiere.ue.id formation_id = matiere.ue.formation.id oid = sco_edit_module.do_module_create(locals()) diff --git a/tests/unit/setup.py b/tests/unit/setup.py index dced6a714..0930a414a 100644 --- a/tests/unit/setup.py +++ b/tests/unit/setup.py @@ -2,7 +2,7 @@ Quelques fonctions d'initialisation pour tests unitaires """ -from app import models +from app import db, models import app.scodoc.sco_utils as scu from app.scodoc import codes_cursus @@ -101,11 +101,11 @@ def build_modules_with_evaluations( G, formation_id, (ue1_id, ue2_id, ue3_id), module_ids = build_formation_test( nb_mods=nb_mods ) - ue1 = models.UniteEns.query.get(ue1_id) - ue2 = models.UniteEns.query.get(ue2_id) - ue3 = models.UniteEns.query.get(ue3_id) + ue1 = db.session.get(models.UniteEns, ue1_id) + ue2 = db.session.get(models.UniteEns, ue2_id) + ue3 = db.session.get(models.UniteEns, ue3_id) for module_id in module_ids: - mod = models.Module.query.get(module_id) + mod = db.session.get(models.Module, module_id) # Coef du module vers les UE c1, c2, c3 = ue_coefs coefs_mod = {ue1.id: c1, ue2.id: c2, ue3.id: c3} @@ -124,7 +124,7 @@ def build_modules_with_evaluations( module_id=module_id, formsemestre_id=formsemestre_id, ) - modimpl = models.ModuleImpl.query.get(moduleimpl_id) + modimpl = db.session.get(models.ModuleImpl, moduleimpl_id) assert modimpl.formsemestre.formation.get_cursus().APC_SAE # BUT # Check ModuleImpl ues = modimpl.formsemestre.get_ues() diff --git a/tests/unit/test_abs_demijournee.py b/tests/unit/test_abs_demijournee.py index c486a9844..a4783a0f7 100644 --- a/tests/unit/test_abs_demijournee.py +++ b/tests/unit/test_abs_demijournee.py @@ -9,6 +9,7 @@ Créer et justifier des absences en utilisant le parametre demijournee import json from tests.unit import sco_fake_gen +from app import db from app.models import Module from app.scodoc import sco_abs from app.scodoc import sco_abs_views @@ -258,7 +259,7 @@ def test_abs_basic(test_client): assert len(load_liste_abs) == 2 assert load_liste_abs2[0]["ampm"] == 1 assert load_liste_abs2[0]["datedmy"] == "22/01/2021" - mod = Module.query.get(module_id) + mod = db.session.get(Module, module_id) assert load_liste_abs2[0]["exams"] == mod.code # absjust_only -> seulement les abs justifiés diff --git a/tests/unit/test_but_modules.py b/tests/unit/test_but_modules.py index b09ad783f..66b818fbc 100644 --- a/tests/unit/test_but_modules.py +++ b/tests/unit/test_but_modules.py @@ -4,15 +4,12 @@ et calcul moyennes modules """ import numpy as np import pandas as pd -from app.models.modules import Module -from app.models.moduleimpls import ModuleImpl from tests.unit import setup from app import db -from app import models +from app.models import Evaluation, EvaluationUEPoids, Module, ModuleImpl, UniteEns from app.comp import moy_mod from app.comp import moy_ue -from app.models import Evaluation from app.scodoc import sco_saisie_notes from app.scodoc.sco_utils import ( NOTES_ATTENTE, @@ -57,18 +54,16 @@ def test_evaluation_poids(test_client): # ue1_id=1684 # formation_id=199 # - e1 = models.Evaluation.query.get(evaluation_id) - ue1 = models.UniteEns.query.get(ue1_id) + e1 = db.session.get(Evaluation, evaluation_id) + ue1 = db.session.get(UniteEns, ue1_id) assert e1.ue_poids == [] p1 = 3.14 e1.set_ue_poids(ue1, p1) db.session.commit() assert e1.get_ue_poids_dict()[ue1_id] == p1 - ues = models.UniteEns.query.filter_by( - formation_id=formation_id, semestre_idx=2 - ).all() + ues = UniteEns.query.filter_by(formation_id=formation_id, semestre_idx=2).all() poids = [1.0, 2.0, 3.0] - for (ue, p) in zip(ues, poids): + for ue, p in zip(ues, poids): e1.set_ue_poids(ue, p) assert len(e1.ue_poids) == len(ues) assert e1.get_ue_poids_dict()[ues[1].id] == poids[1] @@ -85,15 +80,15 @@ def test_evaluation_poids(test_client): # Delete eval db.session.delete(e1) db.session.commit() - assert len(models.EvaluationUEPoids.query.all()) == 0 + assert len(EvaluationUEPoids.query.all()) == 0 def test_modules_coefs(test_client): """Coefs vers les UE (BUT)""" G, formation_id, (ue1_id, ue2_id, ue3_id), module_ids = setup.build_formation_test() - ue1 = models.UniteEns.query.get(ue1_id) - ue2 = models.UniteEns.query.get(ue2_id) - mod = models.Module.query.get(module_ids[0]) + ue1 = db.session.get(UniteEns, ue1_id) + ue2 = db.session.get(UniteEns, ue2_id) + mod = db.session.get(Module, module_ids[0]) coef = 2.5 mod.set_ue_coef(ue1, coef) db.session.commit() @@ -127,7 +122,7 @@ def test_module_conformity(test_client): nb_mods = 1 # 1 seul module nb_evals = 1 # 1 seule evaluation pour l'instant p1, p2, p3 = 1.0, 2.0, 0.0 # poids de l'éval vers les UE 1, 2 et 3 - evaluation = models.Evaluation.query.get(evaluation_ids[0]) + evaluation = db.session.get(Evaluation, evaluation_ids[0]) evaluation.set_ue_poids_dict({ue1.id: p1, ue2.id: p2, ue3.id: p3}) assert evaluation.get_ue_poids_dict() == {ue1.id: p1, ue2.id: p2, ue3.id: p3} # On n'est pas conforme car p3 est nul alors que c3 est non nul @@ -219,7 +214,7 @@ def test_module_moy(test_client): etud = G.create_etud(nom="test") G.inscrit_etudiant(formsemestre_id, etud) etudid = etud["etudid"] - evaluation1 = models.Evaluation.query.get(evaluation1_ids[0]) + evaluation1 = db.session.get(Evaluation, evaluation1_ids[0]) # Crée une deuxième évaluation dans le même moduleimpl: evaluation2_id = G.create_evaluation( moduleimpl_id=evaluation1.moduleimpl_id, @@ -227,7 +222,7 @@ def test_module_moy(test_client): description="evaluation 2", coefficient=coef_e2, )["evaluation_id"] - evaluation2 = models.Evaluation.query.get(evaluation2_id) + evaluation2 = db.session.get(Evaluation, evaluation2_id) # Coefficients de l'eval 1 evaluation1.coefficient = coef_e1 # Poids des évaluations: @@ -237,10 +232,11 @@ def test_module_moy(test_client): evaluation2.set_ue_poids_dict({ue1.id: e2p1, ue2.id: e2p2, ue3.id: e2p3}) # Vérifications moduleimpl_id = evaluation1.moduleimpl_id - nb_evals = models.Evaluation.query.filter_by(moduleimpl_id=moduleimpl_id).count() + nb_evals = Evaluation.query.filter_by(moduleimpl_id=moduleimpl_id).count() assert nb_evals == 2 nb_ues = 3 - modimpl = ModuleImpl.query.get(moduleimpl_id) + modimpl = db.session.get(ModuleImpl, moduleimpl_id) + # --- Change les notes et recalcule les moyennes du module # (rappel: on a deux évaluations: evaluation1, evaluation2, et un seul étudiant) def change_notes(n1, n2): diff --git a/tests/unit/test_but_ues.py b/tests/unit/test_but_ues.py index ae850b53a..ee66bcde7 100644 --- a/tests/unit/test_but_ues.py +++ b/tests/unit/test_but_ues.py @@ -30,8 +30,8 @@ def test_ue_moy(test_client): ) = setup.build_modules_with_evaluations(ue_coefs=ue_coefs, nb_mods=nb_mods) assert len(evaluation_ids) == nb_mods formsemestre = FormSemestre.get_formsemestre(formsemestre_id) - evaluation1 = Evaluation.query.get(evaluation_ids[0]) - evaluation2 = Evaluation.query.get(evaluation_ids[1]) + evaluation1 = db.session.get(Evaluation, evaluation_ids[0]) + evaluation2 = db.session.get(Evaluation, evaluation_ids[1]) etud = G.create_etud(nom="test") G.inscrit_etudiant(formsemestre_id, etud) etudid = etud["etudid"] diff --git a/tests/unit/test_formations.py b/tests/unit/test_formations.py index d521a009f..f4ed75364 100644 --- a/tests/unit/test_formations.py +++ b/tests/unit/test_formations.py @@ -47,6 +47,7 @@ import os import pytest +from app import db from app.models import Formation, ModuleImpl from app.scodoc import sco_edit_formation, sco_formsemestre from app.scodoc import sco_edit_matiere @@ -72,7 +73,7 @@ def test_formations(test_client): acronyme="F1", titre="Formation 1", titre_officiel="Titre officiel 1" ) # --- Objet Formation - formation = Formation.query.get(formation_id) + formation = db.session.get(Formation, formation_id) assert isinstance(formation, Formation) assert formation.acronyme == "F1" assert formation.titre == "Formation 1" @@ -128,7 +129,7 @@ def test_formations(test_client): ) formation_id2 = G.create_formation(acronyme="", titre="Formation test") - assert Formation.query.get(formation_id2) + assert db.session.get(Formation, formation_id2) ue3 = G.create_ue(formation_id=formation_id2, acronyme="TST3", titre="ue test3") matiere_id4 = G.create_matiere(ue_id=ue3, titre="matière test3") module_id3 = G.create_module( @@ -291,7 +292,7 @@ def test_formations(test_client): li_module = sco_edit_module.module_list() assert len(li_module) == 4 # Suppression impossible car utilisé dans le semestre formsemestre_idt: - module3 = ModuleImpl.query.get(mi3).module + module3 = db.session.get(ModuleImpl, mi3).module with pytest.raises(sco_exceptions.ScoNonEmptyFormationObject): sco_edit_module.module_delete(module_id=module3.id) @@ -328,7 +329,7 @@ def test_formations(test_client): # --- Suppression d'une formation sco_edit_formation.do_formation_delete(formation_id=formation_id2) - formation = Formation.query.get(formation_id2) + formation = db.session.get(Formation, formation_id2) assert formation is None diff --git a/tests/unit/test_notes_rattrapage.py b/tests/unit/test_notes_rattrapage.py index b4653009e..853824929 100644 --- a/tests/unit/test_notes_rattrapage.py +++ b/tests/unit/test_notes_rattrapage.py @@ -2,7 +2,7 @@ """ import app - +from app import db from app.comp import res_sem from app.comp.res_but import ResultatsSemestreBUT from app.models import FormSemestre, ModuleImpl @@ -75,10 +75,10 @@ def test_notes_rattrapage(test_client): _, _, _ = G.create_note(evaluation_id=e_rat["id"], etudid=etud["etudid"], note=11.0) # --- Vérifications internes structures ScoDoc - formsemestre = FormSemestre.query.get(formsemestre_id) + formsemestre = db.session.get(FormSemestre, formsemestre_id) res: ResultatsSemestreBUT = res_sem.load_formsemestre_results(formsemestre) mod_res = res.modimpls_results[moduleimpl_id] - moduleimpl = ModuleImpl.query.get(moduleimpl_id) + moduleimpl = db.session.get(ModuleImpl, moduleimpl_id) # retrouve l'éval. de rattrapage: eval_rat = mod_res.get_evaluation_rattrapage(moduleimpl) assert eval_rat.id == e_rat["id"] diff --git a/tests/unit/test_refcomp.py b/tests/unit/test_refcomp.py index 72e61f2e3..993cb546e 100644 --- a/tests/unit/test_refcomp.py +++ b/tests/unit/test_refcomp.py @@ -42,8 +42,9 @@ def test_but_refcomp(test_client): assert ref_comp.competences.count() == 13 assert ref_comp.competences[0].situations.count() == 3 assert ref_comp.competences[0].situations[0].libelle.startswith("Conception ") + competences = ref_comp.competences.all() assert ( - ref_comp.competences[-1].situations[-1].libelle + competences[-1].situations.all()[-1].libelle == "Administration des services multimédia" ) # test cascades on delete @@ -58,13 +59,13 @@ def test_but_assoc_ue_parcours(test_client): dept_id = models.Departement.query.first().id G, formation_id, (ue1_id, ue2_id, ue3_id), module_ids = setup.build_formation_test() ref_comp: ApcReferentielCompetences = orebut_import_refcomp(REF_RT_XML, dept_id) - ue = UniteEns.query.get(ue1_id) + ue = db.session.get(UniteEns, ue1_id) assert ue.niveau_competence is None niveau = ApcNiveau.query.first() ue.niveau_competence = niveau db.session.add(ue) db.session.commit() - ue = UniteEns.query.get(ue1_id) + ue = db.session.get(UniteEns, ue1_id) assert ue.niveau_competence == niveau assert len(niveau.ues) == 1 assert niveau.ues[0] == ue @@ -74,13 +75,13 @@ def test_but_assoc_refcomp(test_client): """Association formation / référentiel de compétences""" dept_id = models.Departement.query.first().id G, formation_id, (ue1_id, ue2_id, ue3_id), module_ids = setup.build_formation_test() - formation: Formation = Formation.query.get(formation_id) + formation: Formation = db.session.get(Formation, formation_id) assert formation is not None ref_comp: ApcReferentielCompetences = orebut_import_refcomp(REF_RT_XML, dept_id) formation.referentiel_competence_id = ref_comp.id db.session.add(formation) db.session.commit() - ue = UniteEns.query.get(ue1_id) + ue = db.session.get(UniteEns, ue1_id) niveau = ( ApcNiveau.query.filter_by(annee="BUT1") .join(ApcCompetence) diff --git a/tests/unit/yaml_setup.py b/tests/unit/yaml_setup.py index 277728e47..bc51849db 100644 --- a/tests/unit/yaml_setup.py +++ b/tests/unit/yaml_setup.py @@ -87,7 +87,7 @@ def setup_formation(formation_infos: dict) -> Formation: # --- Création de la formation formation_id, _, _ = sco_formations.formation_import_xml(doc) - formation: Formation = Formation.query.get(formation_id) + formation: Formation = db.session.get(Formation, formation_id) assert formation return formation @@ -116,11 +116,11 @@ def create_formsemestre( elt_sem_apo=elt_sem_apo, elt_annee_apo=elt_annee_apo, ) + db.session.add(formsemestre) + db.session.flush() # set responsable (list) a_user = User.query.first() formsemestre.responsables = [a_user] - db.session.add(formsemestre) - db.session.flush() formsemestre.add_etape(etape_apo) # Ajoute tous les modules du semestre sans parcours OU avec l'un des parcours indiqués sem_parcours_ids = {p.id for p in parcours} diff --git a/tools/fakedatabase/create_test_api_database.py b/tools/fakedatabase/create_test_api_database.py index 401f33099..142f732f8 100644 --- a/tools/fakedatabase/create_test_api_database.py +++ b/tools/fakedatabase/create_test_api_database.py @@ -66,7 +66,7 @@ def import_formation(dept_id: int) -> Formation: doc = f.read() # --- Création de la formation (import programme) f = sco_formations.formation_import_xml(doc) - formation = Formation.query.get(f[0]) + formation = db.session.get(Formation, f[0]) # --- Association ref. comp. with open(REFCOMP_FILENAME, encoding="utf-8") as f: xml_data = f.read()