Compare commits

..

No commits in common. "6b8667522b20405b225d3c7be6f5f7709f60987f" and "af7b5b01fb65f8ff7dfd4173c095f71d040fffca" have entirely different histories.

38 changed files with 237 additions and 498 deletions

View File

@ -28,9 +28,6 @@ from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from jinja2 import select_autoescape
import numpy as np
import psycopg2
from psycopg2.extensions import AsIs as psycopg2_AsIs
import sqlalchemy as sa
import werkzeug.debug
from wtforms.fields import HiddenField
@ -71,19 +68,6 @@ cache = Cache(
)
# NumPy & Psycopg2 (necessary with Numpy 2.0)
# probablement à changer quand on passera à psycopg3.2
def adapt_numpy_scalar(numpy_scalar):
"""Adapt numeric types for psycopg2"""
return psycopg2_AsIs(numpy_scalar if not np.isnan(numpy_scalar) else "'NaN'")
psycopg2.extensions.register_adapter(np.float32, adapt_numpy_scalar)
psycopg2.extensions.register_adapter(np.float64, adapt_numpy_scalar)
psycopg2.extensions.register_adapter(np.int32, adapt_numpy_scalar)
psycopg2.extensions.register_adapter(np.int64, adapt_numpy_scalar)
def handle_sco_value_error(exc):
"page d'erreur avec message"
return render_template("sco_value_error.j2", exc=exc), 404

View File

@ -7,7 +7,7 @@ from flask_json import as_json
from flask import Blueprint
from flask import current_app, g, request
from flask_login import current_user
from app import db, log
from app import db
from app.decorators import permission_required
from app.scodoc import sco_utils as scu
from app.scodoc.sco_exceptions import AccessDenied, ScoException
@ -47,7 +47,6 @@ def api_permission_required(permission):
@api_bp.errorhandler(404)
def api_error_handler(e):
"erreurs API => json"
log(f"api_error_handler: {e}")
return scu.json_error(404, message=str(e))

View File

