Fix: modif groupes parcours + some code cosmetic

This commit is contained in:
Emmanuel Viennet 2022-08-30 20:31:05 +02:00
parent 42f0cb8e76
commit 28b29b9654
3 changed files with 59 additions and 63 deletions

View File

@ -580,7 +580,7 @@ class FormSemestre(db.Model):
) )
db.session.add(partition) db.session.add(partition)
db.session.flush() # pour avoir un id db.session.flush() # pour avoir un id
flash(f"Partition Parcours créée.") flash("Partition Parcours créée.")
for parcour in self.parcours: for parcour in self.parcours:
if parcour.code: if parcour.code:

View File

@ -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""" """HTML to render menubar"""
formsemestre_id = sem["formsemestre_id"] formsemestre_id = formsemestre.id
if int(sem["etat"]): if formsemestre.etat:
change_lock_msg = "Verrouiller" change_lock_msg = "Verrouiller"
else: else:
change_lock_msg = "Déverrouiller" 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", "title": "Tableau de bord",
"endpoint": "notes.formsemestre_status", "endpoint": "notes.formsemestre_status",
@ -147,11 +156,11 @@ def formsemestre_status_menubar(sem):
"helpmsg": "Tableau de bord du semestre", "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", "endpoint": "notes.ue_table",
"args": { "args": {
"formation_id": sem["formation_id"], "formation_id": formation.id,
"semestre_idx": sem["semestre_id"], "semestre_idx": formsemestre.semestre_id,
}, },
"enabled": True, "enabled": True,
"helpmsg": "Tableau de bord du semestre", "helpmsg": "Tableau de bord du semestre",
@ -160,41 +169,31 @@ def formsemestre_status_menubar(sem):
"title": "Modifier le semestre", "title": "Modifier le semestre",
"endpoint": "notes.formsemestre_editwithmodules", "endpoint": "notes.formsemestre_editwithmodules",
"args": { "args": {
"formation_id": sem["formation_id"], "formation_id": formation.id,
"formsemestre_id": formsemestre_id, "formsemestre_id": formsemestre_id,
}, },
"enabled": ( "enabled": can_modify_sem,
current_user.has_permission(Permission.ScoImplement)
or (current_user.id in sem["responsables"] and sem["resp_can_edit"])
)
and (sem["etat"]),
"helpmsg": "Modifie le contenu du semestre (modules)", "helpmsg": "Modifie le contenu du semestre (modules)",
}, },
{ {
"title": "Préférences du semestre", "title": "Préférences du semestre",
"endpoint": "scolar.formsemestre_edit_preferences", "endpoint": "scolar.formsemestre_edit_preferences",
"args": {"formsemestre_id": formsemestre_id}, "args": {"formsemestre_id": formsemestre_id},
"enabled": ( "enabled": can_modify_sem,
current_user.has_permission(Permission.ScoImplement)
or (current_user.id in sem["responsables"] and sem["resp_can_edit"])
)
and (sem["etat"]),
"helpmsg": "Préférences du semestre", "helpmsg": "Préférences du semestre",
}, },
{ {
"title": "Réglages bulletins", "title": "Réglages bulletins",
"endpoint": "notes.formsemestre_edit_options", "endpoint": "notes.formsemestre_edit_options",
"args": {"formsemestre_id": formsemestre_id}, "args": {"formsemestre_id": formsemestre_id},
"enabled": (current_user.id in sem["responsables"]) "enabled": has_perm_change_sem,
or current_user.has_permission(Permission.ScoImplement),
"helpmsg": "Change les options", "helpmsg": "Change les options",
}, },
{ {
"title": change_lock_msg, "title": change_lock_msg,
"endpoint": "notes.formsemestre_change_lock", "endpoint": "notes.formsemestre_change_lock",
"args": {"formsemestre_id": formsemestre_id}, "args": {"formsemestre_id": formsemestre_id},
"enabled": (current_user.id in sem["responsables"]) "enabled": has_perm_change_sem,
or current_user.has_permission(Permission.ScoImplement),
"helpmsg": "", "helpmsg": "",
}, },
{ {
@ -230,7 +229,7 @@ def formsemestre_status_menubar(sem):
"endpoint": "notes.formsemestre_associate_new_version", "endpoint": "notes.formsemestre_associate_new_version",
"args": {"formsemestre_id": formsemestre_id}, "args": {"formsemestre_id": formsemestre_id},
"enabled": current_user.has_permission(Permission.ScoChangeFormation) "enabled": current_user.has_permission(Permission.ScoChangeFormation)
and (sem["etat"]), and formsemestre.etat,
"helpmsg": "", "helpmsg": "",
}, },
{ {
@ -243,7 +242,7 @@ def formsemestre_status_menubar(sem):
] ]
# debug : # debug :
if current_app.config["ENV"] == "development": if current_app.config["ENV"] == "development":
menuSemestre.append( menu_semestre.append(
{ {
"title": "Vérifier l'intégrité", "title": "Vérifier l'intégrité",
"endpoint": "notes.check_sem_integrity", "endpoint": "notes.check_sem_integrity",
@ -252,20 +251,20 @@ def formsemestre_status_menubar(sem):
} }
) )
menuInscriptions = [ menu_inscriptions = [
{ {
"title": "Voir les inscriptions aux modules", "title": "Voir les inscriptions aux modules",
"endpoint": "notes.moduleimpl_inscriptions_stats", "endpoint": "notes.moduleimpl_inscriptions_stats",
"args": {"formsemestre_id": formsemestre_id}, "args": {"formsemestre_id": formsemestre_id},
} }
] ]
menuInscriptions += [ menu_inscriptions += [
{ {
"title": "Passage des étudiants depuis d'autres semestres", "title": "Passage des étudiants depuis d'autres semestres",
"endpoint": "notes.formsemestre_inscr_passage", "endpoint": "notes.formsemestre_inscr_passage",
"args": {"formsemestre_id": formsemestre_id}, "args": {"formsemestre_id": formsemestre_id},
"enabled": current_user.has_permission(Permission.ScoEtudInscrit) "enabled": current_user.has_permission(Permission.ScoEtudInscrit)
and (sem["etat"]), and formsemestre.etat,
}, },
{ {
"title": "Synchroniser avec étape Apogée", "title": "Synchroniser avec étape Apogée",
@ -273,21 +272,21 @@ def formsemestre_status_menubar(sem):
"args": {"formsemestre_id": formsemestre_id}, "args": {"formsemestre_id": formsemestre_id},
"enabled": current_user.has_permission(Permission.ScoView) "enabled": current_user.has_permission(Permission.ScoView)
and sco_preferences.get_preference("portal_url") and sco_preferences.get_preference("portal_url")
and (sem["etat"]), and formsemestre.etat,
}, },
{ {
"title": "Inscrire un étudiant", "title": "Inscrire un étudiant",
"endpoint": "notes.formsemestre_inscription_with_modules_etud", "endpoint": "notes.formsemestre_inscription_with_modules_etud",
"args": {"formsemestre_id": formsemestre_id}, "args": {"formsemestre_id": formsemestre_id},
"enabled": current_user.has_permission(Permission.ScoEtudInscrit) "enabled": current_user.has_permission(Permission.ScoEtudInscrit)
and (sem["etat"]), and formsemestre.etat,
}, },
{ {
"title": "Importer des étudiants dans ce semestre (table Excel)", "title": "Importer des étudiants dans ce semestre (table Excel)",
"endpoint": "scolar.form_students_import_excel", "endpoint": "scolar.form_students_import_excel",
"args": {"formsemestre_id": formsemestre_id}, "args": {"formsemestre_id": formsemestre_id},
"enabled": current_user.has_permission(Permission.ScoEtudInscrit) "enabled": current_user.has_permission(Permission.ScoEtudInscrit)
and (sem["etat"]), and formsemestre.etat,
}, },
{ {
"title": "Import/export des données admission", "title": "Import/export des données admission",
@ -319,7 +318,7 @@ def formsemestre_status_menubar(sem):
}, },
] ]
menuGroupes = [ menu_groupes = [
{ {
"title": "Listes, photos, feuilles...", "title": "Listes, photos, feuilles...",
"endpoint": "scolar.groups_view", "endpoint": "scolar.groups_view",
@ -346,16 +345,16 @@ def formsemestre_status_menubar(sem):
for partition in partitions: for partition in partitions:
submenu.append( submenu.append(
{ {
"title": "%s" % partition["partition_name"], "title": str(partition["partition_name"]),
"endpoint": "scolar.affect_groups", "endpoint": "scolar.affect_groups",
"args": {"partition_id": partition["partition_id"]}, "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} {"title": "Modifier les groupes", "submenu": submenu, "enabled": enabled}
) )
menuGroupes.append( menu_groupes.append(
{ {
"title": "Expérimental: éditeur de partitions", "title": "Expérimental: éditeur de partitions",
"endpoint": "scolar.partition_editor", "endpoint": "scolar.partition_editor",
@ -367,7 +366,7 @@ def formsemestre_status_menubar(sem):
}, },
) )
menuNotes = [ menu_notes = [
{ {
"title": "Tableau des moyennes (et liens bulletins)", "title": "Tableau des moyennes (et liens bulletins)",
"endpoint": "notes.formsemestre_recapcomplet", "endpoint": "notes.formsemestre_recapcomplet",
@ -408,7 +407,7 @@ def formsemestre_status_menubar(sem):
"args": {"formsemestre_id": formsemestre_id}, "args": {"formsemestre_id": formsemestre_id},
}, },
] ]
menuJury = [ menu_jury = [
{ {
"title": "Voir les décisions du jury", "title": "Voir les décisions du jury",
"endpoint": "notes.formsemestre_pvjury", "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 = [ H = [
# <table><tr><td>',
'<ul id="sco_menu">', '<ul id="sco_menu">',
htmlutils.make_menu("Semestre", menuSemestre), htmlutils.make_menu("Semestre", menu_semestre),
htmlutils.make_menu("Inscriptions", menuInscriptions), htmlutils.make_menu("Inscriptions", menu_inscriptions),
htmlutils.make_menu("Groupes", menuGroupes), htmlutils.make_menu("Groupes", menu_groupes),
htmlutils.make_menu("Notes", menuNotes), htmlutils.make_menu("Notes", menu_notes),
htmlutils.make_menu("Jury", menuJury), htmlutils.make_menu("Jury", menu_jury),
htmlutils.make_menu("Statistiques", menuStats), htmlutils.make_menu("Statistiques", menu_stats),
formsemestre_custommenu_html(formsemestre_id), formsemestre_custommenu_html(formsemestre_id),
"</ul>", "</ul>",
#'</td></tr></table>'
] ]
return "\n".join(H) return "\n".join(H)
@ -536,7 +533,7 @@ def formsemestre_page_title(formsemestre_id=None):
"formsemestre_page_title.html", "formsemestre_page_title.html",
formsemestre=formsemestre, formsemestre=formsemestre,
scu=scu, scu=scu,
sem_menu_bar=formsemestre_status_menubar(formsemestre.to_dict()), sem_menu_bar=formsemestre_status_menubar(formsemestre),
) )
return h return h
@ -544,17 +541,14 @@ def formsemestre_page_title(formsemestre_id=None):
def fill_formsemestre(sem): def fill_formsemestre(sem):
"""Add some useful fields to help display formsemestres""" """Add some useful fields to help display formsemestres"""
notes_url = scu.NotesURL() sem["notes_url"] = scu.NotesURL()
sem["notes_url"] = notes_url
formsemestre_id = sem["formsemestre_id"] formsemestre_id = sem["formsemestre_id"]
if not sem["etat"]: if not sem["etat"]:
sem[ sem[
"locklink" "locklink"
] = """<a href="%s/formsemestre_change_lock?formsemestre_id=%s">%s</a>""" % ( ] = f"""<a href="{url_for('notes.formsemestre_change_lock',
notes_url, scodoc_dept=g.scodoc_dept,formsemestre_id=formsemestre_id )
sem["formsemestre_id"], }">{scu.icontag("lock_img", border="0", title="Semestre verrouillé")}</a>"""
scu.icontag("lock_img", border="0", title="Semestre verrouillé"),
)
else: else:
sem["locklink"] = "" sem["locklink"] = ""
if sco_preferences.get_preference("bul_display_publication", formsemestre_id): if sco_preferences.get_preference("bul_display_publication", formsemestre_id):
@ -562,21 +556,23 @@ def fill_formsemestre(sem):
eyeicon = scu.icontag("hide_img", border="0", title="Bulletins NON publiés") eyeicon = scu.icontag("hide_img", border="0", title="Bulletins NON publiés")
else: else:
eyeicon = scu.icontag("eye_img", border="0", title="Bulletins publiés") eyeicon = scu.icontag("eye_img", border="0", title="Bulletins publiés")
sem["eyelink"] = ( sem[
"""<a href="%s/formsemestre_change_publication_bul?formsemestre_id=%s">%s</a>""" "eyelink"
% (notes_url, sem["formsemestre_id"], eyeicon) ] = f"""<a href="{
) url_for('notes.formsemestre_change_publication_bul',
scodoc_dept=g.scodoc_dept,formsemestre_id=formsemestre_id)
}">{eyeicon}</a>"""
else: else:
sem["eyelink"] = "" sem["eyelink"] = ""
F = sco_formations.formation_list(args={"formation_id": sem["formation_id"]})[0] F = sco_formations.formation_list(args={"formation_id": sem["formation_id"]})[0]
sem["formation"] = F sem["formation"] = F
parcours = sco_codes_parcours.get_parcours_from_code(F["type_parcours"]) parcours = sco_codes_parcours.get_parcours_from_code(F["type_parcours"])
if sem["semestre_id"] != -1: if sem["semestre_id"] != -1:
sem["num_sem"] = ", %s %s" % (parcours.SESSION_NAME, sem["semestre_id"]) sem["num_sem"] = f""", {parcours.SESSION_NAME} {sem["semestre_id"]}"""
else: else:
sem["num_sem"] = "" # formation sans semestres sem["num_sem"] = "" # formation sans semestres
if sem["modalite"]: if sem["modalite"]:
sem["modalitestr"] = " en %s" % sem["modalite"] sem["modalitestr"] = f""" en {sem["modalite"]}"""
else: else:
sem["modalitestr"] = "" sem["modalitestr"] = ""

View File

@ -94,7 +94,7 @@ class ScoData:
else: else:
self.sem = formsemestre self.sem = formsemestre
self.sem_menu_bar = sco_formsemestre_status.formsemestre_status_menubar( self.sem_menu_bar = sco_formsemestre_status.formsemestre_status_menubar(
self.sem.to_dict() self.sem
) )
# --- Préférences # --- Préférences
# prefs fallback to global pref if sem is None: # prefs fallback to global pref if sem is None: