2020-09-26 16:19:37 +02: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.
|
2020-09-26 16:19:37 +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@gmail.com
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""Gestion des groupes, nouvelle mouture (juin/nov 2009)
|
|
|
|
"""
|
2021-02-03 22:00:41 +01:00
|
|
|
import collections
|
2021-07-29 16:31:15 +02:00
|
|
|
import time
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-07-10 17:22:27 +02:00
|
|
|
from xml.etree import ElementTree
|
|
|
|
from xml.etree.ElementTree import Element
|
|
|
|
|
2021-07-29 16:31:15 +02:00
|
|
|
import flask
|
2024-08-24 18:26:51 +02:00
|
|
|
from flask import g, make_response, render_template, request, url_for
|
2022-05-18 20:43:01 +02:00
|
|
|
from sqlalchemy.sql import text
|
2021-07-29 16:31:15 +02:00
|
|
|
|
2023-07-08 16:35:32 +02:00
|
|
|
from app import cache, db, log
|
2022-02-10 21:55:06 +01:00
|
|
|
from app.comp import res_sem
|
2022-03-27 22:25:00 +02:00
|
|
|
from app.comp.res_compat import NotesTableCompat
|
2023-07-05 19:15:33 +02:00
|
|
|
from app.models import FormSemestre, Identite, Scolog
|
2023-11-06 22:05:38 +01:00
|
|
|
from app.models import SHORT_STR_LEN
|
2023-09-02 22:19:35 +02:00
|
|
|
from app.models.groups import GroupDescr, Partition
|
2021-06-19 23:21:37 +02:00
|
|
|
import app.scodoc.notesdb as ndb
|
2021-07-19 19:53:01 +02:00
|
|
|
from app.scodoc import sco_cache
|
2023-02-12 13:36:47 +01:00
|
|
|
from app.scodoc import codes_cursus
|
2022-07-07 16:24:52 +02:00
|
|
|
from app.scodoc import sco_cursus
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_etud
|
2022-09-02 22:00:34 +02:00
|
|
|
from app.scodoc.sco_etud import etud_sort_key
|
2023-11-22 23:31:16 +01:00
|
|
|
import app.scodoc.sco_utils as scu
|
2021-07-10 17:22:27 +02:00
|
|
|
from app.scodoc import sco_xml
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc.sco_exceptions import ScoException, AccessDenied, ScoValueError
|
|
|
|
from app.scodoc.TrivialFormulator import TrivialFormulator
|
2021-07-10 17:22:27 +02:00
|
|
|
|
2021-02-03 22:00:41 +01:00
|
|
|
partitionEditor = ndb.EditableTable(
|
2020-09-26 16:19:37 +02:00
|
|
|
"partition",
|
|
|
|
"partition_id",
|
|
|
|
(
|
|
|
|
"partition_id",
|
|
|
|
"formsemestre_id",
|
|
|
|
"partition_name",
|
|
|
|
"compute_ranks",
|
|
|
|
"numero",
|
|
|
|
"bul_show_rank",
|
|
|
|
"show_in_lists",
|
2022-05-26 23:45:57 +02:00
|
|
|
"editable",
|
2020-09-26 16:19:37 +02:00
|
|
|
),
|
2021-08-11 00:36:07 +02:00
|
|
|
input_formators={
|
|
|
|
"bul_show_rank": bool,
|
|
|
|
"show_in_lists": bool,
|
2022-05-26 23:45:57 +02:00
|
|
|
"editable": bool,
|
2021-08-11 00:36:07 +02:00
|
|
|
},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
2021-02-03 22:00:41 +01:00
|
|
|
groupEditor = ndb.EditableTable(
|
2023-11-08 23:19:58 +01:00
|
|
|
"group_descr",
|
|
|
|
"group_id",
|
|
|
|
("group_id", "partition_id", "group_name", "numero", "edt_id"),
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
group_list = groupEditor.list
|
|
|
|
|
|
|
|
|
2023-07-05 19:15:33 +02:00
|
|
|
def get_group(group_id: int) -> dict: # OBSOLETE !
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Returns group object, with partition"""
|
2021-02-03 22:00:41 +01:00
|
|
|
r = ndb.SimpleDictFetch(
|
2021-08-08 17:38:46 +02:00
|
|
|
"""SELECT gd.id AS group_id, gd.*, p.id AS partition_id, p.*
|
2021-10-24 18:28:01 +02:00
|
|
|
FROM group_descr gd, partition p
|
|
|
|
WHERE gd.id=%(group_id)s
|
2021-08-08 17:38:46 +02:00
|
|
|
AND p.id = gd.partition_id
|
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"group_id": group_id},
|
|
|
|
)
|
|
|
|
if not r:
|
2022-09-13 10:50:13 +02:00
|
|
|
raise ScoValueError(f"Groupe inexistant ! (id {group_id})")
|
2020-09-26 16:19:37 +02:00
|
|
|
return r[0]
|
|
|
|
|
|
|
|
|
2022-05-28 11:38:22 +02:00
|
|
|
def group_delete(group_id: int):
|
2020-12-01 16:46:45 +01:00
|
|
|
"""Delete a group."""
|
2020-09-26 16:19:37 +02:00
|
|
|
# if not group['group_name'] and not force:
|
|
|
|
# raise ValueError('cannot suppress this group')
|
|
|
|
# remove memberships:
|
2022-05-28 11:38:22 +02:00
|
|
|
ndb.SimpleQuery(
|
|
|
|
"DELETE FROM group_membership WHERE group_id=%(group_id)s",
|
|
|
|
{"group_id": group_id},
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
# delete group:
|
2022-05-28 11:38:22 +02:00
|
|
|
ndb.SimpleQuery(
|
|
|
|
"DELETE FROM group_descr WHERE id=%(group_id)s", {"group_id": group_id}
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2023-07-05 19:15:33 +02:00
|
|
|
def get_partition(partition_id): # OBSOLETE
|
2021-02-03 22:00:41 +01:00
|
|
|
r = ndb.SimpleDictFetch(
|
2021-10-24 18:28:01 +02:00
|
|
|
"""SELECT p.id AS partition_id, p.*
|
|
|
|
FROM partition p
|
2021-08-08 17:38:46 +02:00
|
|
|
WHERE p.id = %(partition_id)s
|
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"partition_id": partition_id},
|
|
|
|
)
|
|
|
|
if not r:
|
2022-03-10 09:18:19 +01:00
|
|
|
raise ScoValueError(f"Partition inconnue (déjà supprimée ?) ({partition_id})")
|
2020-09-26 16:19:37 +02:00
|
|
|
return r[0]
|
|
|
|
|
|
|
|
|
2022-07-19 22:17:10 +02:00
|
|
|
def get_partitions_list(formsemestre_id, with_default=True) -> list[dict]:
|
2022-08-31 19:14:21 +02:00
|
|
|
"""Liste des partitions pour ce semestre (list of dicts),
|
|
|
|
triées par numéro, avec la partition par défaut en fin de liste.
|
2023-09-19 21:39:36 +02:00
|
|
|
OBSOLETE: utiliser FormSemestre.get_partitions_list
|
2022-08-31 19:14:21 +02:00
|
|
|
"""
|
2021-02-03 22:00:41 +01:00
|
|
|
partitions = ndb.SimpleDictFetch(
|
2021-10-24 18:28:01 +02:00
|
|
|
"""SELECT p.id AS partition_id, p.*
|
2021-08-08 17:38:46 +02:00
|
|
|
FROM partition p
|
2023-11-06 22:05:38 +01:00
|
|
|
WHERE formsemestre_id=%(formsemestre_id)s
|
2021-08-08 17:38:46 +02:00
|
|
|
ORDER BY numero""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"formsemestre_id": formsemestre_id},
|
|
|
|
)
|
|
|
|
# Move 'all' at end of list (for menus)
|
2022-07-19 22:17:10 +02:00
|
|
|
R = [p for p in partitions if p["partition_name"] is not None]
|
2020-09-26 16:19:37 +02:00
|
|
|
if with_default:
|
2022-07-19 22:17:10 +02:00
|
|
|
R += [p for p in partitions if p["partition_name"] is None]
|
2020-09-26 16:19:37 +02:00
|
|
|
return R
|
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def get_default_partition(formsemestre_id):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Get partition for 'all' students (this one always exists, with NULL name)"""
|
2021-02-03 22:00:41 +01:00
|
|
|
r = ndb.SimpleDictFetch(
|
2021-08-08 17:38:46 +02:00
|
|
|
"""SELECT p.id AS partition_id, p.* FROM partition p
|
2021-10-24 18:28:01 +02:00
|
|
|
WHERE formsemestre_id=%(formsemestre_id)s
|
2021-08-08 17:38:46 +02:00
|
|
|
AND partition_name is NULL
|
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"formsemestre_id": formsemestre_id},
|
|
|
|
)
|
|
|
|
if len(r) != 1:
|
|
|
|
raise ScoException(
|
|
|
|
"inconsistent partition: %d with NULL name for formsemestre_id=%s"
|
|
|
|
% (len(r), formsemestre_id)
|
|
|
|
)
|
|
|
|
return r[0]
|
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def get_formsemestre_groups(formsemestre_id, with_default=False):
|
2020-12-01 16:46:45 +01:00
|
|
|
"""Returns ( partitions, { partition_id : { etudid : group } } )."""
|
2021-08-19 10:28:35 +02:00
|
|
|
partitions = get_partitions_list(formsemestre_id, with_default=with_default)
|
2020-09-26 16:19:37 +02:00
|
|
|
partitions_etud_groups = {} # { partition_id : { etudid : group } }
|
|
|
|
for partition in partitions:
|
|
|
|
pid = partition["partition_id"]
|
2021-08-19 10:28:35 +02:00
|
|
|
partitions_etud_groups[pid] = get_etud_groups_in_partition(pid)
|
2020-09-26 16:19:37 +02:00
|
|
|
return partitions, partitions_etud_groups
|
|
|
|
|
|
|
|
|
2022-07-21 16:46:07 +02:00
|
|
|
def get_formsemestre_etuds_groups(formsemestre_id: int) -> dict:
|
|
|
|
"""{ etudid : { partition_id : group_id } }"""
|
|
|
|
infos = ndb.SimpleDictFetch(
|
|
|
|
"""SELECT etudid, p.id AS partition_id, gd.id AS group_id
|
|
|
|
FROM group_descr gd, group_membership gm, partition p
|
|
|
|
WHERE gd.partition_id = p.id
|
|
|
|
AND gm.group_id = gd.id
|
|
|
|
AND p.formsemestre_id = %(formsemestre_id)s
|
|
|
|
""",
|
|
|
|
{"formsemestre_id": formsemestre_id},
|
|
|
|
)
|
|
|
|
# -> {'etudid': 16483, 'group_id': 5317, 'partition_id': 2264},
|
|
|
|
d = collections.defaultdict(lambda: {})
|
|
|
|
for i in infos:
|
|
|
|
d[i["etudid"]][i["partition_id"]] = i["group_id"]
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
2023-07-05 19:15:33 +02:00
|
|
|
def get_partition_groups(partition): # OBSOLETE !
|
2020-09-26 16:19:37 +02:00
|
|
|
"""List of groups in this partition (list of dicts).
|
|
|
|
Some groups may be empty."""
|
2021-02-03 22:00:41 +01:00
|
|
|
return ndb.SimpleDictFetch(
|
2021-10-24 18:28:01 +02:00
|
|
|
"""SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.*
|
|
|
|
FROM group_descr gd, partition p
|
|
|
|
WHERE gd.partition_id=%(partition_id)s
|
|
|
|
AND gd.partition_id=p.id
|
2022-08-31 19:14:21 +02:00
|
|
|
ORDER BY gd.numero
|
2021-08-08 17:38:46 +02:00
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
partition,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-11 18:13:18 +01:00
|
|
|
def get_default_group(formsemestre_id, fix_if_missing=False) -> int:
|
|
|
|
"""Returns group_id for default ('tous') group
|
|
|
|
XXX remplacé par formsemestre.get_default_group
|
|
|
|
"""
|
2021-02-03 22:00:41 +01:00
|
|
|
r = ndb.SimpleDictFetch(
|
2021-08-08 17:38:46 +02:00
|
|
|
"""SELECT gd.id AS group_id
|
2021-10-24 18:28:01 +02:00
|
|
|
FROM group_descr gd, partition p
|
|
|
|
WHERE p.formsemestre_id=%(formsemestre_id)s
|
|
|
|
AND p.partition_name is NULL
|
2021-08-10 09:10:36 +02:00
|
|
|
AND p.id = gd.partition_id
|
2021-08-08 17:38:46 +02:00
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"formsemestre_id": formsemestre_id},
|
|
|
|
)
|
|
|
|
if len(r) == 0 and fix_if_missing:
|
|
|
|
# No default group (problem during sem creation)
|
|
|
|
# Try to create it
|
|
|
|
log(
|
2022-10-15 10:27:00 +02:00
|
|
|
f"""*** Warning: get_default_group(formsemestre_id={formsemestre_id
|
|
|
|
}): default group missing, recreating it"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
try:
|
2021-08-19 10:28:35 +02:00
|
|
|
partition_id = get_default_partition(formsemestre_id)["partition_id"]
|
2020-09-26 16:19:37 +02:00
|
|
|
except ScoException:
|
2022-10-15 10:27:00 +02:00
|
|
|
log(f"creating default partition for {formsemestre_id}")
|
2021-08-15 21:33:47 +02:00
|
|
|
partition_id = partition_create(
|
2021-08-19 10:28:35 +02:00
|
|
|
formsemestre_id, default=True, redirect=False
|
2021-08-15 21:33:47 +02:00
|
|
|
)
|
2022-09-02 15:07:59 +02:00
|
|
|
group = create_group(partition_id, default=True)
|
|
|
|
return group.id
|
2020-09-26 16:19:37 +02:00
|
|
|
# debug check
|
|
|
|
if len(r) != 1:
|
2023-07-12 22:36:03 +02:00
|
|
|
log(f"invalid group structure for {formsemestre_id}: {len(r)}")
|
2020-09-26 16:19:37 +02:00
|
|
|
group_id = r[0]["group_id"]
|
|
|
|
return group_id
|
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def get_sem_groups(formsemestre_id):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Returns groups for this sem (in all partitions)."""
|
2021-02-03 22:00:41 +01:00
|
|
|
return ndb.SimpleDictFetch(
|
2021-08-10 09:10:36 +02:00
|
|
|
"""SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.*
|
2021-10-24 18:28:01 +02:00
|
|
|
FROM group_descr gd, partition p
|
|
|
|
WHERE p.formsemestre_id=%(formsemestre_id)s
|
2021-08-10 09:10:36 +02:00
|
|
|
AND p.id = gd.partition_id
|
2021-08-08 17:38:46 +02:00
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"formsemestre_id": formsemestre_id},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-12-09 15:53:45 +01:00
|
|
|
def get_group_members(group_id: int, etat=None) -> list[dict]:
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Liste des etudiants d'un groupe.
|
|
|
|
Si etat, filtre selon l'état de l'inscription
|
|
|
|
Trié par nom_usuel (ou nom) puis prénom
|
2023-12-09 15:53:45 +01:00
|
|
|
Résultat: list de dict avec champs étudiant, adresse, group_membership
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2021-08-10 09:10:36 +02:00
|
|
|
req = """SELECT i.id as etudid, i.*, a.*, gm.*, ins.etat
|
2023-11-06 22:05:38 +01:00
|
|
|
FROM identite i, adresse a, group_membership gm,
|
|
|
|
group_descr gd, partition p, notes_formsemestre_inscription ins
|
|
|
|
WHERE i.id = gm.etudid
|
|
|
|
and a.etudid = i.id
|
|
|
|
and ins.etudid = i.id
|
|
|
|
and ins.formsemestre_id = p.formsemestre_id
|
|
|
|
and p.id = gd.partition_id
|
|
|
|
and gd.id = gm.group_id
|
2021-08-08 17:38:46 +02:00
|
|
|
and gm.group_id=%(group_id)s
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
if etat is not None:
|
|
|
|
req += " and ins.etat = %(etat)s"
|
|
|
|
|
2021-07-28 17:03:54 +02:00
|
|
|
r = ndb.SimpleDictFetch(req, {"group_id": group_id, "etat": etat})
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
for etud in r:
|
2021-06-19 23:21:37 +02:00
|
|
|
sco_etud.format_etud_ident(etud)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-09-02 22:00:34 +02:00
|
|
|
# tri selon nom_usuel ou nom, sans accents
|
|
|
|
r.sort(key=etud_sort_key)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-02-04 20:02:44 +01:00
|
|
|
if scu.CONFIG.ALLOW_NULL_PRENOM:
|
2020-09-26 16:19:37 +02:00
|
|
|
for x in r:
|
|
|
|
x["prenom"] = x["prenom"] or ""
|
|
|
|
|
|
|
|
return r
|
|
|
|
|
2022-06-27 19:47:41 +02:00
|
|
|
|
2023-11-16 23:34:47 +01:00
|
|
|
def get_group_infos(group_id, etat: str | None = None): # was _getlisteetud
|
|
|
|
"""legacy code: used by group_list and trombino.
|
|
|
|
etat: état de l'inscription."""
|
2021-06-21 10:17:16 +02:00
|
|
|
from app.scodoc import sco_formsemestre
|
|
|
|
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-08-19 10:28:35 +02:00
|
|
|
group = get_group(group_id)
|
2023-02-01 14:35:25 +01:00
|
|
|
sem = sco_formsemestre.get_formsemestre(group["formsemestre_id"])
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
members = get_group_members(group_id, etat=etat)
|
2020-09-26 16:19:37 +02:00
|
|
|
# add human readable description of state:
|
|
|
|
nbdem = 0
|
|
|
|
for t in members:
|
2022-09-30 22:43:39 +02:00
|
|
|
if t["etat"] == scu.INSCRIT:
|
2020-09-26 16:19:37 +02:00
|
|
|
t["etath"] = "" # etudiant inscrit, ne l'indique pas dans la liste HTML
|
2022-09-30 22:43:39 +02:00
|
|
|
elif t["etat"] == scu.DEMISSION:
|
2021-06-19 23:21:37 +02:00
|
|
|
events = sco_etud.scolar_events_list(
|
2020-09-26 16:19:37 +02:00
|
|
|
cnx,
|
|
|
|
args={
|
|
|
|
"etudid": t["etudid"],
|
|
|
|
"formsemestre_id": group["formsemestre_id"],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
for event in events:
|
|
|
|
event_type = event["event_type"]
|
|
|
|
if event_type == "DEMISSION":
|
|
|
|
t["date_dem"] = event["event_date"]
|
|
|
|
break
|
|
|
|
if "date_dem" in t:
|
|
|
|
t["etath"] = "démission le %s" % t["date_dem"]
|
|
|
|
else:
|
|
|
|
t["etath"] = "(dem.)"
|
|
|
|
nbdem += 1
|
2023-02-12 13:36:47 +01:00
|
|
|
elif t["etat"] == codes_cursus.DEF:
|
2020-09-26 16:19:37 +02:00
|
|
|
t["etath"] = "Défaillant"
|
|
|
|
else:
|
|
|
|
t["etath"] = t["etat"]
|
|
|
|
# Add membership for all partitions, 'partition_id' : group
|
|
|
|
for etud in members: # long: comment eviter ces boucles ?
|
2022-03-05 12:47:08 +01:00
|
|
|
etud_add_group_infos(etud, sem["formsemestre_id"])
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-09-30 16:20:51 +02:00
|
|
|
if group["partition_name"] is None:
|
2020-09-26 16:19:37 +02:00
|
|
|
group_tit = "tous"
|
2022-09-30 16:20:51 +02:00
|
|
|
else:
|
|
|
|
group_tit = f"""{group["partition_name"]} {group["group_name"]}"""
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
return members, group, group_tit, sem, nbdem
|
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def get_group_other_partitions(group):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Liste des partitions du même semestre que ce groupe,
|
|
|
|
sans celle qui contient ce groupe.
|
|
|
|
"""
|
|
|
|
other_partitions = [
|
|
|
|
p
|
2021-08-19 10:28:35 +02:00
|
|
|
for p in get_partitions_list(group["formsemestre_id"])
|
2020-09-26 16:19:37 +02:00
|
|
|
if p["partition_id"] != group["partition_id"] and p["partition_name"]
|
|
|
|
]
|
|
|
|
return other_partitions
|
|
|
|
|
|
|
|
|
2022-03-27 10:05:12 +02:00
|
|
|
def get_etud_groups(etudid: int, formsemestre_id: int, exclude_default=False):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Infos sur groupes de l'etudiant dans ce semestre
|
|
|
|
[ group + partition_name ]
|
|
|
|
"""
|
2023-11-06 22:05:38 +01:00
|
|
|
req = """SELECT p.id AS partition_id, p.*,
|
2022-09-26 17:05:49 +02:00
|
|
|
g.id AS group_id, g.numero as group_numero, g.group_name
|
2023-11-06 22:05:38 +01:00
|
|
|
FROM group_descr g, partition p, group_membership gm
|
|
|
|
WHERE gm.etudid=%(etudid)s
|
|
|
|
and gm.group_id = g.id
|
|
|
|
and g.partition_id = p.id
|
2021-08-08 17:38:46 +02:00
|
|
|
and p.formsemestre_id = %(formsemestre_id)s
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
if exclude_default:
|
|
|
|
req += " and p.partition_name is not NULL"
|
2021-02-03 22:00:41 +01:00
|
|
|
groups = ndb.SimpleDictFetch(
|
2020-09-26 16:19:37 +02:00
|
|
|
req + " ORDER BY p.numero",
|
2022-03-27 10:05:12 +02:00
|
|
|
{"etudid": etudid, "formsemestre_id": formsemestre_id},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
return _sortgroups(groups)
|
|
|
|
|
|
|
|
|
2022-03-27 10:05:12 +02:00
|
|
|
def get_etud_main_group(etudid: int, formsemestre_id: int):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Return main group (the first one) for etud, or default one if no groups"""
|
2022-03-27 10:05:12 +02:00
|
|
|
groups = get_etud_groups(etudid, formsemestre_id, exclude_default=True)
|
2020-09-26 16:19:37 +02:00
|
|
|
if groups:
|
|
|
|
return groups[0]
|
|
|
|
else:
|
2022-03-27 10:05:12 +02:00
|
|
|
return get_group(get_default_group(formsemestre_id))
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def formsemestre_get_main_partition(formsemestre_id):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Return main partition (the first one) for sem, or default one if no groups
|
|
|
|
(rappel: default == tous, main == principale (groupes TD habituellement)
|
|
|
|
"""
|
2021-08-19 10:28:35 +02:00
|
|
|
return get_partitions_list(formsemestre_id, with_default=True)[0]
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def formsemestre_get_etud_groupnames(formsemestre_id, attr="group_name"):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Recupere les groupes de tous les etudiants d'un semestre
|
|
|
|
{ etudid : { partition_id : group_name }} (attr=group_name or group_id)
|
|
|
|
"""
|
2021-02-03 22:00:41 +01:00
|
|
|
infos = ndb.SimpleDictFetch(
|
2021-11-12 11:31:50 +01:00
|
|
|
"""SELECT
|
|
|
|
i.etudid AS etudid,
|
|
|
|
p.id AS partition_id,
|
|
|
|
gd.group_name,
|
|
|
|
gd.id AS group_id
|
2023-11-06 22:05:38 +01:00
|
|
|
FROM
|
2021-11-12 11:31:50 +01:00
|
|
|
notes_formsemestre_inscription i,
|
|
|
|
partition p,
|
|
|
|
group_descr gd,
|
|
|
|
group_membership gm
|
|
|
|
WHERE
|
|
|
|
i.formsemestre_id=%(formsemestre_id)s
|
2021-08-11 00:36:07 +02:00
|
|
|
and i.formsemestre_id = p.formsemestre_id
|
|
|
|
and p.id = gd.partition_id
|
|
|
|
and gm.etudid = i.etudid
|
|
|
|
and gm.group_id = gd.id
|
2021-08-08 17:38:46 +02:00
|
|
|
and p.partition_name is not NULL
|
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"formsemestre_id": formsemestre_id},
|
|
|
|
)
|
|
|
|
R = {}
|
|
|
|
for info in infos:
|
|
|
|
if info["etudid"] in R:
|
|
|
|
R[info["etudid"]][info["partition_id"]] = info[attr]
|
|
|
|
else:
|
|
|
|
R[info["etudid"]] = {info["partition_id"]: info[attr]}
|
|
|
|
return R
|
|
|
|
|
|
|
|
|
2022-05-18 20:43:01 +02:00
|
|
|
def get_etud_formsemestre_groups(
|
|
|
|
etud: Identite, formsemestre: FormSemestre, only_to_show=True
|
|
|
|
) -> list[GroupDescr]:
|
2022-08-31 09:16:00 +02:00
|
|
|
"""Liste les groupes auxquels est inscrit.
|
|
|
|
Si only_to_show (défaut vrai), ne donne que les groupes "visiables",
|
|
|
|
c'est à dire des partitions avec show_in_lists True.
|
|
|
|
"""
|
|
|
|
# Note: je n'ai pas réussi à construire une requete SQLAlechemy avec
|
2022-05-18 20:43:01 +02:00
|
|
|
# la Table d'association group_membership
|
|
|
|
cursor = db.session.execute(
|
|
|
|
text(
|
|
|
|
"""
|
|
|
|
SELECT g.id
|
|
|
|
FROM group_descr g, group_membership gm, partition p
|
|
|
|
WHERE gm.etudid = :etudid
|
|
|
|
AND gm.group_id = g.id
|
|
|
|
AND g.partition_id = p.id
|
|
|
|
AND p.formsemestre_id = :formsemestre_id
|
|
|
|
AND p.partition_name is not NULL
|
|
|
|
"""
|
|
|
|
+ (" and (p.show_in_lists is True) " if only_to_show else "")
|
|
|
|
+ """
|
|
|
|
ORDER BY p.numero
|
|
|
|
"""
|
|
|
|
),
|
|
|
|
{"etudid": etud.id, "formsemestre_id": formsemestre.id},
|
|
|
|
)
|
2023-07-11 06:57:38 +02:00
|
|
|
return [db.session.get(GroupDescr, group_id) for group_id in cursor]
|
2022-05-18 20:43:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Ancienne fonction:
|
2023-03-01 14:39:36 +01:00
|
|
|
def etud_add_group_infos(
|
|
|
|
etud, formsemestre_id, sep=" ", only_to_show=False, with_default_partition=True
|
|
|
|
):
|
2022-05-09 19:56:40 +02:00
|
|
|
"""Add informations on partitions and group memberships to etud
|
|
|
|
(a dict with an etudid)
|
|
|
|
If only_to_show, restrict to partions such that show_in_lists is True.
|
2023-03-01 14:39:36 +01:00
|
|
|
If with_default_partition, does not discard partition whose name is None
|
2022-05-09 19:56:40 +02:00
|
|
|
etud['partitions'] = { partition_id : group + partition_name }
|
|
|
|
etud['groupes'] = "TDB, Gr2, TPB1"
|
|
|
|
etud['partitionsgroupes'] = "Groupes TD:TDB, Groupes TP:Gr2 (...)"
|
|
|
|
"""
|
2024-06-07 17:58:02 +02:00
|
|
|
etud["partitions"] = (
|
|
|
|
collections.OrderedDict()
|
|
|
|
) # partition_id : group + partition_name
|
2022-03-05 12:47:08 +01:00
|
|
|
if not formsemestre_id:
|
2020-09-26 16:19:37 +02:00
|
|
|
etud["groupes"] = ""
|
|
|
|
return etud
|
2021-02-03 22:00:41 +01:00
|
|
|
infos = ndb.SimpleDictFetch(
|
2022-05-09 19:56:40 +02:00
|
|
|
"""SELECT p.partition_name, p.show_in_lists, g.*, g.id AS group_id
|
2021-08-08 17:38:46 +02:00
|
|
|
FROM group_descr g, partition p, group_membership gm WHERE gm.etudid=%(etudid)s
|
|
|
|
and gm.group_id = g.id
|
|
|
|
and g.partition_id = p.id
|
2021-10-24 18:28:01 +02:00
|
|
|
and p.formsemestre_id = %(formsemestre_id)s
|
2022-05-09 19:56:40 +02:00
|
|
|
"""
|
|
|
|
+ (" and (p.show_in_lists is True) " if only_to_show else "")
|
2023-03-01 14:39:36 +01:00
|
|
|
+ (" and (p.partition_name is not null) " if not with_default_partition else "")
|
2022-05-09 19:56:40 +02:00
|
|
|
+ """
|
2021-08-08 17:38:46 +02:00
|
|
|
ORDER BY p.numero
|
|
|
|
""",
|
2022-03-05 12:47:08 +01:00
|
|
|
{"etudid": etud["etudid"], "formsemestre_id": formsemestre_id},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
for info in infos:
|
|
|
|
if info["partition_name"]:
|
|
|
|
etud["partitions"][info["partition_id"]] = info
|
|
|
|
|
|
|
|
# resume textuel des groupes:
|
|
|
|
etud["groupes"] = sep.join(
|
2022-03-05 12:47:08 +01:00
|
|
|
[gr["group_name"] for gr in infos if gr["group_name"] is not None]
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
etud["partitionsgroupes"] = sep.join(
|
|
|
|
[
|
2022-05-18 20:43:01 +02:00
|
|
|
(gr["partition_name"] or "") + ":" + gr["group_name"]
|
2022-03-05 12:47:08 +01:00
|
|
|
for gr in infos
|
|
|
|
if gr["group_name"] is not None
|
2020-09-26 16:19:37 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
return etud
|
|
|
|
|
|
|
|
|
2021-10-15 14:00:51 +02:00
|
|
|
@cache.memoize(timeout=50) # seconds
|
2021-08-19 10:28:35 +02:00
|
|
|
def get_etud_groups_in_partition(partition_id):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Returns { etudid : group }, with all students in this partition"""
|
2021-02-03 22:00:41 +01:00
|
|
|
infos = ndb.SimpleDictFetch(
|
2021-08-10 12:57:38 +02:00
|
|
|
"""SELECT gd.id AS group_id, gd.*, etudid
|
2021-08-08 17:38:46 +02:00
|
|
|
FROM group_descr gd, group_membership gm
|
|
|
|
WHERE gd.partition_id = %(partition_id)s
|
2021-08-10 12:57:38 +02:00
|
|
|
AND gm.group_id = gd.id
|
2021-08-08 17:38:46 +02:00
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"partition_id": partition_id},
|
|
|
|
)
|
|
|
|
R = {}
|
|
|
|
for i in infos:
|
|
|
|
R[i["etudid"]] = i
|
|
|
|
return R
|
|
|
|
|
|
|
|
|
2023-09-21 10:20:19 +02:00
|
|
|
def formsemestre_partition_list(formsemestre_id, fmt="xml"):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Get partitions and groups in this semestre
|
|
|
|
Supported formats: xml, json
|
|
|
|
"""
|
2021-08-19 10:28:35 +02:00
|
|
|
partitions = get_partitions_list(formsemestre_id, with_default=True)
|
2020-09-26 16:19:37 +02:00
|
|
|
# Ajoute les groupes
|
|
|
|
for p in partitions:
|
2021-08-19 10:28:35 +02:00
|
|
|
p["group"] = get_partition_groups(p)
|
2023-09-21 10:20:19 +02:00
|
|
|
return scu.sendResult(partitions, name="partition", fmt=fmt)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-07-10 17:22:27 +02:00
|
|
|
# Encore utilisé par groupmgr.js
|
2021-09-27 10:20:10 +02:00
|
|
|
def XMLgetGroupsInPartition(partition_id): # was XMLgetGroupesTD
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
Deprecated: use group_list
|
|
|
|
Liste des étudiants dans chaque groupe de cette partition.
|
2022-09-02 15:07:59 +02:00
|
|
|
<group partition_id="" partition_name="" group_id="" group_name="" groups_editable="">
|
2021-07-10 17:22:27 +02:00
|
|
|
<etud etuid="" sexe="" nom="" prenom="" civilite="" origin=""/>
|
|
|
|
</group>
|
|
|
|
<group ...>
|
|
|
|
...
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
t0 = time.time()
|
2021-08-19 10:28:35 +02:00
|
|
|
partition = get_partition(partition_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
formsemestre_id = partition["formsemestre_id"]
|
2023-03-20 11:17:38 +01:00
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
2022-02-10 21:55:06 +01:00
|
|
|
etuds_set = {ins.etudid for ins in formsemestre.inscriptions}
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
groups = get_partition_groups(partition)
|
2021-09-27 10:20:10 +02:00
|
|
|
# Build XML:
|
2021-10-04 22:05:05 +02:00
|
|
|
t1 = time.time()
|
2021-07-10 17:22:27 +02:00
|
|
|
doc = Element("ajax-response")
|
|
|
|
x_response = Element("response", type="object", id="MyUpdater")
|
|
|
|
doc.append(x_response)
|
2020-09-26 16:19:37 +02:00
|
|
|
for group in groups:
|
2021-07-10 17:22:27 +02:00
|
|
|
x_group = Element(
|
|
|
|
"group",
|
2021-08-11 00:36:07 +02:00
|
|
|
partition_id=str(partition_id),
|
2023-07-17 14:04:42 +02:00
|
|
|
partition_name=partition["partition_name"] or "",
|
2022-09-02 15:07:59 +02:00
|
|
|
groups_editable=str(int(partition["groups_editable"])),
|
2021-08-11 00:36:07 +02:00
|
|
|
group_id=str(group["group_id"]),
|
2023-07-17 14:04:42 +02:00
|
|
|
group_name=group["group_name"] or "",
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
2021-07-10 17:22:27 +02:00
|
|
|
x_response.append(x_group)
|
2021-08-19 10:28:35 +02:00
|
|
|
for e in get_group_members(group["group_id"]):
|
2021-10-04 22:05:05 +02:00
|
|
|
etud = sco_etud.get_etud_info(etudid=e["etudid"], filled=True)[0]
|
2021-07-10 17:22:27 +02:00
|
|
|
x_group.append(
|
|
|
|
Element(
|
|
|
|
"etud",
|
2021-08-11 00:36:07 +02:00
|
|
|
etudid=str(e["etudid"]),
|
2023-07-17 14:04:42 +02:00
|
|
|
civilite=etud["civilite_str"] or "",
|
|
|
|
sexe=etud["civilite_str"] or "", # compat
|
2023-11-22 23:31:16 +01:00
|
|
|
nom=scu.format_nom(etud["nom"] or ""),
|
|
|
|
prenom=scu.format_prenom(etud["prenom"] or ""),
|
2022-08-31 19:14:21 +02:00
|
|
|
origin=_comp_etud_origin(etud, formsemestre),
|
2021-07-10 17:22:27 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
if e["etudid"] in etuds_set:
|
|
|
|
etuds_set.remove(e["etudid"]) # etudiant vu dans un groupe
|
|
|
|
|
|
|
|
# Ajoute les etudiants inscrits au semestre mais dans aucun groupe de cette partition:
|
|
|
|
if etuds_set:
|
2021-07-10 17:22:27 +02:00
|
|
|
x_group = Element(
|
|
|
|
"group",
|
2021-08-11 00:36:07 +02:00
|
|
|
partition_id=str(partition_id),
|
2023-07-13 12:55:19 +02:00
|
|
|
partition_name=partition["partition_name"] or "",
|
2022-09-02 15:07:59 +02:00
|
|
|
groups_editable=str(int(partition["groups_editable"])),
|
2020-09-26 16:19:37 +02:00
|
|
|
group_id="_none_",
|
|
|
|
group_name="",
|
|
|
|
)
|
2021-07-10 17:22:27 +02:00
|
|
|
doc.append(x_group)
|
2020-09-26 16:19:37 +02:00
|
|
|
for etudid in etuds_set:
|
2021-08-22 13:24:36 +02:00
|
|
|
etud = sco_etud.get_etud_info(etudid=etudid, filled=True)[0]
|
2021-07-10 17:22:27 +02:00
|
|
|
x_group.append(
|
|
|
|
Element(
|
|
|
|
"etud",
|
2021-08-11 00:36:07 +02:00
|
|
|
etudid=str(etud["etudid"]),
|
2023-07-13 12:55:19 +02:00
|
|
|
sexe=etud["civilite_str"] or "",
|
2023-11-22 23:31:16 +01:00
|
|
|
nom=scu.format_nom(etud["nom"] or ""),
|
|
|
|
prenom=scu.format_prenom(etud["prenom"] or ""),
|
2022-08-31 19:14:21 +02:00
|
|
|
origin=_comp_etud_origin(etud, formsemestre),
|
2021-07-10 17:22:27 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
2021-10-04 22:05:05 +02:00
|
|
|
t2 = time.time()
|
|
|
|
log(f"XMLgetGroupsInPartition: {t2-t0} seconds ({t1-t0}+{t2-t1})")
|
2021-09-27 10:20:10 +02:00
|
|
|
# XML response:
|
|
|
|
data = sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING)
|
|
|
|
response = make_response(data)
|
|
|
|
response.headers["Content-Type"] = scu.XML_MIMETYPE
|
|
|
|
return response
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2022-08-31 19:14:21 +02:00
|
|
|
def _comp_etud_origin(etud: dict, cur_formsemestre: FormSemestre):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""breve description de l'origine de l'étudiant (sem. precedent)
|
|
|
|
(n'indique l'origine que si ce n'est pas le semestre precedent normal)
|
|
|
|
"""
|
|
|
|
# cherche le semestre suivant le sem. courant dans la liste
|
|
|
|
cur_sem_idx = None
|
|
|
|
for i in range(len(etud["sems"])):
|
2022-08-31 19:14:21 +02:00
|
|
|
if etud["sems"][i]["formsemestre_id"] == cur_formsemestre.id:
|
2020-09-26 16:19:37 +02:00
|
|
|
cur_sem_idx = i
|
|
|
|
break
|
|
|
|
|
|
|
|
if cur_sem_idx is None or (cur_sem_idx + 1) >= (len(etud["sems"]) - 1):
|
|
|
|
return "" # on pourrait indiquer le bac mais en general on ne l'a pas en debut d'annee
|
|
|
|
|
|
|
|
prev_sem = etud["sems"][cur_sem_idx + 1]
|
2022-08-31 19:14:21 +02:00
|
|
|
if prev_sem["semestre_id"] != (cur_formsemestre.semestre_id - 1):
|
|
|
|
return f" (S{prev_sem['semestre_id']})"
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
|
|
|
return "" # parcours normal, ne le signale pas
|
|
|
|
|
|
|
|
|
2023-07-05 19:15:33 +02:00
|
|
|
def set_group(etudid: int, group_id: int) -> bool: # OBSOLETE !
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Inscrit l'étudiant au groupe.
|
|
|
|
Return True if ok, False si deja inscrit.
|
2022-05-26 23:45:57 +02:00
|
|
|
Warning:
|
|
|
|
- don't check if group_id exists (the caller should check).
|
|
|
|
- don't check if group's partition is editable
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-02-03 22:00:41 +01:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
2020-09-26 16:19:37 +02:00
|
|
|
args = {"etudid": etudid, "group_id": group_id}
|
|
|
|
# déjà inscrit ?
|
2021-02-03 22:00:41 +01:00
|
|
|
r = ndb.SimpleDictFetch(
|
2020-09-26 16:19:37 +02:00
|
|
|
"SELECT * FROM group_membership gm WHERE etudid=%(etudid)s and group_id=%(group_id)s",
|
|
|
|
args,
|
|
|
|
cursor=cursor,
|
|
|
|
)
|
|
|
|
if len(r):
|
|
|
|
return False
|
|
|
|
# inscrit
|
2021-02-03 22:00:41 +01:00
|
|
|
ndb.SimpleQuery(
|
2020-09-26 16:19:37 +02:00
|
|
|
"INSERT INTO group_membership (etudid, group_id) VALUES (%(etudid)s, %(group_id)s)",
|
|
|
|
args,
|
|
|
|
cursor=cursor,
|
|
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2023-07-08 13:57:44 +02:00
|
|
|
def change_etud_group_in_partition(etudid: int, group: GroupDescr) -> bool:
|
2023-07-05 19:15:33 +02:00
|
|
|
"""Inscrit etud au groupe
|
2023-07-08 13:57:44 +02:00
|
|
|
(et le désinscrit d'autres groupes de cette partition)
|
|
|
|
Return True si changement, False s'il était déjà dans ce groupe.
|
2023-01-24 00:35:15 +01:00
|
|
|
"""
|
2024-10-29 19:18:36 +01:00
|
|
|
etud: Identite = Identite.get_or_404(etudid)
|
2023-07-08 16:35:32 +02:00
|
|
|
if not group.partition.set_etud_group(etud, group):
|
2023-07-08 13:57:44 +02:00
|
|
|
return # pas de changement
|
2023-07-05 19:15:33 +02:00
|
|
|
|
|
|
|
# - log
|
|
|
|
formsemestre: FormSemestre = group.partition.formsemestre
|
2023-07-08 13:57:44 +02:00
|
|
|
log(f"change_etud_group_in_partition: etudid={etudid} group={group}")
|
2023-07-05 19:15:33 +02:00
|
|
|
Scolog.logdb(
|
2021-09-02 18:05:22 +02:00
|
|
|
method="changeGroup",
|
|
|
|
etudid=etudid,
|
2023-07-05 19:15:33 +02:00
|
|
|
msg=f"""formsemestre_id={formsemestre.id}, partition_name={
|
|
|
|
group.partition.partition_name or ""}, group_name={group.group_name or ""}""",
|
|
|
|
commit=True,
|
2021-09-02 18:05:22 +02:00
|
|
|
)
|
2022-05-28 11:38:22 +02:00
|
|
|
|
2023-07-05 19:15:33 +02:00
|
|
|
# - Update parcours
|
|
|
|
if group.partition.partition_name == scu.PARTITION_PARCOURS:
|
2023-07-31 18:46:41 +02:00
|
|
|
formsemestre.update_inscriptions_parcours_from_groups(etudid=etudid)
|
2022-05-28 11:38:22 +02:00
|
|
|
|
2023-07-05 19:15:33 +02:00
|
|
|
# - invalidate cache
|
2021-07-19 19:53:01 +02:00
|
|
|
sco_cache.invalidate_formsemestre(
|
2023-07-05 19:15:33 +02:00
|
|
|
formsemestre_id=formsemestre.id
|
2021-06-21 11:22:55 +02:00
|
|
|
) # > change etud group
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def setGroups(
|
|
|
|
partition_id,
|
|
|
|
groupsLists="", # members of each existing group
|
|
|
|
groupsToCreate="", # name and members of new groups
|
|
|
|
groupsToDelete="", # groups to delete
|
|
|
|
):
|
2022-09-02 15:07:59 +02:00
|
|
|
"""Affect groups (Ajax POST request): renvoie du XML
|
2020-09-26 16:19:37 +02:00
|
|
|
groupsLists: lignes de la forme "group_id;etudid;...\n"
|
|
|
|
groupsToCreate: lignes "group_name;etudid;...\n"
|
|
|
|
groupsToDelete: group_id;group_id;...
|
2022-05-26 23:45:57 +02:00
|
|
|
|
|
|
|
Ne peux pas modifier les groupes des partitions non éditables.
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2021-06-21 10:17:16 +02:00
|
|
|
|
2022-05-26 23:45:57 +02:00
|
|
|
def xml_error(msg, code=404):
|
|
|
|
data = (
|
|
|
|
f'<?xml version="1.0" encoding="utf-8"?><response>Error: {msg}</response>'
|
|
|
|
)
|
|
|
|
response = make_response(data, code)
|
|
|
|
response.headers["Content-Type"] = scu.XML_MIMETYPE
|
|
|
|
return response
|
|
|
|
|
2023-07-11 06:57:38 +02:00
|
|
|
partition: Partition = db.session.get(Partition, partition_id)
|
2023-07-08 16:35:32 +02:00
|
|
|
if not partition.groups_editable and (groupsToCreate or groupsToDelete):
|
2022-05-26 23:45:57 +02:00
|
|
|
msg = "setGroups: partition non editable"
|
|
|
|
log(msg)
|
|
|
|
return xml_error(msg, code=403)
|
2023-07-08 16:35:32 +02:00
|
|
|
|
|
|
|
if not partition.formsemestre.etat:
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Modification impossible: semestre verrouillé")
|
2023-09-02 22:19:35 +02:00
|
|
|
if not partition.formsemestre.can_change_groups():
|
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
log(
|
|
|
|
f"""***setGroups: partition={partition}
|
|
|
|
groupsLists={groupsLists}
|
|
|
|
groupsToCreate={groupsToCreate}
|
|
|
|
groupsToDelete={groupsToDelete}
|
|
|
|
"""
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
groupsToDelete = [g for g in groupsToDelete.split(";") if g]
|
2023-07-08 16:35:32 +02:00
|
|
|
etud_groups = formsemestre_get_etud_groupnames(
|
|
|
|
partition.formsemestre.id, attr="group_id"
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
for line in groupsLists.split("\n"): # for each group_id (one per line)
|
|
|
|
fs = line.split(";")
|
|
|
|
group_id = fs[0].strip()
|
|
|
|
if not group_id:
|
|
|
|
continue
|
2022-01-21 00:46:45 +01:00
|
|
|
try:
|
|
|
|
group_id = int(group_id)
|
2022-05-26 23:45:57 +02:00
|
|
|
except ValueError:
|
|
|
|
log(f"setGroups: ignoring invalid group_id={group_id}")
|
2022-01-21 18:46:00 +01:00
|
|
|
continue
|
2024-10-29 19:18:36 +01:00
|
|
|
group: GroupDescr = GroupDescr.get_or_404(group_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
# Anciens membres du groupe:
|
2023-07-08 16:35:32 +02:00
|
|
|
old_members_set = {etud.id for etud in group.etuds}
|
2020-09-26 16:19:37 +02:00
|
|
|
# Place dans ce groupe les etudiants indiqués:
|
2021-08-11 00:36:07 +02:00
|
|
|
for etudid_str in fs[1:-1]:
|
|
|
|
etudid = int(etudid_str)
|
2020-09-26 16:19:37 +02:00
|
|
|
if etudid in old_members_set:
|
2023-07-08 16:35:32 +02:00
|
|
|
# était dans ce groupe, l'enlever
|
|
|
|
old_members_set.remove(etudid)
|
2020-09-26 16:19:37 +02:00
|
|
|
if (etudid not in etud_groups) or (
|
|
|
|
group_id != etud_groups[etudid].get(partition_id, "")
|
|
|
|
): # pas le meme groupe qu'actuel
|
2023-07-05 19:15:33 +02:00
|
|
|
change_etud_group_in_partition(etudid, group)
|
2020-09-26 16:19:37 +02:00
|
|
|
# Retire les anciens membres:
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-02-03 22:00:41 +01:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
2020-09-26 16:19:37 +02:00
|
|
|
for etudid in old_members_set:
|
2021-02-03 22:00:41 +01:00
|
|
|
ndb.SimpleQuery(
|
2020-09-26 16:19:37 +02:00
|
|
|
"DELETE FROM group_membership WHERE etudid=%(etudid)s and group_id=%(group_id)s",
|
|
|
|
{"etudid": etudid, "group_id": group_id},
|
|
|
|
cursor=cursor,
|
|
|
|
)
|
2024-07-08 23:13:45 +02:00
|
|
|
Scolog.logdb(
|
2020-09-26 16:19:37 +02:00
|
|
|
method="removeFromGroup",
|
|
|
|
etudid=etudid,
|
2023-07-08 16:35:32 +02:00
|
|
|
msg=f"""formsemestre_id={partition.formsemestre.id},partition_name={
|
|
|
|
partition.partition_name}, group_name={group.group_name}""",
|
2024-07-08 23:13:45 +02:00
|
|
|
commit=True,
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Supprime les groupes indiqués comme supprimés:
|
|
|
|
for group_id in groupsToDelete:
|
2021-10-12 16:05:50 +02:00
|
|
|
delete_group(group_id, partition_id=partition_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Crée les nouveaux groupes
|
|
|
|
for line in groupsToCreate.split("\n"): # for each group_name (one per line)
|
|
|
|
fs = line.split(";")
|
|
|
|
group_name = fs[0].strip()
|
|
|
|
if not group_name:
|
|
|
|
continue
|
2022-09-02 15:07:59 +02:00
|
|
|
try:
|
|
|
|
group = create_group(partition_id, group_name)
|
|
|
|
except ScoValueError as exc:
|
|
|
|
msg = exc.args[0] if len(exc.args) > 0 else "erreur inconnue"
|
|
|
|
return xml_error(msg, code=404)
|
2020-09-26 16:19:37 +02:00
|
|
|
# Place dans ce groupe les etudiants indiqués:
|
|
|
|
for etudid in fs[1:-1]:
|
2023-07-13 20:13:15 +02:00
|
|
|
change_etud_group_in_partition(etudid, group)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-05-28 11:38:22 +02:00
|
|
|
# Update parcours
|
2023-07-08 16:35:32 +02:00
|
|
|
partition.formsemestre.update_inscriptions_parcours_from_groups()
|
2022-05-28 11:38:22 +02:00
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
data = (
|
2020-09-26 16:19:37 +02:00
|
|
|
'<?xml version="1.0" encoding="utf-8"?><response>Groupes enregistrés</response>'
|
|
|
|
)
|
2021-09-27 10:20:10 +02:00
|
|
|
response = make_response(data)
|
|
|
|
response.headers["Content-Type"] = scu.XML_MIMETYPE
|
|
|
|
return response
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2022-09-02 15:07:59 +02:00
|
|
|
def create_group(partition_id, group_name="", default=False) -> GroupDescr:
|
2022-09-03 10:07:34 +02:00
|
|
|
"""Create a new group in this partition.
|
|
|
|
If default, create default partition (with no name)
|
2023-07-08 16:35:32 +02:00
|
|
|
Obsolete: utiliser Partition.create_group
|
2022-09-03 10:07:34 +02:00
|
|
|
"""
|
2024-10-29 19:18:36 +01:00
|
|
|
partition = Partition.get_or_404(partition_id)
|
2023-09-02 22:19:35 +02:00
|
|
|
if not partition.formsemestre.can_change_groups():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
#
|
|
|
|
if group_name:
|
|
|
|
group_name = group_name.strip()
|
|
|
|
if not group_name and not default:
|
|
|
|
raise ValueError("invalid group name: ()")
|
2022-09-02 15:07:59 +02:00
|
|
|
|
2022-09-03 10:07:34 +02:00
|
|
|
if not GroupDescr.check_name(partition, group_name, default=default):
|
2022-09-02 15:07:59 +02:00
|
|
|
raise ScoValueError(f"Le groupe {group_name} existe déjà dans cette partition")
|
|
|
|
|
2022-09-03 08:42:41 +02:00
|
|
|
numeros = [g.numero if g.numero is not None else 0 for g in partition.groups]
|
|
|
|
if len(numeros) > 0:
|
|
|
|
new_numero = max(numeros) + 1
|
|
|
|
else:
|
|
|
|
new_numero = 0
|
2022-09-02 15:07:59 +02:00
|
|
|
group = GroupDescr(partition=partition, group_name=group_name, numero=new_numero)
|
|
|
|
db.session.add(group)
|
|
|
|
db.session.commit()
|
2023-07-08 16:35:32 +02:00
|
|
|
log(f"create_group: created group_id={group.id}")
|
2020-09-26 16:19:37 +02:00
|
|
|
#
|
2022-09-02 15:07:59 +02:00
|
|
|
return group
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-10-12 16:05:50 +02:00
|
|
|
def delete_group(group_id, partition_id=None):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""form suppression d'un groupe.
|
|
|
|
(ne desinscrit pas les etudiants, change juste leur
|
|
|
|
affectation aux groupes)
|
|
|
|
partition_id est optionnel et ne sert que pour verifier que le groupe
|
|
|
|
est bien dans cette partition.
|
2022-05-28 11:38:22 +02:00
|
|
|
S'il s'agit d'un groupe de parcours, affecte l'inscription des étudiants aux parcours.
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2024-10-29 19:18:36 +01:00
|
|
|
group = GroupDescr.get_or_404(group_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
if partition_id:
|
2022-05-28 11:38:22 +02:00
|
|
|
if partition_id != group.partition_id:
|
2020-09-26 16:19:37 +02:00
|
|
|
raise ValueError("inconsistent partition/group")
|
2023-09-02 22:19:35 +02:00
|
|
|
if not group.partition.formsemestre.can_change_groups():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
2022-06-27 19:49:29 +02:00
|
|
|
log(f"delete_group: group={group} partition={group.partition}")
|
2022-05-28 11:38:22 +02:00
|
|
|
formsemestre = group.partition.formsemestre
|
|
|
|
group_delete(group.id)
|
|
|
|
formsemestre.update_inscriptions_parcours_from_groups()
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def partition_create(
|
|
|
|
formsemestre_id,
|
|
|
|
partition_name="",
|
|
|
|
default=False,
|
|
|
|
numero=None,
|
2021-08-15 21:33:47 +02:00
|
|
|
redirect=True,
|
2020-09-26 16:19:37 +02:00
|
|
|
):
|
|
|
|
"""Create a new partition"""
|
2023-09-02 22:19:35 +02:00
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
if not formsemestre.can_change_groups():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
if partition_name:
|
2021-10-15 14:31:11 +02:00
|
|
|
partition_name = str(partition_name).strip()
|
2020-09-26 16:19:37 +02:00
|
|
|
if default:
|
|
|
|
partition_name = None
|
|
|
|
if not partition_name and not default:
|
|
|
|
raise ScoValueError("Nom de partition invalide (vide)")
|
|
|
|
redirect = int(redirect)
|
|
|
|
# checkGroupName(partition_name)
|
|
|
|
if partition_name in [
|
2021-08-19 10:28:35 +02:00
|
|
|
p["partition_name"] for p in get_partitions_list(formsemestre_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
]:
|
|
|
|
raise ScoValueError(
|
|
|
|
"Il existe déjà une partition %s dans ce semestre" % partition_name
|
|
|
|
)
|
|
|
|
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-10-20 17:41:38 +02:00
|
|
|
if numero is None:
|
|
|
|
numero = (
|
|
|
|
ndb.SimpleQuery(
|
|
|
|
"SELECT MAX(id) FROM partition WHERE formsemestre_id=%(formsemestre_id)s",
|
|
|
|
{"formsemestre_id": formsemestre_id},
|
|
|
|
).fetchone()[0]
|
|
|
|
or 0
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
partition_id = partitionEditor.create(
|
2021-10-20 17:41:38 +02:00
|
|
|
cnx,
|
|
|
|
{
|
|
|
|
"formsemestre_id": formsemestre_id,
|
|
|
|
"partition_name": partition_name,
|
|
|
|
"numero": numero,
|
|
|
|
},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
log("createPartition: created partition_id=%s" % partition_id)
|
|
|
|
#
|
|
|
|
if redirect:
|
2021-07-29 16:31:15 +02:00
|
|
|
return flask.redirect(
|
|
|
|
url_for(
|
2022-05-22 05:01:25 +02:00
|
|
|
"scolar.edit_partition_form",
|
2021-07-29 16:31:15 +02:00
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
formsemestre_id=formsemestre_id,
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
return partition_id
|
|
|
|
|
|
|
|
|
2021-10-12 16:05:50 +02:00
|
|
|
def get_arrow_icons_tags():
|
2020-09-26 16:19:37 +02:00
|
|
|
"""returns html tags for arrows"""
|
|
|
|
#
|
2021-02-04 20:02:44 +01:00
|
|
|
arrow_up = scu.icontag("arrow_up", title="remonter")
|
|
|
|
arrow_down = scu.icontag("arrow_down", title="descendre")
|
|
|
|
arrow_none = scu.icontag("arrow_none", title="")
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
return arrow_up, arrow_down, arrow_none
|
|
|
|
|
|
|
|
|
2022-05-22 05:01:25 +02:00
|
|
|
def edit_partition_form(formsemestre_id=None):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Form to create/suppress partitions"""
|
|
|
|
# ad-hoc form
|
2023-03-20 11:17:38 +01:00
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
2023-09-02 22:19:35 +02:00
|
|
|
if not formsemestre.can_change_groups():
|
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
partitions = get_partitions_list(formsemestre_id)
|
2024-08-24 18:26:51 +02:00
|
|
|
arrow_up, arrow_down, _ = get_arrow_icons_tags()
|
2021-02-04 20:02:44 +01:00
|
|
|
suppricon = scu.icontag(
|
2020-09-26 16:19:37 +02:00
|
|
|
"delete_small_img", border="0", alt="supprimer", title="Supprimer"
|
|
|
|
)
|
|
|
|
#
|
|
|
|
H = [
|
2021-12-29 19:30:49 +01:00
|
|
|
# limite à SHORT_STR_LEN
|
2021-01-17 22:31:28 +01:00
|
|
|
r"""<script type="text/javascript">
|
2020-09-26 16:19:37 +02:00
|
|
|
function checkname() {
|
|
|
|
var val = document.editpart.partition_name.value.replace(/^\s+/, "").replace(/\s+$/, "");
|
2021-12-29 19:30:49 +01:00
|
|
|
if ((val.length > 0)&&(val.length < 32)) {
|
2020-09-26 16:19:37 +02:00
|
|
|
document.editpart.ok.disabled = false;
|
|
|
|
} else {
|
|
|
|
document.editpart.ok.disabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
""",
|
2023-07-14 07:16:33 +02:00
|
|
|
f"""<h2>Partitions du semestre</h2>
|
|
|
|
<p class="help">
|
|
|
|
👉💡 vous pourriez essayer <a href="{
|
|
|
|
url_for("scolar.partition_editor",
|
|
|
|
scodoc_dept=g.scodoc_dept, formsemestre_id=formsemestre_id)
|
|
|
|
}" class="stdlink">le nouvel éditeur</a>
|
|
|
|
</p>
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
<form name="editpart" id="editpart" method="POST" action="partition_create">
|
|
|
|
<div id="epmsg"></div>
|
2023-07-14 07:16:33 +02:00
|
|
|
<table>
|
|
|
|
<tr class="eptit">
|
|
|
|
<th></th><th></th><th></th><th>Partition</th><th>Groupes</th><th></th><th></th><th></th>
|
|
|
|
</tr>
|
2020-09-26 16:19:37 +02:00
|
|
|
""",
|
|
|
|
]
|
|
|
|
i = 0
|
|
|
|
for p in partitions:
|
|
|
|
if p["partition_name"] is not None:
|
|
|
|
H.append(
|
2023-11-06 22:05:38 +01:00
|
|
|
f"""<tr><td class="epnav"><a class="stdlink"
|
|
|
|
href="{url_for("scolar.partition_delete",
|
2022-08-03 21:42:53 +02:00
|
|
|
scodoc_dept=g.scodoc_dept, partition_id=p["partition_id"])
|
|
|
|
}">{suppricon}</a> </td><td class="epnav">"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
if i != 0:
|
|
|
|
H.append(
|
2022-08-03 21:42:53 +02:00
|
|
|
f"""<a href="{url_for("scolar.partition_move",
|
|
|
|
scodoc_dept=g.scodoc_dept, partition_id=p["partition_id"], after=0)
|
|
|
|
}">{arrow_up}</a>"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
H.append('</td><td class="epnav">')
|
|
|
|
if i < len(partitions) - 2:
|
|
|
|
H.append(
|
2022-08-03 21:42:53 +02:00
|
|
|
f"""<a href="{url_for("scolar.partition_move",
|
|
|
|
scodoc_dept=g.scodoc_dept, partition_id=p["partition_id"], after=1)
|
|
|
|
}">{arrow_down}</a>"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
i += 1
|
2022-08-03 21:42:53 +02:00
|
|
|
H.append(
|
|
|
|
f"""</td>
|
|
|
|
<td>{p["partition_name"] or ""}</td>
|
|
|
|
<td>"""
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
lg = [
|
2022-08-03 21:42:53 +02:00
|
|
|
f"""{group["group_name"]} ({len(get_group_members(group["group_id"]))})"""
|
2021-08-19 10:28:35 +02:00
|
|
|
for group in get_partition_groups(p)
|
2020-09-26 16:19:37 +02:00
|
|
|
]
|
|
|
|
H.append(", ".join(lg))
|
2022-05-26 23:45:57 +02:00
|
|
|
H.append("""</td><td>""")
|
2022-08-03 21:42:53 +02:00
|
|
|
H.append(
|
|
|
|
f"""<a class="stdlink" href="{
|
|
|
|
url_for("scolar.affect_groups",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
partition_id=p["partition_id"])
|
|
|
|
}">répartir</a></td>
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
H.append("""</td>""")
|
2022-05-26 23:45:57 +02:00
|
|
|
if p["groups_editable"]:
|
|
|
|
H.append(
|
2022-08-03 21:42:53 +02:00
|
|
|
f"""<td><a class="stdlink" href="{
|
|
|
|
url_for("scolar.partition_rename",
|
|
|
|
scodoc_dept=g.scodoc_dept, partition_id=p["partition_id"])
|
|
|
|
}">renommer</a></td>"""
|
2022-05-26 23:45:57 +02:00
|
|
|
)
|
|
|
|
else:
|
2022-08-03 21:42:53 +02:00
|
|
|
H.append("""<td>non éditable</td>""")
|
2020-09-26 16:19:37 +02:00
|
|
|
# classement:
|
|
|
|
H.append('<td width="250px">')
|
|
|
|
if p["bul_show_rank"]:
|
|
|
|
checked = 'checked="1"'
|
|
|
|
else:
|
|
|
|
checked = ""
|
|
|
|
H.append(
|
|
|
|
'<div><input type="checkbox" class="rkbox" data-partition_id="%s" %s onchange="update_rk(this);"/>afficher rang sur bulletins</div>'
|
|
|
|
% (p["partition_id"], checked)
|
|
|
|
)
|
|
|
|
if p["show_in_lists"]:
|
|
|
|
checked = 'checked="1"'
|
|
|
|
else:
|
|
|
|
checked = ""
|
|
|
|
H.append(
|
2022-08-31 09:16:00 +02:00
|
|
|
f"""<div><input type="checkbox" class="rkbox" data-partition_id="{p['partition_id']
|
|
|
|
}" {checked} onchange="update_show_in_list(this);"/>Afficher ces groupes sur les tableaux et bulletins</div>"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
H.append("</td>")
|
|
|
|
#
|
|
|
|
H.append("</tr>")
|
|
|
|
H.append("</table>")
|
|
|
|
H.append(
|
2022-05-22 05:01:25 +02:00
|
|
|
f"""<div class="form_rename_partition">
|
|
|
|
<input type="hidden" name="formsemestre_id" value="{formsemestre_id}"/>
|
|
|
|
<input type="hidden" name="redirect" value="1"/>
|
|
|
|
<input type="text" name="partition_name" size="12" onkeyup="checkname();"/>
|
|
|
|
<input type="submit" name="ok" disabled="1" value="Nouvelle partition"/>
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
2022-05-26 03:55:03 +02:00
|
|
|
if formsemestre.formation.is_apc() and scu.PARTITION_PARCOURS not in (
|
2022-05-22 05:01:25 +02:00
|
|
|
p["partition_name"] for p in partitions
|
|
|
|
):
|
|
|
|
# propose création partition "Parcours"
|
|
|
|
H.append(
|
|
|
|
f"""
|
|
|
|
<div style="margin-top: 10px"><a class="stdlink" href="{
|
2024-08-24 18:26:51 +02:00
|
|
|
url_for("scolar.create_partition_parcours",
|
|
|
|
scodoc_dept=g.scodoc_dept, formsemestre_id=formsemestre_id)
|
2022-05-22 05:01:25 +02:00
|
|
|
}">Créer une partition avec un groupe par parcours (BUT)</a>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
H.append(
|
2022-05-22 05:01:25 +02:00
|
|
|
"""
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
H.append(
|
|
|
|
"""<div class="help">
|
2022-05-22 05:01:25 +02:00
|
|
|
<p>Les partitions sont des découpages de l'ensemble des étudiants.
|
|
|
|
Par exemple, les "groupes de TD" sont une partition.
|
|
|
|
On peut créer autant de partitions que nécessaire.
|
2020-09-26 16:19:37 +02:00
|
|
|
</p>
|
|
|
|
<ul>
|
2022-05-22 05:01:25 +02:00
|
|
|
<li>Dans chaque partition, un nombre de groupes quelconque peuvent
|
|
|
|
être créés (suivre le lien "répartir").
|
|
|
|
<li>On peut faire afficher le classement de l'étudiant dans son
|
|
|
|
groupe d'une partition en cochant "afficher rang sur bulletins"
|
|
|
|
(ainsi, on peut afficher le classement en groupes de TD mais pas en
|
|
|
|
groupe de TP, si ce sont deux partitions).
|
|
|
|
</li>
|
2024-08-24 18:26:51 +02:00
|
|
|
<li>Décocher "Afficher ces groupes sur les tableaux et bulletins"
|
|
|
|
pour ne pas que cette partition apparaisse dans les noms de groupes
|
2020-09-26 16:19:37 +02:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
)
|
2024-08-24 18:26:51 +02:00
|
|
|
return render_template(
|
|
|
|
"sco_page.j2",
|
|
|
|
title="Partitions...",
|
|
|
|
javascripts=["js/edit_partition_form.js"],
|
|
|
|
content="\n".join(H),
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def partition_set_attr(partition_id, attr, value):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Set partition attribute: bul_show_rank or show_in_lists"""
|
|
|
|
if attr not in {"bul_show_rank", "show_in_lists"}:
|
2023-09-02 22:19:35 +02:00
|
|
|
raise ValueError(f"invalid partition attribute: {attr}")
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
partition = Partition.get_or_404(partition_id)
|
2023-09-02 22:19:35 +02:00
|
|
|
if not partition.formsemestre.can_change_groups():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
|
2023-09-02 22:19:35 +02:00
|
|
|
log(f"partition_set_attr({partition_id}, {attr}, {value})")
|
2020-09-26 16:19:37 +02:00
|
|
|
value = int(value)
|
2023-09-02 22:19:35 +02:00
|
|
|
if getattr(partition, attr, None) != value:
|
|
|
|
setattr(partition, attr, value)
|
|
|
|
db.session.add(partition)
|
|
|
|
db.session.commit()
|
|
|
|
# invalid bulletin cache
|
2023-09-03 19:23:00 +02:00
|
|
|
sco_cache.invalidate_formsemestre(formsemestre_id=partition.formsemestre.id)
|
2020-09-26 16:19:37 +02:00
|
|
|
return "enregistré"
|
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def partition_delete(partition_id, force=False, redirect=1, dialog_confirmed=False):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Suppress a partition (and all groups within).
|
2022-05-28 11:38:22 +02:00
|
|
|
The default partition cannot be suppressed (unless force).
|
|
|
|
Si la partition de parcours est supprimée, les étudiants sont désinscrits des parcours.
|
|
|
|
"""
|
2021-08-19 10:28:35 +02:00
|
|
|
partition = get_partition(partition_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
formsemestre_id = partition["formsemestre_id"]
|
2023-03-20 11:17:38 +01:00
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
2023-09-02 22:19:35 +02:00
|
|
|
if not formsemestre.can_change_groups():
|
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
if not partition["partition_name"] and not force:
|
|
|
|
raise ValueError("cannot suppress this partition")
|
|
|
|
redirect = int(redirect)
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-08-19 10:28:35 +02:00
|
|
|
groups = get_partition_groups(partition)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
if not dialog_confirmed:
|
|
|
|
if groups:
|
|
|
|
grnames = "(" + ", ".join([g["group_name"] or "" for g in groups]) + ")"
|
|
|
|
else:
|
|
|
|
grnames = ""
|
2021-06-02 22:40:34 +02:00
|
|
|
return scu.confirm_dialog(
|
2020-09-26 16:19:37 +02:00
|
|
|
"""<h2>Supprimer la partition "%s" ?</h2>
|
|
|
|
<p>Les groupes %s de cette partition seront supprimés</p>
|
|
|
|
"""
|
|
|
|
% (partition["partition_name"], grnames),
|
|
|
|
dest_url="",
|
2022-05-22 05:01:25 +02:00
|
|
|
cancel_url="edit_partition_form?formsemestre_id=%s" % formsemestre_id,
|
2020-09-26 16:19:37 +02:00
|
|
|
parameters={"redirect": redirect, "partition_id": partition_id},
|
|
|
|
)
|
|
|
|
|
|
|
|
log("partition_delete: partition_id=%s" % partition_id)
|
|
|
|
# 1- groups
|
|
|
|
for group in groups:
|
2022-05-28 11:38:22 +02:00
|
|
|
group_delete(group["group_id"])
|
2020-09-26 16:19:37 +02:00
|
|
|
# 2- partition
|
|
|
|
partitionEditor.delete(cnx, partition_id)
|
|
|
|
|
2022-05-28 11:38:22 +02:00
|
|
|
formsemestre.update_inscriptions_parcours_from_groups()
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
# redirect to partition edit page:
|
|
|
|
if redirect:
|
2021-08-10 17:12:10 +02:00
|
|
|
return flask.redirect(
|
2022-05-22 05:01:25 +02:00
|
|
|
"edit_partition_form?formsemestre_id=" + str(formsemestre_id)
|
2021-08-10 17:12:10 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def partition_move(partition_id, after=0, redirect=1):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Move before/after previous one (decrement/increment numero)"""
|
2021-08-19 10:28:35 +02:00
|
|
|
partition = get_partition(partition_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
formsemestre_id = partition["formsemestre_id"]
|
2023-09-02 22:19:35 +02:00
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
if not formsemestre.can_change_groups():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
#
|
|
|
|
redirect = int(redirect)
|
|
|
|
after = int(after) # 0: deplace avant, 1 deplace apres
|
|
|
|
if after not in (0, 1):
|
|
|
|
raise ValueError('invalid value for "after"')
|
2021-08-19 10:28:35 +02:00
|
|
|
others = get_partitions_list(formsemestre_id)
|
2021-12-16 21:42:23 +01:00
|
|
|
|
|
|
|
objs = (
|
|
|
|
Partition.query.filter_by(formsemestre_id=formsemestre_id)
|
|
|
|
.order_by(Partition.numero, Partition.partition_name)
|
|
|
|
.all()
|
|
|
|
)
|
|
|
|
if len({o.numero for o in objs}) != len(objs):
|
|
|
|
# il y a des numeros identiques !
|
2021-12-17 13:42:39 +01:00
|
|
|
scu.objects_renumber(db, objs)
|
2021-12-16 21:42:23 +01:00
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
if len(others) > 1:
|
|
|
|
pidx = [p["partition_id"] for p in others].index(partition_id)
|
2021-10-20 17:41:38 +02:00
|
|
|
# log("partition_move: after=%s pidx=%s" % (after, pidx))
|
2020-09-26 16:19:37 +02:00
|
|
|
neigh = None # partition to swap with
|
|
|
|
if after == 0 and pidx > 0:
|
|
|
|
neigh = others[pidx - 1]
|
|
|
|
elif after == 1 and pidx < len(others) - 1:
|
|
|
|
neigh = others[pidx + 1]
|
|
|
|
if neigh: #
|
|
|
|
# swap numero between partition and its neighbor
|
2021-10-20 17:41:38 +02:00
|
|
|
# log("moving partition %s" % partition_id)
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-10-20 17:41:38 +02:00
|
|
|
# Si aucun numéro n'a été affecté, le met au minimum
|
|
|
|
min_numero = (
|
|
|
|
ndb.SimpleQuery(
|
|
|
|
"SELECT MIN(numero) FROM partition WHERE formsemestre_id=%(formsemestre_id)s",
|
|
|
|
{"formsemestre_id": formsemestre_id},
|
|
|
|
).fetchone()[0]
|
|
|
|
or 0
|
|
|
|
)
|
|
|
|
if neigh["numero"] is None:
|
|
|
|
neigh["numero"] = min_numero - 1
|
|
|
|
if partition["numero"] is None:
|
|
|
|
partition["numero"] = min_numero - 1 - after
|
2020-09-26 16:19:37 +02:00
|
|
|
partition["numero"], neigh["numero"] = neigh["numero"], partition["numero"]
|
|
|
|
partitionEditor.edit(cnx, partition)
|
|
|
|
partitionEditor.edit(cnx, neigh)
|
2023-02-02 18:27:15 +01:00
|
|
|
sco_cache.invalidate_formsemestre(formsemestre_id=formsemestre_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# redirect to partition edit page:
|
|
|
|
if redirect:
|
2021-08-10 17:12:10 +02:00
|
|
|
return flask.redirect(
|
2022-05-22 05:01:25 +02:00
|
|
|
"edit_partition_form?formsemestre_id=" + str(formsemestre_id)
|
2021-08-10 17:12:10 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def partition_rename(partition_id):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Form to rename a partition"""
|
2021-08-19 10:28:35 +02:00
|
|
|
partition = get_partition(partition_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
formsemestre_id = partition["formsemestre_id"]
|
2023-09-02 22:19:35 +02:00
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
if not formsemestre.can_change_groups():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
H = ["<h2>Renommer une partition</h2>"]
|
|
|
|
tf = TrivialFormulator(
|
2021-09-18 10:10:02 +02:00
|
|
|
request.base_url,
|
2021-09-27 16:42:14 +02:00
|
|
|
scu.get_request_args(),
|
2020-09-26 16:19:37 +02:00
|
|
|
(
|
|
|
|
("partition_id", {"default": partition_id, "input_type": "hidden"}),
|
|
|
|
(
|
|
|
|
"partition_name",
|
|
|
|
{
|
|
|
|
"title": "Nouveau nom",
|
|
|
|
"default": partition["partition_name"],
|
|
|
|
"allow_null": False,
|
|
|
|
"size": 12,
|
2022-05-28 11:38:22 +02:00
|
|
|
"validator": lambda val, _: (len(val) < SHORT_STR_LEN)
|
|
|
|
and (val != scu.PARTITION_PARCOURS),
|
2020-09-26 16:19:37 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
submitlabel="Renommer",
|
|
|
|
cancelbutton="Annuler",
|
|
|
|
)
|
|
|
|
if tf[0] == 0:
|
2024-08-24 18:26:51 +02:00
|
|
|
return render_template(
|
|
|
|
"sco_page.j2",
|
|
|
|
title="Renommer une partition",
|
|
|
|
content=("\n".join(H) + "\n" + tf[1]),
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
elif tf[0] == -1:
|
2021-08-10 17:12:10 +02:00
|
|
|
return flask.redirect(
|
2022-05-22 05:01:25 +02:00
|
|
|
"edit_partition_form?formsemestre_id=" + str(formsemestre_id)
|
2021-08-10 17:12:10 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
|
|
|
# form submission
|
2021-09-27 10:20:10 +02:00
|
|
|
return partition_set_name(partition_id, tf[2]["partition_name"])
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def partition_set_name(partition_id, partition_name, redirect=1):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Set partition name"""
|
2021-10-15 14:31:11 +02:00
|
|
|
partition_name = str(partition_name).strip()
|
2020-09-26 16:19:37 +02:00
|
|
|
if not partition_name:
|
|
|
|
raise ValueError("partition name must be non empty")
|
2021-08-19 10:28:35 +02:00
|
|
|
partition = get_partition(partition_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
if partition["partition_name"] is None:
|
|
|
|
raise ValueError("can't set a name to default partition")
|
2022-05-28 11:38:22 +02:00
|
|
|
if partition_name == scu.PARTITION_PARCOURS:
|
|
|
|
raise ScoValueError(f"nom de partition {scu.PARTITION_PARCOURS} réservé.")
|
2020-09-26 16:19:37 +02:00
|
|
|
formsemestre_id = partition["formsemestre_id"]
|
2023-09-02 22:19:35 +02:00
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
if not formsemestre.can_change_groups():
|
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
2020-09-26 16:19:37 +02:00
|
|
|
# check unicity
|
2021-02-03 22:00:41 +01:00
|
|
|
r = ndb.SimpleDictFetch(
|
2021-10-24 18:28:01 +02:00
|
|
|
"""SELECT p.* FROM partition p
|
|
|
|
WHERE p.partition_name = %(partition_name)s
|
2021-08-08 17:38:46 +02:00
|
|
|
AND formsemestre_id = %(formsemestre_id)s
|
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"partition_name": partition_name, "formsemestre_id": formsemestre_id},
|
|
|
|
)
|
2021-10-24 18:28:01 +02:00
|
|
|
if len(r) > 1 or (len(r) == 1 and r[0]["id"] != partition_id):
|
2020-09-26 16:19:37 +02:00
|
|
|
raise ScoValueError(
|
2023-02-02 18:27:15 +01:00
|
|
|
f"Partition {partition_name} déjà existante dans ce semestre !"
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
redirect = int(redirect)
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2020-09-26 16:19:37 +02:00
|
|
|
partitionEditor.edit(
|
|
|
|
cnx, {"partition_id": partition_id, "partition_name": partition_name}
|
|
|
|
)
|
2023-02-02 18:27:15 +01:00
|
|
|
sco_cache.invalidate_formsemestre(formsemestre_id=formsemestre_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# redirect to partition edit page:
|
|
|
|
if redirect:
|
2021-08-10 17:12:10 +02:00
|
|
|
return flask.redirect(
|
2022-05-22 05:01:25 +02:00
|
|
|
"edit_partition_form?formsemestre_id=" + str(formsemestre_id)
|
2021-08-10 17:12:10 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2023-09-06 08:48:00 +02:00
|
|
|
def groups_auto_repartition(partition: Partition):
|
|
|
|
"""Réparti les etudiants dans des groupes dans une partition, en respectant le niveau
|
2020-09-26 16:19:37 +02:00
|
|
|
et la mixité.
|
|
|
|
"""
|
2024-08-24 18:26:51 +02:00
|
|
|
from app.views import ScoData
|
|
|
|
|
2023-07-08 16:35:32 +02:00
|
|
|
if not partition.groups_editable:
|
2022-05-26 23:45:57 +02:00
|
|
|
raise AccessDenied("Partition non éditable")
|
2023-07-08 16:35:32 +02:00
|
|
|
formsemestre = partition.formsemestre
|
2023-07-14 07:16:33 +02:00
|
|
|
# renvoie sur page édition partitions et groupes
|
2021-08-16 08:33:12 +02:00
|
|
|
dest_url = url_for(
|
2023-07-14 07:16:33 +02:00
|
|
|
"scolar.partition_editor",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
2023-09-06 08:48:00 +02:00
|
|
|
formsemestre_id=formsemestre.id,
|
2021-08-16 08:33:12 +02:00
|
|
|
)
|
2023-09-02 22:19:35 +02:00
|
|
|
if not formsemestre.can_change_groups():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
|
|
|
|
descr = [
|
|
|
|
("partition_id", {"input_type": "hidden"}),
|
|
|
|
(
|
|
|
|
"groupNames",
|
|
|
|
{
|
|
|
|
"size": 40,
|
|
|
|
"title": "Groupes à créer",
|
|
|
|
"allow_null": False,
|
|
|
|
"explanation": "noms des groupes à former, séparés par des virgules (les groupes existants seront effacés)",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
tf = TrivialFormulator(
|
2021-09-18 10:10:02 +02:00
|
|
|
request.base_url,
|
2021-09-27 16:42:14 +02:00
|
|
|
scu.get_request_args(),
|
2020-09-26 16:19:37 +02:00
|
|
|
descr,
|
|
|
|
{},
|
|
|
|
cancelbutton="Annuler",
|
|
|
|
submitlabel="Créer et peupler les groupes",
|
|
|
|
name="tf",
|
|
|
|
)
|
|
|
|
if tf[0] == 0:
|
2024-08-24 18:26:51 +02:00
|
|
|
return render_template(
|
2024-08-26 14:46:28 +02:00
|
|
|
"formsemestre/groups_auto_repartition.j2",
|
|
|
|
title="Répartition dans des groupes",
|
|
|
|
form_html=tf[1],
|
|
|
|
partition=partition,
|
2024-08-24 18:26:51 +02:00
|
|
|
sco=ScoData(formsemestre=formsemestre),
|
|
|
|
)
|
2024-08-26 14:46:28 +02:00
|
|
|
if tf[0] == -1:
|
2021-07-31 18:01:10 +02:00
|
|
|
return flask.redirect(dest_url)
|
2024-08-26 14:46:28 +02:00
|
|
|
|
|
|
|
# form submission
|
|
|
|
log(f"groups_auto_repartition({partition})")
|
|
|
|
group_names = tf[2]["groupNames"]
|
|
|
|
group_names = sorted({x.strip() for x in group_names.split(",")})
|
|
|
|
# Détruit les groupes existant de cette partition
|
|
|
|
for group in partition.groups:
|
|
|
|
db.session.delete(group)
|
|
|
|
db.session.commit()
|
|
|
|
# Crée les nouveaux groupes
|
|
|
|
groups = []
|
|
|
|
for group_name in group_names:
|
|
|
|
if group_name.strip():
|
|
|
|
groups.append(partition.create_group(group_name))
|
|
|
|
#
|
|
|
|
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
|
|
|
identdict = nt.identdict
|
|
|
|
# build: { civilite : liste etudids trie par niveau croissant }
|
|
|
|
civilites = {x["civilite"] for x in identdict.values()}
|
|
|
|
listes = {}
|
|
|
|
for civilite in civilites:
|
|
|
|
listes[civilite] = [
|
|
|
|
(_get_prev_moy(x["etudid"], formsemestre.id), x["etudid"])
|
|
|
|
for x in identdict.values()
|
|
|
|
if x["civilite"] == civilite
|
|
|
|
]
|
|
|
|
listes[civilite].sort()
|
|
|
|
log("listes[%s] = %s" % (civilite, listes[civilite]))
|
|
|
|
# affect aux groupes:
|
|
|
|
n = len(identdict)
|
|
|
|
igroup = 0
|
|
|
|
nbgroups = len(groups)
|
|
|
|
while n > 0:
|
|
|
|
log(f"n={n}")
|
2021-02-13 17:28:55 +01:00
|
|
|
for civilite in civilites:
|
2024-08-26 14:46:28 +02:00
|
|
|
log(f"civilite={civilite}")
|
|
|
|
if len(listes[civilite]):
|
|
|
|
n -= 1
|
|
|
|
etudid = listes[civilite].pop()[1]
|
|
|
|
group = groups[igroup]
|
|
|
|
igroup = (igroup + 1) % nbgroups
|
|
|
|
log(f"in {etudid} in group {group.id}")
|
|
|
|
change_etud_group_in_partition(etudid, group)
|
|
|
|
log(f"{etudid} in group {group.id}")
|
|
|
|
return flask.redirect(dest_url)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2024-06-07 17:58:02 +02:00
|
|
|
def _get_prev_moy(etudid: int, formsemestre_id: int) -> float | str:
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Donne la derniere moyenne generale calculee pour cette étudiant,
|
|
|
|
ou 0 si on n'en trouve pas (nouvel inscrit,...).
|
|
|
|
"""
|
2024-06-07 17:58:02 +02:00
|
|
|
etud = Identite.get_etud(etudid)
|
2022-07-07 16:24:52 +02:00
|
|
|
Se = sco_cursus.get_situation_etud_cursus(etud, formsemestre_id)
|
2024-06-07 17:58:02 +02:00
|
|
|
if Se.prev_formsemestre:
|
|
|
|
prev_sem = db.session.get(FormSemestre, Se.prev_formsemestre.id)
|
2022-02-10 22:35:55 +01:00
|
|
|
nt: NotesTableCompat = res_sem.load_formsemestre_results(prev_sem)
|
2024-06-07 17:58:02 +02:00
|
|
|
return nt.get_etud_moy_gen(etud.id)
|
|
|
|
return 0.0
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def create_etapes_partition(formsemestre_id, partition_name="apo_etapes"):
|
2020-12-01 16:46:45 +01:00
|
|
|
"""Crée une partition "apo_etapes" avec un groupe par étape Apogée.
|
|
|
|
Cette partition n'est crée que si plusieurs étapes différentes existent dans ce
|
|
|
|
semestre.
|
|
|
|
Si la partition existe déjà, ses groupes sont mis à jour (les groupes devenant
|
|
|
|
vides ne sont pas supprimés).
|
|
|
|
"""
|
2023-07-05 19:15:33 +02:00
|
|
|
# A RE-ECRIRE pour utiliser les modèles.
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_formsemestre_inscriptions
|
|
|
|
|
2021-10-15 14:31:11 +02:00
|
|
|
partition_name = str(partition_name)
|
2023-07-05 19:15:33 +02:00
|
|
|
log(f"create_etapes_partition({formsemestre_id})")
|
2021-06-19 23:21:37 +02:00
|
|
|
ins = sco_formsemestre_inscriptions.do_formsemestre_inscription_list(
|
2021-08-19 10:28:35 +02:00
|
|
|
args={"formsemestre_id": formsemestre_id}
|
2020-12-01 16:46:45 +01:00
|
|
|
)
|
|
|
|
etapes = {i["etape"] for i in ins if i["etape"]}
|
2021-08-19 10:28:35 +02:00
|
|
|
partitions = get_partitions_list(formsemestre_id, with_default=False)
|
2020-12-01 16:46:45 +01:00
|
|
|
partition = None
|
|
|
|
for p in partitions:
|
|
|
|
if p["partition_name"] == partition_name:
|
|
|
|
partition = p
|
|
|
|
break
|
|
|
|
if len(etapes) < 2 and not partition:
|
|
|
|
return # moins de deux étapes, pas de création
|
|
|
|
if partition:
|
|
|
|
pid = partition["partition_id"]
|
|
|
|
else:
|
|
|
|
pid = partition_create(
|
2021-08-19 10:28:35 +02:00
|
|
|
formsemestre_id, partition_name=partition_name, redirect=False
|
2020-12-01 16:46:45 +01:00
|
|
|
)
|
2023-07-11 06:57:38 +02:00
|
|
|
partition: Partition = db.session.get(Partition, pid)
|
2023-07-05 19:15:33 +02:00
|
|
|
groups = partition.groups
|
2023-07-12 14:06:34 +02:00
|
|
|
groups_by_names = {g.group_name: g for g in groups}
|
2020-12-01 16:46:45 +01:00
|
|
|
for etape in etapes:
|
2023-07-05 19:15:33 +02:00
|
|
|
if etape not in groups_by_names:
|
2022-09-02 15:07:59 +02:00
|
|
|
new_group = create_group(pid, etape)
|
2023-07-05 19:15:33 +02:00
|
|
|
groups_by_names[etape] = new_group
|
2020-12-01 16:46:45 +01:00
|
|
|
# Place les etudiants dans les groupes
|
|
|
|
for i in ins:
|
|
|
|
if i["etape"]:
|
2023-07-05 19:15:33 +02:00
|
|
|
change_etud_group_in_partition(i["etudid"], groups_by_names[i["etape"]])
|
2020-12-01 16:46:45 +01:00
|
|
|
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
def do_evaluation_listeetuds_groups(
|
2023-01-24 13:22:31 +01:00
|
|
|
evaluation_id: int,
|
|
|
|
groups=None,
|
|
|
|
getallstudents: bool = False,
|
|
|
|
include_demdef: bool = False,
|
|
|
|
) -> list[tuple[int, str]]:
|
|
|
|
"""Donne la liste non triée des etudids inscrits à cette évaluation dans les
|
2024-06-30 23:00:42 +02:00
|
|
|
groupes indiqués (donc inscrits au modimpl ET au formsemestre).
|
2023-01-24 13:22:31 +01:00
|
|
|
Si getallstudents==True, donne tous les étudiants inscrits à cette
|
2020-09-26 16:19:37 +02:00
|
|
|
evaluation.
|
2022-01-16 23:47:52 +01:00
|
|
|
Si include_demdef, compte aussi les etudiants démissionnaires et défaillants
|
2020-09-26 16:19:37 +02:00
|
|
|
(sinon, par défaut, seulement les 'I')
|
2021-11-20 17:21:51 +01:00
|
|
|
|
|
|
|
Résultat: [ (etudid, etat) ], où etat='I', 'D', 'DEF'
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2022-01-16 23:47:52 +01:00
|
|
|
# nb: pour notes_table / do_evaluation_etat, getallstudents est vrai et
|
|
|
|
# include_demdef faux
|
2020-09-26 16:19:37 +02:00
|
|
|
fromtables = [
|
|
|
|
"notes_moduleimpl_inscription Im",
|
|
|
|
"notes_formsemestre_inscription Isem",
|
|
|
|
"notes_moduleimpl M",
|
|
|
|
"notes_evaluation E",
|
|
|
|
]
|
|
|
|
# construit condition sur les groupes
|
|
|
|
if not getallstudents:
|
|
|
|
if not groups:
|
|
|
|
return [] # no groups, so no students
|
|
|
|
rg = ["gm.group_id = '%(group_id)s'" % g for g in groups]
|
2021-10-15 14:00:51 +02:00
|
|
|
rq = """and Isem.etudid = gm.etudid
|
2023-11-06 22:05:38 +01:00
|
|
|
and gd.partition_id = p.id
|
2021-08-11 14:00:39 +02:00
|
|
|
and p.formsemestre_id = Isem.formsemestre_id
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
r = rq + " AND (" + " or ".join(rg) + " )"
|
|
|
|
fromtables += ["group_membership gm", "group_descr gd", "partition p"]
|
|
|
|
else:
|
|
|
|
r = ""
|
|
|
|
|
|
|
|
# requete complete
|
|
|
|
req = (
|
2021-11-20 17:21:51 +01:00
|
|
|
"SELECT distinct Im.etudid, Isem.etat FROM "
|
2020-09-26 16:19:37 +02:00
|
|
|
+ ", ".join(fromtables)
|
2021-10-15 14:00:51 +02:00
|
|
|
+ """ WHERE Isem.etudid = Im.etudid
|
2023-11-06 22:05:38 +01:00
|
|
|
and Im.moduleimpl_id = M.id
|
|
|
|
and Isem.formsemestre_id = M.formsemestre_id
|
|
|
|
and E.moduleimpl_id = M.id
|
2021-08-10 12:57:38 +02:00
|
|
|
and E.id = %(evaluation_id)s
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
2022-01-16 23:47:52 +01:00
|
|
|
if not include_demdef:
|
2020-09-26 16:19:37 +02:00
|
|
|
req += " and Isem.etat='I'"
|
|
|
|
req += r
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-10-15 14:00:51 +02:00
|
|
|
cursor = cnx.cursor()
|
2020-09-26 16:19:37 +02:00
|
|
|
cursor.execute(req, {"evaluation_id": evaluation_id})
|
2021-11-20 17:21:51 +01:00
|
|
|
return cursor.fetchall()
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def do_evaluation_listegroupes(evaluation_id, include_default=False):
|
2020-12-01 16:46:45 +01:00
|
|
|
"""Donne la liste des groupes dans lesquels figurent des etudiants inscrits
|
2020-09-26 16:19:37 +02:00
|
|
|
au module/semestre auquel appartient cette evaluation.
|
|
|
|
Si include_default, inclue aussi le groupe par defaut ('tous')
|
|
|
|
[ group ]
|
|
|
|
"""
|
|
|
|
if include_default:
|
|
|
|
c = ""
|
|
|
|
else:
|
|
|
|
c = " AND p.partition_name is not NULL"
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-10-15 14:00:51 +02:00
|
|
|
cursor = cnx.cursor()
|
2020-09-26 16:19:37 +02:00
|
|
|
cursor.execute(
|
2021-08-11 14:00:39 +02:00
|
|
|
"""SELECT DISTINCT gd.id AS group_id
|
2023-11-06 22:05:38 +01:00
|
|
|
FROM group_descr gd, group_membership gm, partition p,
|
2021-08-11 14:00:39 +02:00
|
|
|
notes_moduleimpl m, notes_evaluation e
|
|
|
|
WHERE gm.group_id = gd.id
|
|
|
|
and gd.partition_id = p.id
|
|
|
|
and p.formsemestre_id = m.formsemestre_id
|
|
|
|
and m.id = e.moduleimpl_id
|
|
|
|
and e.id = %(evaluation_id)s
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
+ c,
|
|
|
|
{"evaluation_id": evaluation_id},
|
|
|
|
)
|
2021-10-15 14:00:51 +02:00
|
|
|
group_ids = [x[0] for x in cursor]
|
2021-08-19 10:28:35 +02:00
|
|
|
return listgroups(group_ids)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def listgroups(group_ids):
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-02-03 22:00:41 +01:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
2020-09-26 16:19:37 +02:00
|
|
|
groups = []
|
|
|
|
for group_id in group_ids:
|
|
|
|
cursor.execute(
|
2021-10-24 18:28:01 +02:00
|
|
|
"""SELECT gd.id AS group_id, gd.*, p.id AS partition_id, p.*
|
|
|
|
FROM group_descr gd, partition p
|
|
|
|
WHERE p.id = gd.partition_id
|
2021-08-11 13:01:37 +02:00
|
|
|
AND gd.id = %(group_id)s
|
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"group_id": group_id},
|
|
|
|
)
|
|
|
|
r = cursor.dictfetchall()
|
|
|
|
if r:
|
|
|
|
groups.append(r[0])
|
|
|
|
return _sortgroups(groups)
|
|
|
|
|
|
|
|
|
|
|
|
def _sortgroups(groups):
|
|
|
|
# Tri: place 'all' en tête, puis groupe par partition / nom de groupe
|
|
|
|
R = [g for g in groups if g["partition_name"] is None]
|
|
|
|
o = [g for g in groups if g["partition_name"] != None]
|
2021-09-16 00:16:50 +02:00
|
|
|
o.sort(key=lambda x: (x["numero"] or 0, x["group_name"]))
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
return R + o
|
|
|
|
|
|
|
|
|
|
|
|
def listgroups_filename(groups):
|
|
|
|
"""Build a filename representing groups"""
|
|
|
|
return "gr" + "+".join([g["group_name"] or "tous" for g in groups])
|
|
|
|
|
|
|
|
|
|
|
|
def listgroups_abbrev(groups):
|
|
|
|
"""Human readable abbreviation descring groups (eg "A / AB / B3")
|
|
|
|
Ne retient que les partitions avec show_in_lists
|
|
|
|
"""
|
|
|
|
return " / ".join(
|
|
|
|
[g["group_name"] for g in groups if g["group_name"] and g["show_in_lists"]]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# form_group_choice replaces formChoixGroupe
|
2024-10-30 10:28:15 +01:00
|
|
|
# obsolete, utilisé seulement par formsemestre_inscription_with_modules
|
2020-09-26 16:19:37 +02:00
|
|
|
def form_group_choice(
|
|
|
|
formsemestre_id,
|
|
|
|
allow_none=True, # offre un choix vide dans chaque partition
|
|
|
|
select_default=True, # Le groupe par defaut est mentionné (hidden).
|
|
|
|
display_sem_title=False,
|
|
|
|
):
|
|
|
|
"""Partie de formulaire pour le choix d'un ou plusieurs groupes.
|
|
|
|
Variable : group_ids
|
|
|
|
"""
|
2021-06-21 11:22:55 +02:00
|
|
|
from app.scodoc import sco_formsemestre
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
sem = sco_formsemestre.get_formsemestre(formsemestre_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
if display_sem_title:
|
|
|
|
sem_title = "%s: " % sem["titremois"]
|
|
|
|
else:
|
|
|
|
sem_title = ""
|
|
|
|
#
|
|
|
|
H = ["""<table>"""]
|
2021-08-19 10:28:35 +02:00
|
|
|
for p in get_partitions_list(formsemestre_id):
|
2020-09-26 16:19:37 +02:00
|
|
|
if p["partition_name"] is None:
|
|
|
|
if select_default:
|
|
|
|
H.append(
|
|
|
|
'<input type="hidden" name="group_ids:list" value="%s"/>'
|
2021-08-19 10:28:35 +02:00
|
|
|
% get_partition_groups(p)[0]["group_id"]
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
H.append("<tr><td>Groupe de %(partition_name)s</td><td>" % p)
|
|
|
|
H.append('<select name="group_ids:list">')
|
|
|
|
if allow_none:
|
|
|
|
H.append('<option value="">aucun</option>')
|
2021-08-19 10:28:35 +02:00
|
|
|
for group in get_partition_groups(p):
|
2020-09-26 16:19:37 +02:00
|
|
|
H.append(
|
|
|
|
'<option value="%s">%s %s</option>'
|
|
|
|
% (group["group_id"], sem_title, group["group_name"])
|
|
|
|
)
|
|
|
|
H.append("</select></td></tr>")
|
|
|
|
H.append("""</table>""")
|
|
|
|
return "\n".join(H)
|
|
|
|
|
|
|
|
|
|
|
|
def make_query_groups(group_ids):
|
|
|
|
if group_ids:
|
2021-08-10 17:12:10 +02:00
|
|
|
return "&".join(["group_ids%3Alist=" + str(group_id) for group_id in group_ids])
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
2021-07-09 23:31:16 +02:00
|
|
|
class GroupIdInferer(object):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Sert à retrouver l'id d'un groupe dans un semestre donné
|
|
|
|
à partir de son nom.
|
|
|
|
Attention: il peut y avoir plusieurs groupes de même nom
|
|
|
|
dans des partitions différentes. Dans ce cas, prend le dernier listé.
|
|
|
|
On peut indiquer la partition en écrivant
|
|
|
|
partition_name:group_name
|
|
|
|
"""
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def __init__(self, formsemestre_id):
|
|
|
|
groups = get_sem_groups(formsemestre_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
self.name2group_id = {}
|
|
|
|
self.partitionname2group_id = {}
|
|
|
|
for group in groups:
|
|
|
|
self.name2group_id[group["group_name"]] = group["group_id"]
|
|
|
|
self.partitionname2group_id[
|
|
|
|
(group["partition_name"], group["group_name"])
|
|
|
|
] = group["group_id"]
|
|
|
|
|
|
|
|
def __getitem__(self, name):
|
|
|
|
"""Get group_id from group_name, or None is nonexistent.
|
|
|
|
The group name can be prefixed by the partition's name, using
|
|
|
|
syntax partition_name:group_name
|
|
|
|
"""
|
|
|
|
l = name.split(":", 1)
|
|
|
|
if len(l) > 1:
|
|
|
|
partition_name, group_name = l
|
|
|
|
else:
|
|
|
|
partition_name = None
|
|
|
|
group_name = name
|
|
|
|
if partition_name is None:
|
|
|
|
group_id = self.name2group_id.get(group_name, None)
|
|
|
|
if group_id is None and name[-2:] == ".0":
|
|
|
|
# si nom groupe numerique, excel ajoute parfois ".0" !
|
|
|
|
group_name = group_name[:-2]
|
|
|
|
group_id = self.name2group_id.get(group_name, None)
|
|
|
|
else:
|
|
|
|
group_id = self.partitionname2group_id.get(
|
|
|
|
(partition_name, group_name), None
|
|
|
|
)
|
|
|
|
return group_id
|