Fix Issue 364 : vérif group_name déjà existant

This commit is contained in:
Matthias Hartmann 2022-06-17 20:10:09 +02:00
parent 21a2c1b7e7
commit 1a4461cfb0

View File

@ -599,6 +599,11 @@ def XMLgetGroupsInPartition(partition_id): # was XMLgetGroupesTD
response.headers["Content-Type"] = scu.XML_MIMETYPE response.headers["Content-Type"] = scu.XML_MIMETYPE
return response return response
def check_group_name(group_name, partition):
"""Raise ScoValueError if group_name exists in partition"""
exists = group_name in [g["group_name"] for g in get_partition_groups(partition)]
if exists:
raise ScoValueError("Le nom de groupe existe déjà dans la partition")
def comp_origin(etud, cur_sem): def comp_origin(etud, cur_sem):
"""breve description de l'origine de l'étudiant (sem. precedent) """breve description de l'origine de l'étudiant (sem. precedent)
@ -1244,6 +1249,7 @@ def group_set_name(group_id, group_name, redirect=True):
if not sco_permissions_check.can_change_groups(formsemestre_id): if not sco_permissions_check.can_change_groups(formsemestre_id):
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !") raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
redirect = int(redirect) redirect = int(redirect)
check_group_name(group_name, get_partition(group['partition_id']))
cnx = ndb.GetDBConnexion() cnx = ndb.GetDBConnexion()
groupEditor.edit(cnx, {"group_id": group_id, "group_name": group_name}) groupEditor.edit(cnx, {"group_id": group_id, "group_name": group_name})
@ -1372,13 +1378,13 @@ def groups_auto_repartition(partition_id=None):
# Crée les nouveaux groupes # Crée les nouveaux groupes
group_ids = [] group_ids = []
for group_name in group_names: for group_name in group_names:
# try: try:
# checkGroupName(group_name) check_group_name(group_name, partition)
# except: except:
# H.append('<p class="warning">Nom de groupe invalide: %s</p>'%group_name) H.append('<p class="warning">Nom de groupe invalide: %s</p>'%group_name)
# return '\n'.join(H) + tf[1] + html_sco_header.sco_footer() return '\n'.join(H) + tf[1] + html_sco_header.sco_footer()
group_ids.append(create_group(partition_id, group_name)) group_ids.append(create_group(partition_id, group_name))
#
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
identdict = nt.identdict identdict = nt.identdict
# build: { civilite : liste etudids trie par niveau croissant } # build: { civilite : liste etudids trie par niveau croissant }