ScoDocMM/app/api/sco_api.py

81 lines
2.9 KiB
Python
Raw Normal View History

2021-09-09 12:49:23 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
2022-01-01 14:49:42 +01:00
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
2021-09-09 12:49:23 +02:00
#
# 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
2021-12-21 18:49:33 +01:00
from datetime import datetime
2021-09-09 12:49:23 +02:00
2021-12-21 18:49:33 +01:00
from flask import jsonify, request, g, send_file
from sqlalchemy.sql import func
from app import db, log
2021-12-22 00:35:58 +01:00
from app.api import bp, requested_format
2021-09-09 12:49:23 +02:00
from app.api.auth import token_auth
2021-12-21 18:49:33 +01:00
from app.api.errors import error_response
2021-09-09 12:49:23 +02:00
from app import models
from app.models import FormSemestre, FormSemestreInscription, Identite
from app.scodoc.sco_permissions import Permission
2021-09-09 12:49:23 +02:00
@bp.route("list_depts", methods=["GET"])
2021-09-09 12:49:23 +02:00
@token_auth.login_required
def list_depts():
depts = models.Departement.query.filter_by(visible=True).all()
data = [d.to_dict() for d in depts]
2021-09-09 12:49:23 +02:00
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(),
)
2021-12-21 15:33:21 +01:00
return jsonify([e.to_dict_bul(include_urls=False) for e in query])