2021-01-17 22:31:28 +01:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2021-01-17 22:31:28 +01: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
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2024-02-04 23:08:08 +01:00
|
|
|
"""Fonctions sur les moduleimpl (legacy: use models.moduleimpls instead)
|
2021-01-17 22:31:28 +01:00
|
|
|
"""
|
2021-08-22 13:24:36 +02:00
|
|
|
|
2022-02-14 13:55:07 +01:00
|
|
|
import psycopg2
|
2021-06-19 23:21:37 +02:00
|
|
|
|
2024-07-08 23:13:45 +02:00
|
|
|
from app.models import Scolog
|
2023-07-11 06:57:38 +02:00
|
|
|
from app.scodoc import sco_cache
|
2021-06-19 23:21:37 +02:00
|
|
|
import app.scodoc.notesdb as ndb
|
2024-02-04 23:08:08 +01:00
|
|
|
from app.scodoc.sco_exceptions import ScoValueError
|
2021-01-17 22:31:28 +01:00
|
|
|
|
2021-10-22 23:09:15 +02:00
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def do_moduleimpl_inscription_list(moduleimpl_id=None, etudid=None):
|
2021-01-17 22:31:28 +01:00
|
|
|
"list moduleimpl_inscriptions"
|
|
|
|
args = locals()
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-09-27 10:20:10 +02:00
|
|
|
return _moduleimpl_inscriptionEditor.list(cnx, args)
|
2021-01-17 22:31:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
# --- Inscriptions aux modules
|
2021-06-19 23:21:37 +02:00
|
|
|
_moduleimpl_inscriptionEditor = ndb.EditableTable(
|
2021-01-17 22:31:28 +01:00
|
|
|
"notes_moduleimpl_inscription",
|
|
|
|
"moduleimpl_inscription_id",
|
|
|
|
("moduleimpl_inscription_id", "etudid", "moduleimpl_id"),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-02-14 21:45:58 +01:00
|
|
|
def do_moduleimpl_inscription_create(args, formsemestre_id=None, cnx=None):
|
2021-01-17 22:31:28 +01:00
|
|
|
"create a moduleimpl_inscription"
|
2024-02-14 21:45:58 +01:00
|
|
|
cnx = cnx or ndb.GetDBConnexion()
|
2022-02-14 13:55:07 +01:00
|
|
|
try:
|
|
|
|
r = _moduleimpl_inscriptionEditor.create(cnx, args)
|
|
|
|
except psycopg2.errors.UniqueViolation as exc:
|
|
|
|
raise ScoValueError(
|
|
|
|
"Inscription impossible car déjà existante: vérifiez la situation"
|
2022-12-07 20:06:01 +01:00
|
|
|
) from exc
|
2021-07-19 19:53:01 +02:00
|
|
|
sco_cache.invalidate_formsemestre(
|
|
|
|
formsemestre_id=formsemestre_id
|
2021-06-13 23:37:14 +02:00
|
|
|
) # > moduleimpl_inscription
|
2024-07-08 23:13:45 +02:00
|
|
|
Scolog.logdb(
|
2021-09-02 18:05:22 +02:00
|
|
|
method="moduleimpl_inscription",
|
|
|
|
etudid=args["etudid"],
|
2024-02-14 21:45:58 +01:00
|
|
|
msg=f"inscription module {args['moduleimpl_id']}",
|
2024-07-08 23:13:45 +02:00
|
|
|
commit=True,
|
2021-09-02 18:05:22 +02:00
|
|
|
)
|
2021-01-17 22:31:28 +01:00
|
|
|
return r
|
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_moduleimpl_inscription_delete(oid, formsemestre_id=None):
|
2021-01-17 22:31:28 +01:00
|
|
|
"delete moduleimpl_inscription"
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-01-17 22:31:28 +01:00
|
|
|
_moduleimpl_inscriptionEditor.delete(cnx, oid)
|
2021-07-19 19:53:01 +02:00
|
|
|
sco_cache.invalidate_formsemestre(
|
|
|
|
formsemestre_id=formsemestre_id
|
2021-06-13 23:37:14 +02:00
|
|
|
) # > moduleimpl_inscription
|
2021-01-17 22:31:28 +01:00
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def do_moduleimpl_inscrit_etuds(moduleimpl_id, formsemestre_id, etudids, reset=False):
|
2021-01-17 22:31:28 +01:00
|
|
|
"""Inscrit les etudiants (liste d'etudids) a ce module.
|
|
|
|
Si reset, desinscrit tous les autres.
|
|
|
|
"""
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_formsemestre_inscriptions
|
|
|
|
|
2021-01-17 22:31:28 +01:00
|
|
|
# Verifie qu'ils sont tous bien inscrits au semestre
|
|
|
|
for etudid in etudids:
|
2021-06-17 00:08:37 +02:00
|
|
|
insem = sco_formsemestre_inscriptions.do_formsemestre_inscription_list(
|
2021-08-19 10:28:35 +02:00
|
|
|
args={"formsemestre_id": formsemestre_id, "etudid": etudid}
|
2021-01-17 22:31:28 +01:00
|
|
|
)
|
|
|
|
if not insem:
|
2024-02-14 21:45:58 +01:00
|
|
|
raise ScoValueError(f"{etudid} n'est pas inscrit au semestre !")
|
2021-01-17 22:31:28 +01:00
|
|
|
|
2024-02-14 21:45:58 +01:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-01-17 22:31:28 +01:00
|
|
|
# Desinscriptions
|
|
|
|
if reset:
|
2021-06-19 23:21:37 +02:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
2021-01-17 22:31:28 +01:00
|
|
|
cursor.execute(
|
|
|
|
"delete from notes_moduleimpl_inscription where moduleimpl_id = %(moduleimpl_id)s",
|
|
|
|
{"moduleimpl_id": moduleimpl_id},
|
|
|
|
)
|
|
|
|
# Inscriptions au module:
|
2024-02-14 21:45:58 +01:00
|
|
|
inmod_set = {
|
|
|
|
x["etudid"] for x in do_moduleimpl_inscription_list(moduleimpl_id=moduleimpl_id)
|
|
|
|
}
|
2021-01-17 22:31:28 +01:00
|
|
|
for etudid in etudids:
|
2024-02-14 21:45:58 +01:00
|
|
|
# déja inscrit ?
|
2021-01-17 22:31:28 +01:00
|
|
|
if not etudid in inmod_set:
|
|
|
|
do_moduleimpl_inscription_create(
|
|
|
|
{"moduleimpl_id": moduleimpl_id, "etudid": etudid},
|
|
|
|
formsemestre_id=formsemestre_id,
|
2024-02-14 21:45:58 +01:00
|
|
|
cnx=cnx,
|
2021-01-17 22:31:28 +01:00
|
|
|
)
|
2024-02-14 21:45:58 +01:00
|
|
|
cnx.commit()
|
2021-07-19 19:53:01 +02:00
|
|
|
sco_cache.invalidate_formsemestre(
|
|
|
|
formsemestre_id=formsemestre_id
|
2021-06-13 23:37:14 +02:00
|
|
|
) # > moduleimpl_inscrit_etuds
|