diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index 7a55e16b7..1016a5f09 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -580,7 +580,7 @@ class FormSemestre(db.Model): ) db.session.add(partition) db.session.flush() # pour avoir un id - flash(f"Partition Parcours créée.") + flash("Partition Parcours créée.") for parcour in self.parcours: if parcour.code: diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 2ea119552..246a3c9af 100644 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -128,17 +128,26 @@ def _build_menu_stats(formsemestre_id): ] -def formsemestre_status_menubar(sem): +def formsemestre_status_menubar(formsemestre: FormSemestre) -> str: """HTML to render menubar""" - formsemestre_id = sem["formsemestre_id"] - if int(sem["etat"]): + formsemestre_id = formsemestre.id + if formsemestre.etat: change_lock_msg = "Verrouiller" else: change_lock_msg = "Déverrouiller" - F = sco_formations.formation_list(args={"formation_id": sem["formation_id"]})[0] + formation = formsemestre.formation - menuSemestre = [ + # L'utilisateur est-il resp. du semestre ? + is_responsable = current_user.id in (u.id for u in formsemestre.responsables) + # A le droit de changer le semestre (déverrouiller, préférences bul., ...): + has_perm_change_sem = current_user.has_permission(Permission.ScoImplement) or ( + formsemestre.resp_can_edit and is_responsable + ) + # Peut modifier le semestre (si n'est pas verrouillé): + can_modify_sem = has_perm_change_sem and formsemestre.etat + + menu_semestre = [ { "title": "Tableau de bord", "endpoint": "notes.formsemestre_status", @@ -147,11 +156,11 @@ def formsemestre_status_menubar(sem): "helpmsg": "Tableau de bord du semestre", }, { - "title": "Voir la formation %(acronyme)s (v%(version)s)" % F, + "title": f"Voir la formation {formation.acronyme} (v{formation.version})", "endpoint": "notes.ue_table", "args": { - "formation_id": sem["formation_id"], - "semestre_idx": sem["semestre_id"], + "formation_id": formation.id, + "semestre_idx": formsemestre.semestre_id, }, "enabled": True, "helpmsg": "Tableau de bord du semestre", @@ -160,41 +169,31 @@ def formsemestre_status_menubar(sem): "title": "Modifier le semestre", "endpoint": "notes.formsemestre_editwithmodules", "args": { - "formation_id": sem["formation_id"], + "formation_id": formation.id, "formsemestre_id": formsemestre_id, }, - "enabled": ( - current_user.has_permission(Permission.ScoImplement) - or (current_user.id in sem["responsables"] and sem["resp_can_edit"]) - ) - and (sem["etat"]), + "enabled": can_modify_sem, "helpmsg": "Modifie le contenu du semestre (modules)", }, { "title": "Préférences du semestre", "endpoint": "scolar.formsemestre_edit_preferences", "args": {"formsemestre_id": formsemestre_id}, - "enabled": ( - current_user.has_permission(Permission.ScoImplement) - or (current_user.id in sem["responsables"] and sem["resp_can_edit"]) - ) - and (sem["etat"]), + "enabled": can_modify_sem, "helpmsg": "Préférences du semestre", }, { "title": "Réglages bulletins", "endpoint": "notes.formsemestre_edit_options", "args": {"formsemestre_id": formsemestre_id}, - "enabled": (current_user.id in sem["responsables"]) - or current_user.has_permission(Permission.ScoImplement), + "enabled": has_perm_change_sem, "helpmsg": "Change les options", }, { "title": change_lock_msg, "endpoint": "notes.formsemestre_change_lock", "args": {"formsemestre_id": formsemestre_id}, - "enabled": (current_user.id in sem["responsables"]) - or current_user.has_permission(Permission.ScoImplement), + "enabled": has_perm_change_sem, "helpmsg": "", }, { @@ -230,7 +229,7 @@ def formsemestre_status_menubar(sem): "endpoint": "notes.formsemestre_associate_new_version", "args": {"formsemestre_id": formsemestre_id}, "enabled": current_user.has_permission(Permission.ScoChangeFormation) - and (sem["etat"]), + and formsemestre.etat, "helpmsg": "", }, { @@ -243,7 +242,7 @@ def formsemestre_status_menubar(sem): ] # debug : if current_app.config["ENV"] == "development": - menuSemestre.append( + menu_semestre.append( { "title": "Vérifier l'intégrité", "endpoint": "notes.check_sem_integrity", @@ -252,20 +251,20 @@ def formsemestre_status_menubar(sem): } ) - menuInscriptions = [ + menu_inscriptions = [ { "title": "Voir les inscriptions aux modules", "endpoint": "notes.moduleimpl_inscriptions_stats", "args": {"formsemestre_id": formsemestre_id}, } ] - menuInscriptions += [ + menu_inscriptions += [ { "title": "Passage des étudiants depuis d'autres semestres", "endpoint": "notes.formsemestre_inscr_passage", "args": {"formsemestre_id": formsemestre_id}, "enabled": current_user.has_permission(Permission.ScoEtudInscrit) - and (sem["etat"]), + and formsemestre.etat, }, { "title": "Synchroniser avec étape Apogée", @@ -273,21 +272,21 @@ def formsemestre_status_menubar(sem): "args": {"formsemestre_id": formsemestre_id}, "enabled": current_user.has_permission(Permission.ScoView) and sco_preferences.get_preference("portal_url") - and (sem["etat"]), + and formsemestre.etat, }, { "title": "Inscrire un étudiant", "endpoint": "notes.formsemestre_inscription_with_modules_etud", "args": {"formsemestre_id": formsemestre_id}, "enabled": current_user.has_permission(Permission.ScoEtudInscrit) - and (sem["etat"]), + and formsemestre.etat, }, { "title": "Importer des étudiants dans ce semestre (table Excel)", "endpoint": "scolar.form_students_import_excel", "args": {"formsemestre_id": formsemestre_id}, "enabled": current_user.has_permission(Permission.ScoEtudInscrit) - and (sem["etat"]), + and formsemestre.etat, }, { "title": "Import/export des données admission", @@ -319,7 +318,7 @@ def formsemestre_status_menubar(sem): }, ] - menuGroupes = [ + menu_groupes = [ { "title": "Listes, photos, feuilles...", "endpoint": "scolar.groups_view", @@ -346,16 +345,16 @@ def formsemestre_status_menubar(sem): for partition in partitions: submenu.append( { - "title": "%s" % partition["partition_name"], + "title": str(partition["partition_name"]), "endpoint": "scolar.affect_groups", "args": {"partition_id": partition["partition_id"]}, - "enabled": enabled and partition["groups_editable"], + "enabled": enabled, } ) - menuGroupes.append( + menu_groupes.append( {"title": "Modifier les groupes", "submenu": submenu, "enabled": enabled} ) - menuGroupes.append( + menu_groupes.append( { "title": "Expérimental: éditeur de partitions", "endpoint": "scolar.partition_editor", @@ -367,7 +366,7 @@ def formsemestre_status_menubar(sem): }, ) - menuNotes = [ + menu_notes = [ { "title": "Tableau des moyennes (et liens bulletins)", "endpoint": "notes.formsemestre_recapcomplet", @@ -408,7 +407,7 @@ def formsemestre_status_menubar(sem): "args": {"formsemestre_id": formsemestre_id}, }, ] - menuJury = [ + menu_jury = [ { "title": "Voir les décisions du jury", "endpoint": "notes.formsemestre_pvjury", @@ -441,19 +440,17 @@ def formsemestre_status_menubar(sem): }, ] - menuStats = _build_menu_stats(formsemestre_id) + menu_stats = _build_menu_stats(formsemestre_id) H = [ - #
', ' | ", - #'