@ -41,10 +41,6 @@ from app.models import (
from app.models.formsemestre import GROUPS_AUTO_ASSIGNMENT_DATA_MAX
from app.scodoc.sco_bulletins import get_formsemestre_bulletin_etud_json
from app.scodoc import sco_edt_cal
from app.scodoc.sco_formsemestre_inscriptions import (
do_formsemestre_inscription_with_modules,
do_formsemestre_desinscription,
)
from app.scodoc import sco_groups
from app.scodoc.sco_permissions import Permission
from app.scodoc.sco_utils import ModuleType
@ -68,7 +64,10 @@ def formsemestre_get(formsemestre_id: int):
-------
/formsemestre/1
"""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id)
formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
return formsemestre.to_dict_api()
@ -401,7 +400,12 @@ def bulletins(formsemestre_id: int, version: str = "long"):
-------
/formsemestre/1/bulletins
"""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id)
formsemestre: FormSemestre = query.first()
if formsemestre is None:
return json_error(404, "formsemestre non trouve")
app.set_sco_dept(formsemestre.departement.acronym)
data = []
@ -428,7 +432,10 @@ def formsemestre_programme(formsemestre_id: int):
-------
/formsemestre/1/programme
"""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id)
formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
ues = formsemestre.get_ues()
m_list = {
ModuleType.RESSOURCE: [],
@ -501,7 +508,10 @@ def formsemestre_etudiants(
/formsemestre/1/etudiants/query;
"""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id)
formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
if with_query:
etat = request.args.get("etat")
if etat is not None:
@ -533,63 +543,6 @@ def formsemestre_etudiants(
return sorted(etuds, key=itemgetter("sort_key"))
@bp.post("/formsemestre/<int:formsemestre_id>/etudid/<int:etudid>/inscrit")
@api_web_bp.post("/formsemestre/<int:formsemestre_id>/etudid/<int:etudid>/inscrit")
@login_required
@scodoc
@permission_required(Permission.EtudInscrit)
@as_json
def formsemestre_etud_inscrit(formsemestre_id: int, etudid: int):
"""Inscrit l'étudiant à ce formsemestre et TOUS ses modules STANDARDS
(donc sauf les modules bonus sport).
DATA
----
```json
{
"dept_id" : int, # le département
"etape" : string, # optionnel: l'étape Apogée d'inscription
"group_ids" : [int], # optionnel: liste des groupes où inscrire l'étudiant (doivent exister)
}
```
"""
data = request.get_json(force=True) if request.data else {}
dept_id = data.get("dept_id", g.scodoc_dept_id)
formsemestre = FormSemestre.get_formsemestre(formsemestre_id, dept_id=dept_id)
app.set_sco_dept(formsemestre.departement.acronym)
etud = Identite.get_etud(etudid)
group_ids = data.get("group_ids", [])
etape = data.get("etape", None)
do_formsemestre_inscription_with_modules(
formsemestre.id, etud.id, dept_id=dept_id, etape=etape, group_ids=group_ids
)
app.log(f"formsemestre_etud_inscrit: {etud} inscrit à {formsemestre}")
return (
FormSemestreInscription.query.filter_by(
formsemestre_id=formsemestre.id, etudid=etud.id
)
.first()
.to_dict()
)
@bp.post("/formsemestre/<int:formsemestre_id>/etudid/<int:etudid>/desinscrit")
@api_web_bp.post("/formsemestre/<int:formsemestre_id>/etudid/<int:etudid>/desinscrit")
@login_required
@scodoc
@permission_required(Permission.EtudInscrit)
@as_json
def formsemestre_etud_desinscrit(formsemestre_id: int, etudid: int):
"""Désinscrit l'étudiant de ce formsemestre et TOUS ses modules"""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
app.set_sco_dept(formsemestre.departement.acronym)
etud = Identite.get_etud(etudid)
do_formsemestre_desinscription(etud.id, formsemestre.id)
app.log(f"formsemestre_etud_desinscrit: {etud} désinscrit de {formsemestre}")
return {"status": "ok"}
@bp.route("/formsemestre/<int:formsemestre_id>/etat_evals")
@api_web_bp.route("/formsemestre/<int:formsemestre_id>/etat_evals")
@login_required
@ -696,7 +649,10 @@ def formsemestre_resultat(formsemestre_id: int):
return json_error(API_CLIENT_ERROR, "invalid format specification")
convert_values = format_spec != "raw"
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id)
formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
app.set_sco_dept(formsemestre.departement.acronym)
res: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
# Ajoute le groupe de chaque partition,
@ -734,7 +690,10 @@ def formsemestre_resultat(formsemestre_id: int):
@as_json
def groups_get_auto_assignment(formsemestre_id: int):
"""Rend les données stockées par `groups_save_auto_assignment`."""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id)
formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
response = make_response(formsemestre.groups_auto_assignment_data or b"")
response.headers["Content-Type"] = scu.JSON_MIMETYPE
return response
@ -754,7 +713,11 @@ def groups_save_auto_assignment(formsemestre_id: int):
"""Enregistre les données, associées à ce formsemestre.
Usage réservé aux fonctions de gestion des groupes, ne pas utiliser ailleurs.
"""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id)
formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
if not formsemestre.can_change_groups():
return json_error(403, "non autorisé (can_change_groups)")
@ -763,7 +726,6 @@ def groups_save_auto_assignment(formsemestre_id: int):
formsemestre.groups_auto_assignment_data = request.data
db.session.add(formsemestre)
db.session.commit()
return {"status": "ok"}
@bp.route("/formsemestre/<int:formsemestre_id>/edt")
@ -784,7 +746,10 @@ def formsemestre_edt(formsemestre_id: int):
group_ids : string (optionnel) filtre sur les groupes ScoDoc.
show_modules_titles: show_modules_titles affiche le titre complet du module (défaut), sinon juste le code.
"""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id)
formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
group_ids = request.args.getlist("group_ids", int)
show_modules_titles = scu.to_bool(request.args.get("show_modules_titles", False))
return sco_edt_cal.formsemestre_edt_dict(

View File

@ -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 = db.session.get(Departement, dept_id)
dept: Departement = Departement.query.get(dept_id)
if dept is None:
return json_error(404, "Assiduité non existante")
etuds: list[int] = [etud.id for etud in dept.etudiants]
@ -765,7 +765,7 @@ def justif_export(justif_id: int | None = None, filename: str | None = None):
current_user.has_permission(Permission.AbsJustifView)
or justificatif_unique.user_id == current_user.id
):
return json_error(403, "non autorisé à voir ce fichier")
return json_error(401, "non autorisé à voir ce fichier")
# On récupère l'archive concernée
archive_name: str = justificatif_unique.fichier

View File

@ -16,15 +16,12 @@ from flask_json import as_json
from flask_login import login_required
import app
from app import db
from app.api import api_bp as bp, api_web_bp
from app.api import api_permission_required as permission_required
from app.decorators import scodoc
from app.models import Identite, ModuleImpl, ModuleImplInscription
from app.scodoc import sco_cache, sco_liste_notes
from app.scodoc.sco_moduleimpl import do_moduleimpl_inscrit_etuds
from app.models import ModuleImpl
from app.scodoc import sco_liste_notes
from app.scodoc.sco_permissions import Permission
from app.scodoc.sco_utils import json_error
@bp.route("/moduleimpl/<int:moduleimpl_id>")
@ -66,60 +63,6 @@ def moduleimpl_inscriptions(moduleimpl_id: int):
return [i.to_dict() for i in modimpl.inscriptions]
@bp.post("/moduleimpl/<int:moduleimpl_id>/etudid/<int:etudid>/inscrit")
@api_web_bp.post("/moduleimpl/<int:moduleimpl_id>/etudid/<int:etudid>/inscrit")
@login_required
@scodoc
@permission_required(Permission.ScoView)
@as_json
def moduleimpl_etud_inscrit(moduleimpl_id: int, etudid: int):
"""Inscrit l'étudiant à ce moduleimpl.
SAMPLES
-------
/moduleimpl/1/etudid/2/inscrit
"""
modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
if not modimpl.can_change_inscriptions():
return json_error(403, "opération non autorisée")
etud = Identite.get_etud(etudid)
do_moduleimpl_inscrit_etuds(modimpl.id, modimpl.formsemestre_id, [etud.id])
app.log(f"moduleimpl_etud_inscrit: {etud} inscrit à {modimpl}")
return (
ModuleImplInscription.query.filter_by(moduleimpl_id=modimpl.id, etudid=etud.id)
.first()
.to_dict()
)
@bp.post("/moduleimpl/<int:moduleimpl_id>/etudid/<int:etudid>/desinscrit")
@api_web_bp.post("/moduleimpl/<int:moduleimpl_id>/etudid/<int:etudid>/desinscrit")
@login_required
@scodoc
@permission_required(Permission.ScoView)
@as_json
def moduleimpl_etud_desinscrit(moduleimpl_id: int, etudid: int):
"""Désinscrit l'étudiant de ce moduleimpl.
SAMPLES
-------
/moduleimpl/1/etudid/2/desinscrit
"""
modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
if not modimpl.can_change_inscriptions():
return json_error(403, "opération non autorisée")
etud = Identite.get_etud(etudid)
inscription = ModuleImplInscription.query.filter_by(
etudid=etud.id, moduleimpl_id=modimpl.id
).first()
if inscription:
db.session.delete(inscription)
db.session.commit()
sco_cache.invalidate_formsemestre(formsemestre_id=modimpl.formsemestre_id)
app.log(f"moduleimpl_etud_desinscrit: {etud} inscrit à {modimpl}")
return {"status": "ok"}
@bp.route("/moduleimpl/<int:moduleimpl_id>/notes")
@api_web_bp.route("/moduleimpl/<int:moduleimpl_id>/notes")
@login_required

View File

@ -169,7 +169,7 @@ def group_set_etudiant(group_id: int, etudid: int):
if not group.partition.formsemestre.etat:
return json_error(403, "formsemestre verrouillé")
if not group.partition.formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
if etud.id not in {e.id for e in group.partition.formsemestre.etuds}:
return json_error(404, "etud non inscrit au formsemestre du groupe")
@ -202,7 +202,7 @@ def group_remove_etud(group_id: int, etudid: int):
if not group.partition.formsemestre.etat:
return json_error(403, "formsemestre verrouillé")
if not group.partition.formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
group.remove_etud(etud)
@ -232,7 +232,7 @@ def partition_remove_etud(partition_id: int, etudid: int):
if not partition.formsemestre.etat:
return json_error(403, "formsemestre verrouillé")
if not partition.formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
db.session.execute(
sa.text(
"""DELETE FROM group_membership
@ -289,7 +289,7 @@ def group_create(partition_id: int): # partition-group-create
if not partition.groups_editable:
return json_error(403, "partition non editable")
if not partition.formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
args = request.get_json(force=True) # may raise 400 Bad Request
group_name = args.get("group_name")
@ -337,7 +337,7 @@ def group_delete(group_id: int):
if not group.partition.groups_editable:
return json_error(403, "partition non editable")
if not group.partition.formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
formsemestre_id = group.partition.formsemestre_id
log(f"deleting {group}")
db.session.delete(group)
@ -378,7 +378,7 @@ def group_edit(group_id: int):
if not group.partition.groups_editable:
return json_error(403, "partition non editable")
if not group.partition.formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
args = request.get_json(force=True) # may raise 400 Bad Request
if "group_name" in args:
@ -423,7 +423,7 @@ def group_set_edt_id(group_id: int, edt_id: str):
)
group: GroupDescr = query.first_or_404()
if not group.partition.formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
log(f"group_set_edt_id( {group_id}, '{edt_id}' )")
group.edt_id = edt_id
db.session.add(group)
@ -461,7 +461,7 @@ def partition_create(formsemestre_id: int):
if not formsemestre.etat:
return json_error(403, "formsemestre verrouillé")
if not formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
data = request.get_json(force=True) # may raise 400 Bad Request
partition_name = data.get("partition_name")
if partition_name is None:
@ -523,7 +523,7 @@ def formsemestre_set_partitions_order(formsemestre_id: int):
if not formsemestre.etat:
return json_error(403, "formsemestre verrouillé")
if not formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
partition_ids = request.get_json(force=True) # may raise 400 Bad Request
if not isinstance(partition_ids, list) and not all(
isinstance(x, int) for x in partition_ids
@ -569,7 +569,7 @@ def partition_order_groups(partition_id: int):
if not partition.formsemestre.etat:
return json_error(403, "formsemestre verrouillé")
if not partition.formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
group_ids = request.get_json(force=True) # may raise 400 Bad Request
if not isinstance(group_ids, list) and not all(
isinstance(x, int) for x in group_ids
@ -623,7 +623,7 @@ def partition_edit(partition_id: int):
if not partition.formsemestre.etat:
return json_error(403, "formsemestre verrouillé")
if not partition.formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
data = request.get_json(force=True) # may raise 400 Bad Request
modified = False
partition_name = data.get("partition_name")
@ -689,7 +689,7 @@ def partition_delete(partition_id: int):
if not partition.formsemestre.etat:
return json_error(403, "formsemestre verrouillé")
if not partition.formsemestre.can_change_groups():
return json_error(403, "opération non autorisée")
return json_error(401, "opération non autorisée")
if not partition.partition_name:
return json_error(
API_CLIENT_ERROR, "ne peut pas supprimer la partition par défaut"

View File

@ -445,10 +445,9 @@ class User(UserMixin, ScoDocModel):
def set_roles(self, roles, dept):
"set roles in the given dept"
self.user_roles = []
for r in roles:
if isinstance(r, Role):
self.add_role(r, dept)
self.user_roles = [
UserRole(user=self, role=r, dept=dept) for r in roles if isinstance(r, Role)
]
def get_roles(self):
"iterator on my roles"

View File

@ -44,9 +44,7 @@ def formation_change_referentiel(
ue.niveau_competence_id = niveaux_map[ue.niveau_competence_id]
db.session.add(ue)
if ue.parcours:
new_list = [
db.session.get(ApcParcours, parcours_map[p.id]) for p in ue.parcours
]
new_list = [ApcParcours.query.get(parcours_map[p.id]) for p in ue.parcours]
ue.parcours.clear()
ue.parcours.extend(new_list)
db.session.add(ue)
@ -54,7 +52,7 @@ def formation_change_referentiel(
for module in formation.modules:
if module.parcours:
new_list = [
db.session.get(ApcParcours, parcours_map[p.id]) for p in module.parcours
ApcParcours.query.get(parcours_map[p.id]) for p in module.parcours
]
module.parcours.clear()
module.parcours.extend(new_list)
@ -78,8 +76,7 @@ def formation_change_referentiel(
# FormSemestre / parcours_formsemestre
for formsemestre in formation.formsemestres:
new_list = [
db.session.get(ApcParcours, parcours_map[p.id])
for p in formsemestre.parcours
ApcParcours.query.get(parcours_map[p.id]) for p in formsemestre.parcours
]
formsemestre.parcours.clear()
formsemestre.parcours.extend(new_list)

View File

@ -1557,8 +1557,8 @@ class DecisionsProposeesUE(DecisionsProposees):
res: ResultatsSemestreBUT = (
self.rcue.res_pair if paire else self.rcue.res_impair
)
self.moy_ue = np.nan
self.moy_ue_with_cap = np.nan
self.moy_ue = np.NaN
self.moy_ue_with_cap = np.NaN
self.ue_status = {}
if self.ue.type != sco_codes.UE_STANDARD:

View File

@ -541,16 +541,17 @@ def load_evaluations_poids(moduleimpl_id: int) -> tuple[pd.DataFrame, list]:
ue_ids = [ue.id for ue in ues]
evaluation_ids = [evaluation.id for evaluation in modimpl.evaluations]
evals_poids = pd.DataFrame(columns=ue_ids, index=evaluation_ids, dtype=float)
if modimpl.module.module_type in (ModuleType.RESSOURCE, ModuleType.SAE):
if (
modimpl.module.module_type == ModuleType.RESSOURCE
or modimpl.module.module_type == ModuleType.SAE
):
for ue_poids in EvaluationUEPoids.query.join(
EvaluationUEPoids.evaluation
).filter_by(moduleimpl_id=moduleimpl_id):
if (
ue_poids.evaluation_id in evals_poids.index
and ue_poids.ue_id in evals_poids.columns
):
evals_poids.at[ue_poids.evaluation_id, ue_poids.ue_id] = ue_poids.poids
# ignore poids vers des UEs qui n'existent plus ou sont dans un autre semestre...
try:
evals_poids[ue_poids.ue_id][ue_poids.evaluation_id] = ue_poids.poids
except KeyError:
pass # poids vers des UE qui n'existent plus ou sont dans un autre semestre...
# Initialise poids non enregistrés:
default_poids = (
@ -563,7 +564,7 @@ def load_evaluations_poids(moduleimpl_id: int) -> tuple[pd.DataFrame, list]:
if np.isnan(evals_poids.values.flat).any():
ue_coefs = modimpl.module.get_ue_coef_dict()
for ue in ues:
evals_poids.loc[evals_poids[ue.id].isna(), ue.id] = (
evals_poids[ue.id][evals_poids[ue.id].isna()] = (
1 if ue_coefs.get(ue.id, default_poids) > 0 else 0
)

View File

@ -82,7 +82,7 @@ def compute_sem_moys_apc_using_ects(
moy_gen = (etud_moy_ue_df * ects).sum(axis=1) / ects.sum(axis=1)
except ZeroDivisionError:
# peut arriver si aucun module... on ignore
moy_gen = pd.Series(np.nan, index=etud_moy_ue_df.index)
moy_gen = pd.Series(np.NaN, index=etud_moy_ue_df.index)
except TypeError:
if None in ects:
formation = db.session.get(Formation, formation_id)
@ -93,7 +93,7 @@ def compute_sem_moys_apc_using_ects(
scodoc_dept=g.scodoc_dept, formation_id=formation_id)}">{formation.get_titre_version()}</a>)"""
)
)
moy_gen = pd.Series(np.nan, index=etud_moy_ue_df.index)
moy_gen = pd.Series(np.NaN, index=etud_moy_ue_df.index)
else:
raise
return moy_gen

View File

@ -92,7 +92,7 @@ def df_load_module_coefs(formation_id: int, semestre_idx: int = None) -> pd.Data
for mod_coef in query:
if mod_coef.module_id in module_coefs_df:
module_coefs_df.at[mod_coef.ue_id, mod_coef.module_id] = mod_coef.coef
module_coefs_df[mod_coef.module_id][mod_coef.ue_id] = mod_coef.coef
# silently ignore coefs associated to other modules (ie when module_type is changed)
# Initialisation des poids non fixés:
@ -138,16 +138,14 @@ def df_load_modimpl_coefs(
)
for mod_coef in mod_coefs:
if (
mod_coef.ue_id in modimpl_coefs_df.index
and mod2impl[mod_coef.module_id] in modimpl_coefs_df.columns
):
modimpl_coefs_df.at[mod_coef.ue_id, mod2impl[mod_coef.module_id]] = (
mod_coef.coef
)
try:
modimpl_coefs_df[mod2impl[mod_coef.module_id]][
mod_coef.ue_id
] = mod_coef.coef
except IndexError:
# il peut y avoir en base des coefs sur des modules ou UE
# qui ont depuis été retirés de la formation : on ignore ces coefs
# qui ont depuis été retirés de la formation
pass
# Initialisation des poids non fixés:
# 0 pour modules normaux, 1. pour bonus (car par défaut, on veut qu'un bonus agisse
# sur toutes les UE)
@ -180,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([str(x.shape) for x in modimpls_notes_arr])}"""
", ".join([x.shape for x in modimpls_notes_arr])}"""
)
return modimpls_notes.swapaxes(0, 1)
@ -301,11 +299,7 @@ def compute_ue_moys_apc(
)
# Les "dispenses" sont très peu nombreuses et traitées en python:
for dispense_ue in dispense_ues:
if (
dispense_ue[0] in etud_moy_ue_df.columns
and dispense_ue[1] in etud_moy_ue_df.index
):
etud_moy_ue_df.at[dispense_ue[1], dispense_ue[0]] = 0.0
etud_moy_ue_df[dispense_ue[1]][dispense_ue[0]] = 0.0
return etud_moy_ue_df

View File

@ -111,12 +111,6 @@ class ScoDocModel(db.Model):
db.session.add(self)
return modified
def to_dict(self) -> dict:
"dict"
d = dict(self.__dict__)
d.pop("_sa_instance_state", None)
return d
def edit_from_form(self, form) -> bool:
"""Generic edit method for updating model instance.
True if modification.

View File

@ -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 = db.session.get(ModuleImpl, moduleimpl_id)
moduleimpl: ModuleImpl = ModuleImpl.query.get(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 = db.session.get(ModuleImpl, self.moduleimpl_id)
mod: Module = db.session.get(Module, modimpl.module_id)
modimpl: ModuleImpl = ModuleImpl.query.get(self.moduleimpl_id)
mod: Module = Module.query.get(modimpl.module_id)
if traduire:
return f"{mod.code} {mod.titre}"
return mod

View File

@ -1318,7 +1318,7 @@ notes_formsemestre_responsables = db.Table(
)
class FormSemestreEtape(models.ScoDocModel):
class FormSemestreEtape(db.Model):
"""Étape Apogée associée au semestre"""
__tablename__ = "notes_formsemestre_etapes"
@ -1349,7 +1349,7 @@ class FormSemestreEtape(models.ScoDocModel):
return ApoEtapeVDI(self.etape_apo)
class FormationModalite(models.ScoDocModel):
class FormationModalite(db.Model):
"""Modalités de formation, utilisées pour la présentation
(grouper les semestres, générer des codes, etc.)
"""
@ -1400,7 +1400,7 @@ class FormationModalite(models.ScoDocModel):
raise
class FormSemestreUECoef(models.ScoDocModel):
class FormSemestreUECoef(db.Model):
"""Coef des UE capitalisees arrivant dans ce semestre"""
__tablename__ = "notes_formsemestre_uecoef"
@ -1441,7 +1441,7 @@ class FormSemestreUEComputationExpr(db.Model):
computation_expr = db.Column(db.Text())
class FormSemestreCustomMenu(models.ScoDocModel):
class FormSemestreCustomMenu(db.Model):
"""Menu custom associe au semestre"""
__tablename__ = "notes_formsemestre_custommenu"
@ -1457,7 +1457,7 @@ class FormSemestreCustomMenu(models.ScoDocModel):
idx = db.Column(db.Integer, default=0, server_default="0") # rang dans le menu
class FormSemestreInscription(models.ScoDocModel):
class FormSemestreInscription(db.Model):
"""Inscription à un semestre de formation"""
__tablename__ = "notes_formsemestre_inscription"
@ -1503,7 +1503,7 @@ class FormSemestreInscription(models.ScoDocModel):
} {('etape="'+self.etape+'"') if self.etape else ''}>"""
class NotesSemSet(models.ScoDocModel):
class NotesSemSet(db.Model):
"""semsets: ensemble de formsemestres pour exports Apogée"""
__tablename__ = "notes_semset"

View File

@ -325,7 +325,7 @@ notes_modules_enseignants = db.Table(
# XXX il manque probablement une relation pour gérer cela
class ModuleImplInscription(ScoDocModel):
class ModuleImplInscription(db.Model):
"""Inscription à un module (etudiants,moduleimpl)"""
__tablename__ = "notes_moduleimpl_inscription"

View File

@ -56,7 +56,7 @@ class BulAppreciations(models.ScoDocModel):
return safehtml.html_to_safe_html(self.comment or "")
class NotesNotes(models.ScoDocModel):
class NotesNotes(db.Model):
"""Une note"""
__tablename__ = "notes_notes"
@ -75,6 +75,12 @@ class NotesNotes(models.ScoDocModel):
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
uid = db.Column(db.Integer, db.ForeignKey("user.id"))
def to_dict(self) -> dict:
"dict"
d = dict(self.__dict__)
d.pop("_sa_instance_state", None)
return d
def __repr__(self):
"pour debug"
from app.models.evaluations import Evaluation

View File

@ -333,7 +333,7 @@ class SxTag(pe_tabletags.TableTag):
etud_moy = np.max(set_cube_no_nan, axis=2)
# Fix les max non calculé -1 -> NaN
etud_moy[etud_moy < 0] = np.nan
etud_moy[etud_moy < 0] = np.NaN
# Le dataFrame
etud_moy_tag_df = pd.DataFrame(

View File

@ -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 = db.session.get(Identite, etudid)
etud = Identite.query.get(etudid)
raise ScoValueError(
f"""désinscription impossible: l'étudiant {etud.nomprenom} a
une décision de jury (la supprimer avant si nécessaire)"""
@ -287,12 +287,6 @@ def do_formsemestre_inscription_with_modules(
group_ids = group_ids or []
if isinstance(group_ids, int):
group_ids = [group_ids]
# Check that all groups exist before creating the inscription
groups = [
GroupDescr.query.get_or_404(group_id)
for group_id in group_ids
if group_id != ""
]
formsemestre = FormSemestre.get_formsemestre(formsemestre_id, dept_id=dept_id)
# inscription au semestre
args = {"formsemestre_id": formsemestre_id, "etudid": etudid}
@ -309,13 +303,14 @@ def do_formsemestre_inscription_with_modules(
# 1- inscrit au groupe 'tous'
group_id = sco_groups.get_default_group(formsemestre_id)
sco_groups.set_group(etudid, group_id)
gdone = {group_id} # empeche doublons
gdone = {group_id: 1} # empeche doublons
# 2- inscrit aux groupes
for group in groups:
if group.id not in gdone:
sco_groups.set_group(etudid, group.id)
gdone.add(group.id)
for group_id in group_ids:
if group_id and group_id not in gdone:
_ = GroupDescr.query.get_or_404(group_id)
sco_groups.set_group(etudid, group_id)
gdone[group_id] = 1
# Inscription à tous les modules de ce semestre
for modimpl in formsemestre.modimpls:

View File

@ -376,7 +376,7 @@ def formsemestre_inscr_passage(
if a_desinscrire:
H.append("<h3>Étudiants à désinscrire</h3><ol>")
a_desinscrire_ident = sorted(
(db.session.get(Identite, eid) for eid in a_desinscrire),
(Identite.query.get(eid) for eid in a_desinscrire),
key=lambda x: x.sort_key,
)
for etud in a_desinscrire_ident:

View File

@ -136,8 +136,7 @@ def moduleimpl_inscriptions_edit(
}
} else {
for (var i =nb_inputs_to_skip; i < elems.length; i++) {
let tds = elems[i].parentNode.parentNode.getElementsByTagName("td");
var cells = tds[partitionIdx].childNodes;
var cells = elems[i].parentNode.parentNode.getElementsByTagName("td")[partitionIdx].childNodes;
if (cells.length && cells[0].nodeValue == groupName) {
elems[i].checked=check;
}
@ -179,19 +178,19 @@ def moduleimpl_inscriptions_edit(
else:
checked = ""
H.append(
f"""<tr><td class="etud">
<input type="checkbox" name="etudids:list" value="{etud['etudid']}" {checked}>
<a class="discretelink etudinfo" href="{
f"""<tr><td class="etud"><input type="checkbox" name="etudids:list" value="{etud['etudid']}" {checked}>"""
)
H.append(
f"""<a class="discretelink etudinfo" href="{
url_for(
"scolar.fiche_etud",
scodoc_dept=g.scodoc_dept,
etudid=etud["etudid"],
)
}" id="{etud['etudid']}">{etud['nomprenom']}</a>
</input>
</td>
"""
}" id="{etud['etudid']}">{etud['nomprenom']}</a>"""
)
H.append("""</input></td>""")
groups = sco_groups.get_etud_groups(etud["etudid"], formsemestre.id)
for partition in partitions:
if partition["partition_name"]:

View File

@ -483,8 +483,6 @@ def moduleimpl_status(moduleimpl_id=None, partition_id=None):
}" title="Charger toutles les notes via tableur">Importer les notes</a>
"""
)
else:
bot_table_links = top_table_links
if nb_evaluations > 0:
H.append(
'<div class="moduleimpl_evaluations_top_links">'

View File

@ -292,7 +292,7 @@ def _descr_decisions_ues(nt, etudid, decisions_ue, decision_sem) -> list[dict]:
)
)
):
ue = db.session.get(UniteEns, ue_id)
ue = UniteEns.query.get(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())

View File

@ -408,7 +408,7 @@ def _check_inscription(
elif etudid not in etudids_inscrits_mod:
msg_err = "non inscrit au module"
if msg_err:
etud = db.session.get(Identite, etudid) if isinstance(etudid, int) else None
etud = Identite.query.get(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 = db.session.get(Identite, etudid) if isinstance(etudid, int) else None
etud = Identite.query.get(etudid) if isinstance(etudid, int) else None
raise NoteProcessError(
f"etudiant {etud.nomprenom if etud else etudid}: valeur de note invalide ({value})"
)
@ -491,9 +491,7 @@ def notes_add(
# si change sur DEM/DEF ajoute message warning aux messages
if etudid not in etudids_actifs: # DEM ou DEF
etud = (
db.session.get(Identite, etudid)
if isinstance(etudid, int)
else None
Identite.query.get(etudid) if isinstance(etudid, int) else None
)
messages.append(
f"""étudiant {etud.nomprenom if etud else etudid
@ -803,7 +801,7 @@ def get_sorted_etuds_notes(
notes_db[etudid]["value"], fixed_precision_str=False
)
user = (
db.session.get(User, notes_db[etudid]["uid"])
User.query.get(notes_db[etudid]["uid"])
if notes_db[etudid]["uid"]
else None
)

View File

@ -144,7 +144,7 @@ def external_ue_create(
),
},
)
modimpl = db.session.get(ModuleImpl, moduleimpl_id)
modimpl = ModuleImpl.query.get(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 = db.session.get(ModuleImpl, modimpl_id)
modimpl = ModuleImpl.query.get(modimpl_id)
assert modimpl
return modimpl
else:

View File

@ -553,7 +553,7 @@ class RowAssiJusti(tb.Row):
)
if self.table.options.show_module:
if self.ligne["type"] == "assiduite":
assi: Assiduite = db.session.get(Assiduite, self.ligne["obj_id"])
assi: Assiduite = Assiduite.query.get(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,9 +607,7 @@ class RowAssiJusti(tb.Row):
def _utilisateur(self) -> None:
utilisateur: User = (
db.session.get(User, self.ligne["user_id"])
if self.ligne["user_id"] is not None
else None
User.query.get(self.ligne["user_id"]) if self.ligne["user_id"] else None
)
self.add_cell(

View File

@ -270,9 +270,6 @@ Pour uniformiser les résultats des exemples, ceux sont soumis à quelques post-
Voir exemples d'utilisation de l'API en Python, dans `tests/api/`.
!!! info
Cette page a été générée par la commande `flask gen-api-doc`, et les exemples de résultats
sont créés par `tools/test_api.sh --make-samples`.
!!! note "Voir aussi"

View File

@ -24,9 +24,6 @@
#
##############################################################################
"""Vues assiduité
"""
import datetime
import json
import re
@ -511,7 +508,7 @@ def _record_assiduite_etud(
case None:
moduleimpl = None
case _:
moduleimpl = db.session.get(ModuleImpl, moduleimpl_id)
moduleimpl = ModuleImpl.query.get(moduleimpl_id)
try:
assi_etat: scu.EtatAssiduite = scu.EtatAssiduite.get(form.assi_etat.data)
@ -1681,7 +1678,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 = db.session.get(Justificatif, justi_id)
justi: Justificatif = Justificatif.query.get(justi_id)
objet_prepare["justification"]["justificatifs"].append(
_preparer_objet("justificatif", justi, sans_gros_objet=True)
)
@ -1720,7 +1717,7 @@ def _preparer_objet(
objet_prepare["etud_nom"] = objet.etudiant.nomprenom
if objet.user_id is not None:
user: User = db.session.get(User, objet.user_id)
user: User = User.query.get(objet.user_id)
objet_prepare["saisie_par"] = user.get_nomprenom()
else:
objet_prepare["saisie_par"] = "Inconnu"
@ -2928,7 +2925,7 @@ def _module_selector_multiple(
)
choices = OrderedDict()
for formsemestre_id in modimpls_by_formsemestre:
formsemestre: FormSemestre = db.session.get(FormSemestre, formsemestre_id)
formsemestre: FormSemestre = FormSemestre.query.get(formsemestre_id)
if only_form is not None and formsemestre != only_form:
continue
# indique le nom du semestre dans le menu (optgroup)

View File

@ -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 = db.session.get(Departement, g.scodoc_dept_id)
departement = Departement.query.get(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 = db.session.get(Departement, g.scodoc_dept_id)
departement = Departement.query.get(g.scodoc_dept_id)
formsemestres = FormSemestre.get_dept_formsemestres_courants(departement)
else:
formsemestres = [FormSemestre.get_formsemestre(formsemestre_id)]
@ -2557,9 +2557,13 @@ 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 = f"""Erreur: code <tt>{status_code}</tt>
Merci de contacter <a href="mailto:{scu.SCO_DEV_MAIL}">{scu.SCO_DEV_MAIL}</a>
"""
r_msg = "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

View File

@ -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,8 +31,7 @@ def user_board(user_name: str):
modimpls_by_formsemestre,
) = FormSemestre.get_user_formsemestres_annee_by_dept(user)
depts = {
dept_id: db.session.get(Departement, dept_id)
for dept_id in formsemestres_by_dept
dept_id: Departement.query.get(dept_id) for dept_id in formsemestres_by_dept
}
dept_names = {
dept_id: sco_preferences.get_preference("DeptName", dept_id=dept_id)

View File

@ -1,116 +1,114 @@
alembic==1.13.2
astroid==3.2.4
alembic==1.13.0
astroid==3.0.1
async-timeout==4.0.3
attrs==23.2.0
Babel==2.15.0
black==24.4.2
blinker==1.8.2
attrs==23.1.0
Babel==2.13.1
black==23.11.0
blinker==1.7.0
Brotli==1.1.0
cachelib==0.9.0
certifi==2024.7.4
certifi==2023.11.17
cffi==1.16.0
chardet==5.2.0
charset-normalizer==3.3.2
click==8.1.7
cracklib==2.9.6
cryptography==43.0.0
cryptography==41.0.7
cssselect2==0.7.0
deepdiff==6.7.1
Deprecated==1.2.14
dill==0.3.8
dnspython==2.6.1
dominate==2.9.1
email_validator==2.2.0
dill==0.3.7
dnspython==2.4.2
dominate==2.9.0
email-validator==2.1.0.post1
ERAlchemy==1.2.10
et-xmlfile==1.1.0
exceptiongroup==1.2.2
execnet==2.1.1
flake8==7.1.0
Flask==3.0.3
exceptiongroup==1.2.0
execnet==2.0.2
flake8==6.1.0
Flask==3.0.0
flask-babel==4.0.0
Flask-Caching==2.3.0
Flask-Caching==2.1.0
Flask-HTTPAuth==4.8.0
Flask-JSON==0.4.0
Flask-Login==0.6.3
Flask-Mail==0.10.0
Flask-Migrate==4.0.7
Flask-Mail==0.9.1
Flask-Migrate==4.0.5
Flask-SQLAlchemy==3.1.1
Flask-WTF==1.2.1
fonttools==4.53.1
gprof2dot==2024.6.6
greenlet==3.0.3
gunicorn==22.0.0
fonttools==4.46.0
gprof2dot==2022.7.29
greenlet==3.0.1
gunicorn==21.2.0
html5lib==1.1
icalendar==5.0.13
idna==3.7
importlib_metadata==8.2.0
icalendar==5.0.11
idna==3.6
importlib-metadata==7.0.0
iniconfig==2.0.0
isort==5.13.2
itsdangerous==2.2.0
Jinja2==3.1.4
lazy-object-proxy==1.10.0
lxml==5.2.2
Mako==1.3.5
MarkupSafe==2.1.5
isort==5.12.0
itsdangerous==2.1.2
Jinja2==3.1.2
lazy-object-proxy==1.9.0
lxml==4.9.3
Mako==1.3.0
MarkupSafe==2.1.3
mccabe==0.7.0
mypy==1.11.0
mypy==1.7.1
mypy-extensions==1.0.0
numpy==2.0.1
openpyxl==3.1.5
ordered-set==4.1.0
packaging==24.1
pandas==2.2.2
pathspec==0.12.1
pillow==10.4.0
platformdirs==4.2.2
pluggy==1.5.0
numpy==1.26.2
openpyxl==3.1.2
packaging==23.2
pandas==2.1.3
pathspec==0.11.2
Pillow==10.1.0
platformdirs==4.1.0
pluggy==1.3.0
psycopg2==2.9.9
puremagic==1.26
puremagic==1.15
py==1.11.0
pycodestyle==2.12.0
pycparser==2.22
pydot==3.0.1
pydyf==0.11.0
pyflakes==3.2.0
pygraphviz==1.13
pycodestyle==2.11.1
pycparser==2.21
pydot==1.4.2
pydyf==0.8.0
pyflakes==3.1.0
pygraphviz==1.11
PyJWT==2.8.0
pylint==3.2.6
pylint==3.0.2
pylint-flask==0.6
pylint-flask-sqlalchemy==0.2.0
pylint-plugin-utils==0.8.2
pyOpenSSL==24.2.1
pyparsing==3.1.2
pyphen==0.16.0
pytest==8.3.2
pytest-xdist==3.6.1
python-dateutil==2.9.0.post0
python-docx==1.1.2
python-dotenv==1.0.1
pyOpenSSL==23.3.0
pyparsing==3.1.1
pyphen==0.14.0
pytest==7.4.3
pytest-xdist==3.5.0
python-dateutil==2.8.2
python-docx==1.1.0
python-dotenv==1.0.0
python-editor==1.0.4
pytz==2024.1
pytz==2023.3.post1
PyYAML==6.0.1
redis==5.0.8
reportlab==4.2.2
requests==2.32.3
rq==1.16.2
redis==5.0.1
reportlab==4.0.7
requests==2.31.0
rq==1.15.1
six==1.16.0
snakeviz==2.2.0
SQLAlchemy==2.0.31
tinycss2==1.3.0
SQLAlchemy==2.0.23
tinycss2==1.2.1
toml==0.10.2
tomli==2.0.1
tomlkit==0.13.0
tornado==6.4.1
tomlkit==0.12.3
tornado==6.4
tuna==0.5.11
typing_extensions==4.12.2
tzdata==2024.1
urllib3==2.2.2
typing_extensions==4.8.0
tzdata==2023.3
urllib3==2.1.0
visitor==0.1.3
weasyprint==62.3
weasyprint==60.1
webencodings==0.5.1
Werkzeug==3.0.3
Werkzeug==3.0.1
wrapt==1.16.0
WTForms==3.1.2
WTForms==3.1.1
xmltodict==0.13.0
zipp==3.19.2
zipp==3.17.0
zopfli==0.2.3

View File

@ -52,20 +52,16 @@ print(f"API_USER={API_USER}")
class APIError(Exception):
def __init__(self, message: str = "", payload=None, status_code=None):
def __init__(self, message: str = "", payload=None):
self.message = message
self.payload = payload or {}
self.status_code = status_code
def __str__(self):
return f"APIError: {self.message} payload={self.payload} status_code={self.status_code}"
def get_auth_headers(user, password) -> dict:
"Demande de jeton, dict à utiliser dans les en-têtes de requêtes http"
ans = requests.post(API_URL + "/tokens", auth=(user, password), timeout=5)
if ans.status_code != 200:
raise APIError(f"Echec demande jeton par {user}", status_code=ans.status_code)
raise APIError(f"Echec demande jeton par {user}")
token = ans.json()["token"]
return {"Authorization": f"Bearer {token}"}
@ -110,12 +106,11 @@ def GET(path: str, headers: dict = None, errmsg=None, dept=None, raw=False):
timeout=SCO_TEST_API_TIMEOUT,
)
if reply.status_code != 200:
print("url", SCODOC_URL)
print("url", url)
print("reply", reply.text)
raise APIError(
errmsg or f"""erreur get {url} !""",
reply.json(),
status_code=reply.status_code,
errmsg or f"""erreur status={reply.status_code} !""", reply.json()
)
if raw:
return reply
@ -131,24 +126,15 @@ def GET(path: str, headers: dict = None, errmsg=None, dept=None, raw=False):
"Content-Disposition": reply.headers.get("Content-Disposition", None),
}
return retval
raise APIError(
"Unknown returned content {r.headers.get('Content-Type', None} !\n",
status_code=reply.status_code,
)
raise APIError("Unknown returned content {r.headers.get('Content-Type', None} !\n")
def POST(
path: str,
data: dict = None,
headers: dict = None,
errmsg=None,
dept=None,
raw=False,
path: str, data: dict = {}, headers: dict = None, errmsg=None, dept=None, raw=False
):
"""Post
Decode réponse en json, sauf si raw.
"""
data = data or {}
if dept:
url = SCODOC_URL + f"/ScoDoc/{dept}/api" + path
else:
@ -161,15 +147,7 @@ def POST(
timeout=SCO_TEST_API_TIMEOUT,
)
if r.status_code != 200:
try:
payload = r.json()
except requests.exceptions.JSONDecodeError:
payload = r.text
raise APIError(
errmsg or f"erreur url={url} status={r.status_code} !",
payload=payload,
status_code=r.status_code,
)
raise APIError(errmsg or f"erreur status={r.status_code} !", r.json())
return r if raw else r.json() # decode la reponse JSON

View File

@ -1,51 +0,0 @@
"""Test API exceptions
"""
import json
import requests
import pytest
from tests.api.setup_test_api import (
API_URL,
CHECK_CERTIFICATE,
api_headers,
)
from app.scodoc import sco_utils as scu
def test_exceptions(api_headers):
"""
Vérifie que les exceptions de l'API sont toutes en JSON.
"""
# Une requete sur une url inexistante ne passe pas par les blueprints API
# et est donc en HTML
r = requests.get(
f"{API_URL}/mmm/non/existant/mmm",
headers=api_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 404
assert r.headers["Content-Type"] == "text/html; charset=utf-8"
# Une requete d'un objet non existant est en JSON
r = requests.get(
f"{API_URL}/formsemestre/999999",
headers=api_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 404
assert r.headers["Content-Type"] == "application/json"
assert r.json()
# Une requête API sans autorisation est en JSON
r = requests.post(
f"{API_URL}/formsemestre/1/etudid/1/inscrit",
headers=api_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 401
assert r.headers["Content-Type"] == "application/json"
assert r.json()

View File

@ -29,7 +29,6 @@ from tests.api.setup_test_api import (
CHECK_CERTIFICATE,
GET,
api_headers,
api_admin_headers,
)
from tests.api.tools_test_api import (
@ -586,46 +585,6 @@ def test_formsemestre_etudiants(api_headers):
assert r_error_defaillants.status_code == 404
def test_formsemestre_inscriptions(api_admin_headers):
"""
Route: /formsemestre/<int:formsemestre_id>/etudid/<int:etudid>/inscrit
"""
dept_id = 1
formsemestre_id = 1
etudid = 20 # pas déjà inscrit au semestre 1
# -- Inscription
r = requests.post(
f"{API_URL}/formsemestre/{formsemestre_id}/etudid/{etudid}/inscrit",
data=json.dumps({"dept_id": dept_id}),
headers=api_admin_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 200
inscription = r.json()
assert inscription["formsemestre_id"] == formsemestre_id
assert inscription["etudid"] == etudid
assert inscription["etat"] == "I"
# -- Désincription
r = requests.post(
f"{API_URL}/formsemestre/{formsemestre_id}/etudid/{etudid}/desinscrit",
headers=api_admin_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 200
### ERROR ###
etudid_inexistant = 165165165165165165165
r_error = requests.post(
f"{API_URL}/formsemestre/{formsemestre_id}/etudid/{etudid_inexistant}/inscrit",
headers=api_admin_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r_error.status_code == 404
def test_formsemestre_programme(api_headers):
"""
Route: /formsemestre/1/programme

View File

@ -185,7 +185,7 @@ def test_modif_users_depts(api_admin_headers):
headers=admin_h,
)
except APIError as exc:
if exc.status_code == 400:
if exc.args[1]["status"] == 400:
ok = True
assert ok
# Un "vrai" mot de passe:
@ -234,7 +234,7 @@ def test_modif_users_depts(api_admin_headers):
dept=dept3["acronym"],
)
except APIError as exc:
if exc.status_code == 401:
if exc.args[1]["status"] == 401:
ok = True
assert ok
# Nettoyage:

View File

@ -250,7 +250,7 @@ def run_sco_basic(verbose=False, dept=None) -> FormSemestre:
def _signal_absences_justificatifs(etudid: int):
etud: Identite = db.session.get(Identite, etudid)
etud: Identite = Identite.query.get(etudid)
db.session.commit()
for i in range(15, 18):
db.session.add(

View File

@ -968,8 +968,6 @@ def gen_api_doc(app, endpoint_start="api."):
with open(fname, "w", encoding="utf-8") as f:
f.write(mdpage)
print(
f"""La documentation API a été générée avec succès.
Vous pouvez la consulter à l'adresse suivante : {fname}.
Vous pouvez maintenant générer les samples avec `tools/test_api.sh --make-samples`.
"""
"La documentation API a été générée avec succès. "
f"Vous pouvez la consulter à l'adresse suivante : {fname}"
)

View File

@ -11,17 +11,13 @@
#
# Toutes les autres options sont passées telles qu'elles à pytest
#
# Utilisation pour générer des exemples de documentation:
# tools/test_api.sh --make-samples
#
# Exemples:
# - lancer tous les tests API: tools/test_api.sh
# - lancer tous les tests, en mode debug (arrêt pdb sur le 1er):
# tools/test_api.sh -x --pdb tests/api
# - lancer un module de test, en utilisant un server dev existant:
# tools/test_api.sh --dont-start-server -x --pdb tests/api/test_api_evaluations.py
# - Générer les samples pour la doc:
# tools/test_api.sh --make-samples
#
#
# E. Viennet, Fev 2023
@ -74,16 +70,10 @@ if [ "$#" -eq 0 ]
then
echo "Starting pytest tests/api"
pytest tests/api
else
if [ "$1" = "--make-samples" ]
then
echo "Generating API documentation samples"
python tests/api/make_samples.py -i /tmp/samples.csv
else
echo "Starting pytest $@"
pytest "$@"
fi
fi
# ------------------
if [ "$START_SERVER" -eq 1 ]