diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index 705e26248..b44498007 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -631,7 +631,7 @@ class FormSemestre(db.Model): def can_change_groups(self, user: User = None) -> bool: """Vrai si l'utilisateur (par def. current) peut changer les groupes dans - ce semestre: vérifie permission et verrouillage. + ce semestre: vérifie permission et verrouillage (mais pas si la partition est éditable). """ if not self.etat: return False # semestre verrouillé diff --git a/app/models/groups.py b/app/models/groups.py index 33eac2604..8e8791ca0 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -282,18 +282,18 @@ class GroupDescr(db.Model): return False return True - def set_name( - self, group_name: str, edt_id: str | bool = False, dest_url: str = None - ): + def set_name(self, group_name: str, dest_url: str = None): """Set group name, and optionally edt_id. - Check permission and invalidate caches. Commit session. + Check permission (partition must be groups_editable) + and invalidate caches. Commit session. dest_url is used for error messages. """ if not self.partition.formsemestre.can_change_groups(): raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !") if self.group_name is None: raise ValueError("can't set a name to default group") - + if not self.partition.groups_editable: + raise AccessDenied("Partition non éditable") if group_name: group_name = group_name.strip() if not group_name: @@ -306,16 +306,22 @@ class GroupDescr(db.Model): ) self.group_name = group_name - if edt_id is not False: - if isinstance(edt_id, str): - edt_id = edt_id.strip() or None - self.edt_id = edt_id db.session.add(self) db.session.commit() sco_cache.invalidate_formsemestre( formsemestre_id=self.partition.formsemestre_id ) + def set_edt_id(self, edt_id: str): + "Set edt_id. Check permission. Commit session." + if not self.partition.formsemestre.can_change_groups(): + raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !") + if isinstance(edt_id, str): + edt_id = edt_id.strip() or None + self.edt_id = edt_id + db.session.add(self) + db.session.commit() + def remove_etud(self, etud: "Identite"): "Enlève l'étudiant de ce groupe s'il en fait partie (ne fait rien sinon)" if etud in self.etuds: diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index bff18edb3..42bc71b3e 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -214,6 +214,9 @@ def do_formsemestre_createwithmodules(edit=False, formsemestre: FormSemestre = N ) for index, resp in enumerate(formsemestre.responsables): initvalues[resp_fields[index]] = uid2display.get(resp.id) + group_tous = formsemestre.get_default_group() + if group_tous: + initvalues["edt_promo_id"] = group_tous.edt_id or "" # Liste des ID de semestres if formation.type_parcours is not None: @@ -458,6 +461,18 @@ def do_formsemestre_createwithmodules(edit=False, formsemestre: FormSemestre = N }, ) ) + modform.append( + ( + "edt_promo_id", + { + "size": 32, + "title": "Identifiant EDT promo", + "explanation": """optionnel, identifiant du groupe "tous" + (promotion complète) dans l'emploi du temps.""", + "allow_null": True, + }, + ) + ) if edit: formtit = f"""

|| ${groupe.group_name} ${edt_id_str} - ✏️ + ✏️ `; div.addEventListener("click", filtre);