245 lines
7.5 KiB
Python
245 lines
7.5 KiB
Python
# -*- mode: python -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
#
|
|
# Gestion scolarite IUT
|
|
#
|
|
# Copyright (c) 1999 - 2021 Emmanuel Viennet. All rights reserved.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
#
|
|
# Emmanuel Viennet emmanuel.viennet@viennet.net
|
|
#
|
|
##############################################################################
|
|
|
|
"""API ScoDoc 9
|
|
"""
|
|
# PAS ENCORE IMPLEMENTEE, juste un essai
|
|
# Pour P. Bouron, il faudrait en priorité l'équivalent de
|
|
# Scolarite/Notes/moduleimpl_withmodule_list (alias scodoc7 do_moduleimpl_withmodule_list)
|
|
# Scolarite/Notes/evaluation_create
|
|
# Scolarite/Notes/evaluation_delete
|
|
# Scolarite/Notes/formation_list
|
|
# Scolarite/Notes/formsemestre_list
|
|
# Scolarite/Notes/formsemestre_partition_list
|
|
# Scolarite/Notes/groups_view
|
|
# Scolarite/Notes/moduleimpl_status
|
|
# Scolarite/setGroups
|
|
from datetime import datetime
|
|
|
|
from flask import jsonify, request, g, send_file
|
|
from sqlalchemy.sql import func
|
|
|
|
from app import db, log
|
|
from app.api import bp, requested_format
|
|
from app.api.auth import token_auth
|
|
from app.api.errors import error_response
|
|
from app import models
|
|
from app.models import FormSemestre, FormSemestreInscription, Identite
|
|
from app.scodoc.sco_permissions import Permission
|
|
|
|
|
|
@bp.route("/list_depts", methods=["GET"])
|
|
@token_auth.login_required
|
|
def list_depts():
|
|
depts = models.Departement.query.filter_by(visible=True).all()
|
|
data = [d.to_dict() for d in depts]
|
|
return jsonify(data)
|
|
|
|
|
|
@bp.route("/etudiants/courant", methods=["GET"])
|
|
@token_auth.login_required
|
|
def etudiants():
|
|
"""Liste de tous les étudiants actuellement inscrits à un semestre
|
|
en cours.
|
|
"""
|
|
# Vérification de l'accès: permission Observateir sur tous les départements
|
|
# (c'est un exemple à compléter)
|
|
if not g.current_user.has_permission(Permission.ScoObservateur, None):
|
|
return error_response(401, message="accès interdit")
|
|
|
|
query = db.session.query(Identite).filter(
|
|
FormSemestreInscription.formsemestre_id == FormSemestre.id,
|
|
FormSemestreInscription.etudid == Identite.id,
|
|
FormSemestre.date_debut <= func.now(),
|
|
FormSemestre.date_fin >= func.now(),
|
|
)
|
|
return jsonify([e.to_dict_bul(include_urls=False) for e in query])
|
|
|
|
|
|
######################## Departements ##################################
|
|
|
|
|
|
@bp.route("/departements", methods=["GET"])
|
|
@token_auth.login_required
|
|
def departements():
|
|
"""
|
|
Liste des id de départements
|
|
"""
|
|
depts = models.Departement.query.filter_by(visible=True).all()
|
|
data = [d.to_dict() for d in depts]
|
|
return jsonify(data)
|
|
|
|
|
|
@bp.route("/departements/<string:dept>/etudiants/liste/<int:sem_id>", methods=["GET"])
|
|
@token_auth.login_required
|
|
def liste_etudiants(dept, *args, sem_id):
|
|
"""
|
|
Liste des étudiants d'un département
|
|
"""
|
|
if sem_id is not None:
|
|
list_etu = models.Departement.query.filter(
|
|
models.Departement.acronym == dept,
|
|
models.FormSemestre.semestre_id == sem_id,
|
|
)
|
|
else:
|
|
list_etu = models.Departement.query.filter(
|
|
models.Departement.acronym == dept,
|
|
models.FormSemestre.semestre_id == models.Departement.formsemestres,
|
|
)
|
|
data = [d.to_dict() for d in list_etu]
|
|
return jsonify(data)
|
|
|
|
|
|
@bp.route("/departements/<string:dept>/semestres_actifs", methods=["GET"])
|
|
@token_auth.login_required
|
|
def liste_semestres_actifs(dept):
|
|
"""
|
|
Liste des semestres actifs d'un départements donné
|
|
"""
|
|
dept_id = models.Departement.query.filter(models.Departement.acronym == dept)
|
|
depts_actifs = models.FormSemestre.query.filter_by(
|
|
etat=True,
|
|
dept_id=dept_id,
|
|
)
|
|
data = [da.to_dict() for da in depts_actifs]
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
@bp.route("/departements/<string:dept>/formations/<int:formation>/referentiel_competences")
|
|
@token_auth.login_required
|
|
def referenciel_competences(dept, formation):
|
|
"""
|
|
Le référenciel de compétences d'une formation donnée
|
|
"""
|
|
ref_comp = models.Formation.query.filter(
|
|
models.Departement.acronym == dept,
|
|
models.Formation.referentiel_competence_id == formation,
|
|
)
|
|
data = [rc.to_dict() for rc in ref_comp]
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
####################### Etudiants ##################################
|
|
|
|
@bp.route("/etudiant/<int:etudid>", methods=["GET"])
|
|
@token_auth.login_required
|
|
def etudiant(etudid):
|
|
"""
|
|
Un dictionnaire avec les informations de l'étudiant correspondant à l'id passé en paramètres.
|
|
"""
|
|
return jsonify(models.Identite.query.filter_by(etudid=etudid))
|
|
|
|
|
|
@bp.route("/etudiant/<int:etudid>/semestre/<int:sem_id>/bulletin", methods=["GET"])
|
|
@token_auth.login_required
|
|
def etudiant_bulletin_semestre(etudid, sem_id):
|
|
"""
|
|
Le bulletin d'un étudiant en fonction de son id et d'un semestre donné
|
|
"""
|
|
return jsonify(models.BulAppreciations.query.filter_by(etudid=etudid, formsemestre_id=sem_id))
|
|
|
|
|
|
@bp.route("/formsemestre/<int:formsemestre_id>/departements/<string:dept>/etudiant/nip/<int:NIP>/releve")
|
|
@bp.route("/formsemestre/<int:formsemestre_id>/departements/<string:dept>/etudiant/id/<int:etudid>/releve")
|
|
@bp.route("/formsemestre/<int:formsemestre_id>/departements/<string:dept>/etudiant/ine/<int:numScodoc/releve")
|
|
@token_auth.login_required
|
|
def etudiant_bulletin(formsemestre_id, dept, etudid, format="json", *args, size):
|
|
"""
|
|
Un bulletin de note
|
|
"""
|
|
data = []
|
|
if args[0] == "short":
|
|
pass
|
|
elif args[0] == "selectevals":
|
|
pass
|
|
elif args[0] == "long":
|
|
pass
|
|
else:
|
|
return "erreur"
|
|
|
|
return jsonify(data)
|
|
|
|
|
|
@bp.route("/etudiant/<int:etudid>/semestre/<int:formsemestre_id>/groups")
|
|
@token_auth.login_required
|
|
def etudiant_groups(etudid : int, fromsemestre_id : int):
|
|
"""
|
|
Liste des groupes auxquels appartient l'étudiant dans le semestre indiqué
|
|
"""
|
|
pass
|
|
|
|
#######################" Programmes de formations #########################
|
|
|
|
@bp.route("/formations")
|
|
@bp.route("/formations/<int:formation_id")
|
|
@token_auth.login_required
|
|
def formations(formation_id : int):
|
|
"""
|
|
Liste des formations
|
|
"""
|
|
pass
|
|
|
|
@bp.route("/formations/formation_export/<int:formation_id>")
|
|
@token_auth.login_required
|
|
def formation_export(formation_id : int, export_ids=False):
|
|
"""
|
|
La formation, avec UE, matières, modules
|
|
"""
|
|
pass
|
|
|
|
###################### UE #######################################
|
|
|
|
@bp.route("/departements/<string:dept>/formations/programme/string:sem_id>")
|
|
@token_auth.login_required
|
|
def eus(dept : str, sem_id : int):
|
|
"""
|
|
Liste des UES, ressources et SAE d'un semestre
|
|
"""
|
|
pass
|
|
|
|
|
|
######## Semestres de formation ###############
|
|
|
|
|
|
|
|
|
|
############ Modules de formation ##############
|
|
|
|
|
|
########### Groupes et partitions ###############
|
|
|
|
|
|
####### Bulletins de notes ###########
|
|
|
|
|
|
############## Absences #############
|
|
|
|
|
|
################ Logos ################
|