From e1db9c542bffc3b6c8620782457e9ee52200795b Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 28 Feb 2022 11:47:39 +0100 Subject: [PATCH] Messages flash flask sur ancioennes pages ScoDoc + warning ECTS BUT --- app/comp/moy_sem.py | 2 +- app/comp/res_common.py | 22 ++++++++++++++++------ app/scodoc/html_sco_header.py | 5 ++++- app/scodoc/sco_edit_ue.py | 2 ++ app/static/css/scodoc.css | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/comp/moy_sem.py b/app/comp/moy_sem.py index 2aec3b736..db42616c8 100644 --- a/app/comp/moy_sem.py +++ b/app/comp/moy_sem.py @@ -65,7 +65,7 @@ def compute_sem_moys_apc_using_ects( moy_gen = (etud_moy_ue_df * ects).sum(axis=1) / sum(ects) except TypeError: if None in ects: - flash(f"""Calcul moyenne générale impossible: ECTS des UE manquants !""") + flash("""Calcul moyenne générale impossible: ECTS des UE manquants !""") moy_gen = pd.Series(np.NaN, index=etud_moy_ue_df.index) else: raise diff --git a/app/comp/res_common.py b/app/comp/res_common.py index 6a821ac69..7d2eb5ae3 100644 --- a/app/comp/res_common.py +++ b/app/comp/res_common.py @@ -9,7 +9,7 @@ from functools import cached_property import numpy as np import pandas as pd -from flask import g, url_for +from flask import g, flash, url_for from app import log from app.comp.aux_stats import StatsMoyenne @@ -419,21 +419,31 @@ class NotesTableCompat(ResultatsSemestre): """Stats (moy/min/max) sur la moyenne générale""" return StatsMoyenne(self.etud_moy_gen) - def get_ues_stat_dict(self, filter_sport=False): # was get_ues() + def get_ues_stat_dict( + self, filter_sport=False, check_apc_ects=True + ) -> list[dict]: # was get_ues() """Liste des UEs, ordonnée par numero. Si filter_sport, retire les UE de type SPORT. Résultat: liste de dicts { champs UE U stats moyenne UE } """ - ues = [] - for ue in self.formsemestre.query_ues(with_sport=not filter_sport): + ues = self.formsemestre.query_ues(with_sport=not filter_sport) + ues_dict = [] + for ue in ues: d = ue.to_dict() if ue.type != UE_SPORT: moys = self.etud_moy_ue[ue.id] else: moys = None d.update(StatsMoyenne(moys).to_dict()) - ues.append(d) - return ues + ues_dict.append(d) + if check_apc_ects and self.is_apc and not hasattr(g, "checked_apc_ects"): + g.checked_apc_ects = True + if None in [ue.ects for ue in ues if ue.type != UE_SPORT]: + flash( + """Calcul moyenne générale impossible: ECTS des UE manquants !""", + category="danger", + ) + return ues_dict def get_modimpls_dict(self, ue_id=None) -> list[dict]: """Liste des modules pour une UE (ou toutes si ue_id==None), diff --git a/app/scodoc/html_sco_header.py b/app/scodoc/html_sco_header.py index 23a8b8340..653cdb80d 100644 --- a/app/scodoc/html_sco_header.py +++ b/app/scodoc/html_sco_header.py @@ -30,7 +30,7 @@ import html -from flask import g +from flask import render_template from flask import request from flask_login import current_user @@ -280,6 +280,9 @@ def sco_header( if not no_side_bar: H.append(html_sidebar.sidebar()) H.append("""
""") + # En attendant le replacement complet de cette fonction, + # inclusion ici des messages flask + H.append(render_template("flashed_messages.html")) # # Barre menu semestre: H.append(formsemestre_page_title()) diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index 73e77dbbd..8cc3269a1 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -472,8 +472,10 @@ def ue_edit(ue_id=None, create=False, formation_id=None, default_semestre_idx=No "semestre_id": tf[2]["semestre_idx"], }, ) + flash("UE créée") else: do_ue_edit(tf[2]) + flash("UE modifiée") return flask.redirect( url_for( "notes.ue_table", diff --git a/app/static/css/scodoc.css b/app/static/css/scodoc.css index 3b80f7d6d..b3a80640a 100644 --- a/app/static/css/scodoc.css +++ b/app/static/css/scodoc.css @@ -138,7 +138,7 @@ div.head_message { border-radius: 8px; font-family : arial, verdana, sans-serif ; font-weight: bold; - width: 40%; + width: 70%; text-align: center; }