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@viennet.net
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""Formulaires gestion des groupes
|
|
|
|
"""
|
2023-11-06 22:05:38 +01:00
|
|
|
import flask
|
|
|
|
from flask import flash, g, render_template, request, url_for
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-11-06 22:05:38 +01:00
|
|
|
from app.models import FormSemestre, GroupDescr, Partition
|
|
|
|
from app.models import GROUPNAME_STR_LEN
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import html_sco_header
|
|
|
|
from app.scodoc.sco_exceptions import AccessDenied
|
2023-11-06 22:05:38 +01:00
|
|
|
import app.scodoc.sco_utils as scu
|
|
|
|
from app.scodoc.TrivialFormulator import TrivialFormulator
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-10-04 22:05:05 +02:00
|
|
|
def affect_groups(partition_id):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Formulaire affectation des etudiants aux groupes de la partition.
|
|
|
|
Permet aussi la creation et la suppression de groupes.
|
|
|
|
"""
|
2021-10-04 22:05:05 +02:00
|
|
|
# réécrit pour 9.0.47 avec un template
|
2022-05-29 17:34:03 +02:00
|
|
|
partition = Partition.query.get_or_404(partition_id)
|
2023-09-02 22:19:35 +02:00
|
|
|
formsemestre = partition.formsemestre
|
|
|
|
if not formsemestre.can_change_groups():
|
2021-10-12 16:05:50 +02:00
|
|
|
raise AccessDenied("vous n'avez pas la permission de modifier les groupes")
|
2023-09-02 22:19:35 +02:00
|
|
|
formsemestre.setup_parcours_groups()
|
2021-10-04 22:05:05 +02:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"scolar/affect_groups.j2",
|
2021-10-04 22:05:05 +02:00
|
|
|
sco_header=html_sco_header.sco_header(
|
2020-09-26 16:19:37 +02:00
|
|
|
page_title="Affectation aux groupes",
|
|
|
|
javascripts=["js/groupmgr.js"],
|
|
|
|
cssstyles=["css/groups.css"],
|
|
|
|
),
|
2021-10-04 22:05:05 +02:00
|
|
|
sco_footer=html_sco_header.sco_footer(),
|
|
|
|
partition=partition,
|
2022-05-29 17:34:03 +02:00
|
|
|
# Liste des partitions sans celle par defaut:
|
|
|
|
partitions_list=partition.formsemestre.partitions.filter(
|
|
|
|
Partition.partition_name != None
|
2021-10-04 22:05:05 +02:00
|
|
|
),
|
2023-09-02 22:19:35 +02:00
|
|
|
formsemestre_id=formsemestre.id,
|
2021-10-04 22:05:05 +02:00
|
|
|
)
|
2023-11-06 22:05:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
def group_rename(group_id):
|
|
|
|
"""Form to rename a group"""
|
|
|
|
group: GroupDescr = GroupDescr.query.get_or_404(group_id)
|
|
|
|
formsemestre_id = group.partition.formsemestre_id
|
|
|
|
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 !")
|
|
|
|
H = [f"<h2>Renommer un groupe de {group.partition.partition_name or '-'}</h2>"]
|
|
|
|
tf = TrivialFormulator(
|
|
|
|
request.base_url,
|
|
|
|
scu.get_request_args(),
|
|
|
|
(
|
|
|
|
("group_id", {"default": group_id, "input_type": "hidden"}),
|
|
|
|
(
|
|
|
|
"group_name",
|
|
|
|
{
|
|
|
|
"title": "Nouveau nom",
|
|
|
|
"default": group.group_name,
|
|
|
|
"size": 12,
|
|
|
|
"allow_null": False,
|
|
|
|
"validator": lambda val, _: len(val) < GROUPNAME_STR_LEN,
|
2024-06-05 10:23:21 +02:00
|
|
|
"explanation": (
|
|
|
|
"doit être unique dans cette partition"
|
|
|
|
if group.partition.groups_editable
|
|
|
|
else "groupes non modifiables dans cette partition"
|
|
|
|
),
|
2023-11-13 12:16:10 +01:00
|
|
|
"enabled": group.partition.groups_editable,
|
2023-11-06 22:05:38 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"edt_id",
|
|
|
|
{
|
|
|
|
"title": "Id EDT",
|
|
|
|
"default": group.edt_id or "",
|
|
|
|
"size": 12,
|
|
|
|
"allow_null": True,
|
2023-11-11 18:13:18 +01:00
|
|
|
"explanation": """optionnel : identifiant du groupe dans le logiciel
|
2023-11-13 12:16:10 +01:00
|
|
|
d'emploi du temps, pour le cas où les noms de groupes ne seraient pas
|
2023-11-21 12:19:35 +01:00
|
|
|
les mêmes dans ScoDoc et dans l'emploi du temps (si plusieurs ids de
|
|
|
|
groupes EDT doivent correspondre au même groupe ScoDoc,
|
2023-11-21 11:31:22 +01:00
|
|
|
les séparer par des virgules).""",
|
2023-11-06 22:05:38 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2023-11-11 18:13:18 +01:00
|
|
|
submitlabel="Enregistrer",
|
2023-11-06 22:05:38 +01:00
|
|
|
cancelbutton="Annuler",
|
|
|
|
)
|
|
|
|
dest_url = url_for(
|
|
|
|
"scolar.partition_editor",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
formsemestre_id=group.partition.formsemestre_id,
|
|
|
|
edit_partition=1,
|
|
|
|
)
|
|
|
|
if tf[0] == 0:
|
|
|
|
return (
|
|
|
|
html_sco_header.sco_header()
|
|
|
|
+ "\n".join(H)
|
|
|
|
+ "\n"
|
|
|
|
+ tf[1]
|
|
|
|
+ html_sco_header.sco_footer()
|
|
|
|
)
|
|
|
|
elif tf[0] == -1:
|
|
|
|
return flask.redirect(dest_url)
|
|
|
|
else:
|
|
|
|
# form submission
|
2023-11-13 12:16:10 +01:00
|
|
|
# Si la partition n'est pas editable, on ne peut changer que l'edt_id
|
|
|
|
group.set_edt_id(tf[2]["edt_id"])
|
|
|
|
if group.partition.groups_editable:
|
|
|
|
group.set_name(tf[2]["group_name"], dest_url=dest_url)
|
2023-11-06 22:05:38 +01:00
|
|
|
flash("groupe modifié")
|
|
|
|
return flask.redirect(dest_url)
|