1
0
forked from ScoDoc/ScoDoc

Assiduites: api routes nip ine

This commit is contained in:
iziram 2023-07-27 14:58:57 +02:00
parent e5b1082e1d
commit 3aa5629d1b
3 changed files with 129 additions and 41 deletions

View File

@ -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/<int:etudid>/count", defaults={"with_query": False})
@bp.route("/assiduites/<int:etudid>/count/query", defaults={"with_query": True})
@api_web_bp.route("/assiduites/<int:etudid>/count", defaults={"with_query": False})
@api_web_bp.route("/assiduites/<int:etudid>/count/query", defaults={"with_query": True})
# etudid
@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})
@bp.route("/assiduites/etudid/<etudid>/count", defaults={"with_query": False})
@api_web_bp.route("/assiduites/etudid/<etudid>/count", defaults={"with_query": False})
@bp.route("/assiduites/etudid/<etudid>/count/query", defaults={"with_query": True})
@api_web_bp.route(
"/assiduites/etudid/<etudid>/count/query", defaults={"with_query": True}
)
# nip
@bp.route("/assiduites/nip/<nip>/count", defaults={"with_query": False})
@api_web_bp.route("/assiduites/nip/<nip>/count", defaults={"with_query": False})
@bp.route("/assiduites/nip/<nip>/count/query", defaults={"with_query": True})
@api_web_bp.route("/assiduites/nip/<nip>/count/query", defaults={"with_query": True})
# ine
@bp.route("/assiduites/ine/<ine>/count", defaults={"with_query": False})
@api_web_bp.route("/assiduites/ine/<ine>/count", defaults={"with_query": False})
@bp.route("/assiduites/ine/<ine>/count/query", defaults={"with_query": True})
@api_web_bp.route("/assiduites/ine/<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/<int:etudid>/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/<int:etudid>", defaults={"with_query": False})
@bp.route("/assiduites/<int:etudid>/query", defaults={"with_query": True})
@api_web_bp.route("/assiduites/<int:etudid>", defaults={"with_query": False})
@api_web_bp.route("/assiduites/<int:etudid>/query", defaults={"with_query": True})
# etudid
@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})
@bp.route("/assiduites/etudid/<etudid>", defaults={"with_query": False})
@api_web_bp.route("/assiduites/etudid/<etudid>", defaults={"with_query": False})
@bp.route("/assiduites/etudid/<etudid>/query", defaults={"with_query": True})
@api_web_bp.route("/assiduites/etudid/<etudid>/query", defaults={"with_query": True})
# nip
@bp.route("/assiduites/nip/<nip>", defaults={"with_query": False})
@api_web_bp.route("/assiduites/nip/<nip>", defaults={"with_query": False})
@bp.route("/assiduites/nip/<nip>/query", defaults={"with_query": True})
@api_web_bp.route("/assiduites/nip/<nip>/query", defaults={"with_query": True})
# ine
@bp.route("/assiduites/ine/<ine>", defaults={"with_query": False})
@api_web_bp.route("/assiduites/ine/<ine>", defaults={"with_query": False})
@bp.route("/assiduites/ine/<ine>/query", defaults={"with_query": True})
@api_web_bp.route("/assiduites/ine/<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/<int:etudid>
@ -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/<int:etudid>/create", methods=["POST"])
@api_web_bp.route("/assiduite/<int:etudid>/create", methods=["POST"])
# etudid
@bp.route("/assiduite/<etudid>/create", methods=["POST"])
@api_web_bp.route("/assiduite/<etudid>/create", methods=["POST"])
@bp.route("/assiduite/etudid/<etudid>/create", methods=["POST"])
@api_web_bp.route("/assiduite/etudid/<etudid>/create", methods=["POST"])
# nip
@bp.route("/assiduite/nip/<nip>/create", methods=["POST"])
@api_web_bp.route("/assiduite/nip/<nip>/create", methods=["POST"])
# ine
@bp.route("/assiduite/ine/<ine>/create", methods=["POST"])
@api_web_bp.route("/assiduite/ine/<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)

View File

@ -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/<int:etudid>", defaults={"with_query": False})
@bp.route("/justificatifs/<int:etudid>/query", defaults={"with_query": True})
@api_web_bp.route("/justificatifs/<int:etudid>", defaults={"with_query": False})
@api_web_bp.route("/justificatifs/<int:etudid>/query", defaults={"with_query": True})
# etudid
@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})
@bp.route("/justificatifs/etudid/<etudid>", defaults={"with_query": False})
@api_web_bp.route("/justificatifs/etudid/<etudid>", defaults={"with_query": False})
@bp.route("/justificatifs/etudid/<etudid>/query", defaults={"with_query": True})
@api_web_bp.route("/justificatifs/etudid/<etudid>/query", defaults={"with_query": True})
# nip
@bp.route("/justificatifs/nip/<nip>", defaults={"with_query": False})
@api_web_bp.route("/justificatifs/nip/<nip>", defaults={"with_query": False})
@bp.route("/justificatifs/nip/<nip>/query", defaults={"with_query": True})
@api_web_bp.route("/justificatifs/nip/<nip>/query", defaults={"with_query": True})
# ine
@bp.route("/justificatifs/ine/<ine>", defaults={"with_query": False})
@api_web_bp.route("/justificatifs/ine/<ine>", defaults={"with_query": False})
@bp.route("/justificatifs/ine/<ine>/query", defaults={"with_query": True})
@api_web_bp.route("/justificatifs/ine/<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/<int:etudid>
@ -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)

View File

@ -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()