From 3aa5629d1bb42027ec5295e69aebde953612a909 Mon Sep 17 00:00:00 2001 From: iziram Date: Thu, 27 Jul 2023 14:58:57 +0200 Subject: [PATCH] Assiduites: api routes nip ine --- app/api/assiduites.py | 114 +++++++++++++++++++++++++++++++-------- app/api/justificatifs.py | 48 ++++++++++++----- app/views/assiduites.py | 8 +-- 3 files changed, 129 insertions(+), 41 deletions(-) diff --git a/app/api/assiduites.py b/app/api/assiduites.py index a618a0ed..ccd35a30 100644 --- a/app/api/assiduites.py +++ b/app/api/assiduites.py @@ -15,7 +15,7 @@ from app import db, log import app.scodoc.sco_assiduites as scass import app.scodoc.sco_utils as scu from app.api import api_bp as bp -from app.api import api_web_bp, get_model_api_object +from app.api import api_web_bp, get_model_api_object, tools from app.decorators import permission_required, scodoc from app.models import Assiduite, FormSemestre, Identite, ModuleImpl, Scolog from app.scodoc.sco_exceptions import ScoValueError @@ -47,15 +47,35 @@ def assiduite(assiduite_id: int = None): return get_model_api_object(Assiduite, assiduite_id, Identite) -@bp.route("/assiduites//count", defaults={"with_query": False}) -@bp.route("/assiduites//count/query", defaults={"with_query": True}) -@api_web_bp.route("/assiduites//count", defaults={"with_query": False}) -@api_web_bp.route("/assiduites//count/query", defaults={"with_query": True}) +# etudid +@bp.route("/assiduites//count", defaults={"with_query": False}) +@api_web_bp.route("/assiduites//count", defaults={"with_query": False}) +@bp.route("/assiduites//count/query", defaults={"with_query": True}) +@api_web_bp.route("/assiduites//count/query", defaults={"with_query": True}) +@bp.route("/assiduites/etudid//count", defaults={"with_query": False}) +@api_web_bp.route("/assiduites/etudid//count", defaults={"with_query": False}) +@bp.route("/assiduites/etudid//count/query", defaults={"with_query": True}) +@api_web_bp.route( + "/assiduites/etudid//count/query", defaults={"with_query": True} +) +# nip +@bp.route("/assiduites/nip//count", defaults={"with_query": False}) +@api_web_bp.route("/assiduites/nip//count", defaults={"with_query": False}) +@bp.route("/assiduites/nip//count/query", defaults={"with_query": True}) +@api_web_bp.route("/assiduites/nip//count/query", defaults={"with_query": True}) +# ine +@bp.route("/assiduites/ine//count", defaults={"with_query": False}) +@api_web_bp.route("/assiduites/ine//count", defaults={"with_query": False}) +@bp.route("/assiduites/ine//count/query", defaults={"with_query": True}) +@api_web_bp.route("/assiduites/ine//count/query", defaults={"with_query": True}) +# @login_required @scodoc @as_json @permission_required(Permission.ScoView) -def count_assiduites(etudid: int = None, with_query: bool = False): +def count_assiduites( + etudid: int = None, nip: str = None, ine: str = None, with_query: bool = False +): """ Retourne le nombre d'assiduités d'un étudiant chemin : /assiduites//count @@ -100,11 +120,20 @@ def count_assiduites(etudid: int = None, with_query: bool = False): """ - query = Identite.query.filter_by(id=etudid) - if g.scodoc_dept: - query = query.filter_by(dept_id=g.scodoc_dept_id) + # query = Identite.query.filter_by(id=etudid) + # if g.scodoc_dept: + # query = query.filter_by(dept_id=g.scodoc_dept_id) + + # etud: Identite = query.first_or_404(etudid) + + etud: Identite = tools.get_etud(etudid, nip, ine) + + if etud is None: + return json_error( + 404, + message="étudiant inconnu", + ) - etud: Identite = query.first_or_404(etudid) filtered: dict[str, object] = {} metric: str = "all" @@ -116,15 +145,31 @@ def count_assiduites(etudid: int = None, with_query: bool = False): ) -@bp.route("/assiduites/", defaults={"with_query": False}) -@bp.route("/assiduites//query", defaults={"with_query": True}) -@api_web_bp.route("/assiduites/", defaults={"with_query": False}) -@api_web_bp.route("/assiduites//query", defaults={"with_query": True}) +# etudid +@bp.route("/assiduites/", defaults={"with_query": False}) +@api_web_bp.route("/assiduites/", defaults={"with_query": False}) +@bp.route("/assiduites//query", defaults={"with_query": True}) +@api_web_bp.route("/assiduites//query", defaults={"with_query": True}) +@bp.route("/assiduites/etudid/", defaults={"with_query": False}) +@api_web_bp.route("/assiduites/etudid/", defaults={"with_query": False}) +@bp.route("/assiduites/etudid//query", defaults={"with_query": True}) +@api_web_bp.route("/assiduites/etudid//query", defaults={"with_query": True}) +# nip +@bp.route("/assiduites/nip/", defaults={"with_query": False}) +@api_web_bp.route("/assiduites/nip/", defaults={"with_query": False}) +@bp.route("/assiduites/nip//query", defaults={"with_query": True}) +@api_web_bp.route("/assiduites/nip//query", defaults={"with_query": True}) +# ine +@bp.route("/assiduites/ine/", defaults={"with_query": False}) +@api_web_bp.route("/assiduites/ine/", defaults={"with_query": False}) +@bp.route("/assiduites/ine//query", defaults={"with_query": True}) +@api_web_bp.route("/assiduites/ine//query", defaults={"with_query": True}) +# @login_required @scodoc @as_json @permission_required(Permission.ScoView) -def assiduites(etudid: int = None, with_query: bool = False): +def assiduites(etudid: int = None, nip=None, ine=None, with_query: bool = False): """ Retourne toutes les assiduités d'un étudiant chemin : /assiduites/ @@ -164,11 +209,18 @@ def assiduites(etudid: int = None, with_query: bool = False): """ - query = Identite.query.filter_by(id=etudid) - if g.scodoc_dept: - query = query.filter_by(dept_id=g.scodoc_dept_id) + # query = Identite.query.filter_by(id=etudid) + # if g.scodoc_dept: + # query = query.filter_by(dept_id=g.scodoc_dept_id) - etud: Identite = query.first_or_404(etudid) + # etud: Identite = query.first_or_404(etudid) + etud: Identite = tools.get_etud(etudid, nip, ine) + + if etud is None: + return json_error( + 404, + message="étudiant inconnu", + ) assiduites_query = etud.assiduites if with_query: @@ -340,13 +392,23 @@ def count_assiduites_formsemestre( return scass.get_assiduites_stats(assiduites_query, metric, filtered) -@bp.route("/assiduite//create", methods=["POST"]) -@api_web_bp.route("/assiduite//create", methods=["POST"]) +# etudid +@bp.route("/assiduite//create", methods=["POST"]) +@api_web_bp.route("/assiduite//create", methods=["POST"]) +@bp.route("/assiduite/etudid//create", methods=["POST"]) +@api_web_bp.route("/assiduite/etudid//create", methods=["POST"]) +# nip +@bp.route("/assiduite/nip//create", methods=["POST"]) +@api_web_bp.route("/assiduite/nip//create", methods=["POST"]) +# ine +@bp.route("/assiduite/ine//create", methods=["POST"]) +@api_web_bp.route("/assiduite/ine//create", methods=["POST"]) +# @scodoc @as_json @login_required @permission_required(Permission.ScoAbsChange) -def assiduite_create(etudid: int = None): +def assiduite_create(etudid: int = None, nip=None, ine=None): """ Création d'une assiduité pour l'étudiant (etudid) La requête doit avoir un content type "application/json": @@ -367,7 +429,13 @@ def assiduite_create(etudid: int = None): ] """ - etud: Identite = Identite.query.filter_by(id=etudid).first_or_404() + etud: Identite = tools.get_etud(etudid, nip, ine) + + if etud is None: + return json_error( + 404, + message="étudiant inconnu", + ) create_list: list[object] = request.get_json(force=True) diff --git a/app/api/justificatifs.py b/app/api/justificatifs.py index 809124d6..c09a2e68 100644 --- a/app/api/justificatifs.py +++ b/app/api/justificatifs.py @@ -16,7 +16,7 @@ import app.scodoc.sco_utils as scu from app import db from app.api import api_bp as bp from app.api import api_web_bp -from app.api import get_model_api_object +from app.api import get_model_api_object, tools from app.decorators import permission_required, scodoc from app.models import Identite, Justificatif, Departement from app.models.assiduites import compute_assiduites_justified @@ -52,15 +52,31 @@ def justificatif(justif_id: int = None): return get_model_api_object(Justificatif, justif_id, Identite) -@bp.route("/justificatifs/", defaults={"with_query": False}) -@bp.route("/justificatifs//query", defaults={"with_query": True}) -@api_web_bp.route("/justificatifs/", defaults={"with_query": False}) -@api_web_bp.route("/justificatifs//query", defaults={"with_query": True}) +# etudid +@bp.route("/justificatifs/", defaults={"with_query": False}) +@api_web_bp.route("/justificatifs/", defaults={"with_query": False}) +@bp.route("/justificatifs//query", defaults={"with_query": True}) +@api_web_bp.route("/justificatifs//query", defaults={"with_query": True}) +@bp.route("/justificatifs/etudid/", defaults={"with_query": False}) +@api_web_bp.route("/justificatifs/etudid/", defaults={"with_query": False}) +@bp.route("/justificatifs/etudid//query", defaults={"with_query": True}) +@api_web_bp.route("/justificatifs/etudid//query", defaults={"with_query": True}) +# nip +@bp.route("/justificatifs/nip/", defaults={"with_query": False}) +@api_web_bp.route("/justificatifs/nip/", defaults={"with_query": False}) +@bp.route("/justificatifs/nip//query", defaults={"with_query": True}) +@api_web_bp.route("/justificatifs/nip//query", defaults={"with_query": True}) +# ine +@bp.route("/justificatifs/ine/", defaults={"with_query": False}) +@api_web_bp.route("/justificatifs/ine/", defaults={"with_query": False}) +@bp.route("/justificatifs/ine//query", defaults={"with_query": True}) +@api_web_bp.route("/justificatifs/ine//query", defaults={"with_query": True}) +# @login_required @scodoc @as_json @permission_required(Permission.ScoView) -def justificatifs(etudid: int = None, with_query: bool = False): +def justificatifs(etudid: int = None, nip=None, ine=None, with_query: bool = False): """ Retourne toutes les assiduités d'un étudiant chemin : /justificatifs/ @@ -87,11 +103,13 @@ def justificatifs(etudid: int = None, with_query: bool = False): ex query?user_id=3 """ - query = Identite.query.filter_by(id=etudid) - if g.scodoc_dept: - query = query.filter_by(dept_id=g.scodoc_dept_id) + etud: Identite = tools.get_etud(etudid, nip, ine) - etud: Identite = query.first_or_404(etudid) + if etud is None: + return json_error( + 404, + message="étudiant inconnu", + ) justificatifs_query = etud.justificatifs if with_query: @@ -136,7 +154,7 @@ def justificatifs_dept(dept_id: int = None, with_query: bool = False): @login_required @as_json @permission_required(Permission.ScoAbsChange) -def justif_create(etudid: int = None): +def justif_create(etudid: int = None, nip = None, ine = None): """ Création d'un justificatif pour l'étudiant (etudid) La requête doit avoir un content type "application/json": @@ -156,7 +174,13 @@ def justif_create(etudid: int = None): ] """ - etud: Identite = Identite.query.filter_by(id=etudid).first_or_404() + etud: Identite = tools.get_etud(etudid, nip, ine) + + if etud is None: + return json_error( + 404, + message="étudiant inconnu", + ) create_list: list[object] = request.get_json(force=True) diff --git a/app/views/assiduites.py b/app/views/assiduites.py index 1f21858d..8c1b7cc7 100644 --- a/app/views/assiduites.py +++ b/app/views/assiduites.py @@ -446,8 +446,6 @@ def signal_assiduites_group(): date: str = request.args.get("jour", datetime.date.today().isoformat()) group_ids: list[int] = request.args.get("group_ids", None) - readonly: str = "false" - if group_ids is None: group_ids = [] else: @@ -573,7 +571,7 @@ def signal_assiduites_group(): dept_id=g.scodoc_dept_id, ), defdem=_get_etuds_dem_def(formsemestre), - readonly=readonly, + readonly="false", ), html_sco_header.sco_footer(), ).build() @@ -594,8 +592,6 @@ def visu_assiduites_group(): date: str = request.args.get("jour", datetime.date.today().isoformat()) group_ids: list[int] = request.args.get("group_ids", None) - readonly: str = "true" - if group_ids is None: group_ids = [] else: @@ -721,7 +717,7 @@ def visu_assiduites_group(): dept_id=g.scodoc_dept_id, ), defdem=_get_etuds_dem_def(formsemestre), - readonly=readonly, + readonly="true", ), html_sco_header.sco_footer(), ).build()