# -*- mode: python -*- # -*- coding: utf-8 -*- ############################################################################## # # Gestion scolarite IUT # # Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Emmanuel Viennet emmanuel.viennet@viennet.net # ############################################################################## """Tableau de bord module """ import time from flask import g, url_for from flask_login import current_user from app.auth.models import User from app.comp import res_sem from app.comp.res_compat import NotesTableCompat from app.models import ModuleImpl from app.models.evaluations import Evaluation import app.scodoc.sco_utils as scu from app.scodoc.sco_exceptions import ScoInvalidIdType from app.scodoc.sco_cursus_dut import formsemestre_has_decisions from app.scodoc.sco_permissions import Permission from app.scodoc import html_sco_header from app.scodoc import htmlutils from app.scodoc import sco_abs from app.scodoc import sco_compute_moy from app.scodoc import sco_cache from app.scodoc import sco_edit_module from app.scodoc import sco_evaluations from app.scodoc import sco_evaluation_db from app.scodoc import sco_formations from app.scodoc import sco_formsemestre from app.scodoc import sco_formsemestre_status from app.scodoc import sco_groups from app.scodoc import sco_moduleimpl from app.scodoc import sco_permissions_check from app.scodoc import sco_users # ported from old DTML code in oct 2009 # menu evaluation dans moduleimpl def moduleimpl_evaluation_menu(evaluation_id, nbnotes=0): "Menu avec actions sur une evaluation" E = sco_evaluation_db.do_evaluation_list({"evaluation_id": evaluation_id})[0] modimpl = sco_moduleimpl.moduleimpl_list(moduleimpl_id=E["moduleimpl_id"])[0] group_id = sco_groups.get_default_group(modimpl["formsemestre_id"]) if ( sco_permissions_check.can_edit_notes( current_user, E["moduleimpl_id"], allow_ens=False ) and nbnotes != 0 ): sup_label = "Supprimer évaluation impossible (il y a des notes)" else: sup_label = "Supprimer évaluation" menuEval = [ { "title": "Saisir notes", "endpoint": "notes.saisie_notes", "args": { "evaluation_id": evaluation_id, }, "enabled": sco_permissions_check.can_edit_notes( current_user, E["moduleimpl_id"] ), }, { "title": "Modifier évaluation", "endpoint": "notes.evaluation_edit", "args": { "evaluation_id": evaluation_id, }, "enabled": sco_permissions_check.can_edit_notes( current_user, E["moduleimpl_id"], allow_ens=False ), }, { "title": sup_label, "endpoint": "notes.evaluation_delete", "args": { "evaluation_id": evaluation_id, }, "enabled": nbnotes == 0 and sco_permissions_check.can_edit_notes( current_user, E["moduleimpl_id"], allow_ens=False ), }, { "title": "Supprimer toutes les notes", "endpoint": "notes.evaluation_suppress_alln", "args": { "evaluation_id": evaluation_id, }, "enabled": sco_permissions_check.can_edit_notes( current_user, E["moduleimpl_id"], allow_ens=False ), }, { "title": "Afficher les notes", "endpoint": "notes.evaluation_listenotes", "args": { "evaluation_id": evaluation_id, }, "enabled": nbnotes > 0, }, { "title": "Placement étudiants", "endpoint": "notes.placement_eval_selectetuds", "args": { "evaluation_id": evaluation_id, }, "enabled": sco_permissions_check.can_edit_notes( current_user, E["moduleimpl_id"] ), }, { "title": "Absences ce jour", "endpoint": "absences.EtatAbsencesDate", "args": { "date": E["jour"], "group_ids": group_id, }, "enabled": E["jour"], }, { "title": "Vérifier notes vs absents", "endpoint": "notes.evaluation_check_absences_html", "args": { "evaluation_id": evaluation_id, }, "enabled": nbnotes > 0 and E["jour"], }, ] return htmlutils.make_menu("actions", menuEval, alone=True) def _ue_coefs_html(coefs_lst) -> str: """ """ max_coef = max([x[1] for x in coefs_lst]) if coefs_lst else 1.0 H = """
Coefficients vers les UE
""" if coefs_lst: H += ( f"""
""" + "\n".join( [ f"""
{coef}
{ue.acronyme}
""" for ue, coef in coefs_lst ] ) + "
" ) else: H += """
non définis
""" H += "
" return H def moduleimpl_status(moduleimpl_id=None, partition_id=None): """Tableau de bord module (liste des evaluations etc)""" if not isinstance(moduleimpl_id, int): raise ScoInvalidIdType("moduleimpl_id must be an integer !") modimpl: ModuleImpl = ModuleImpl.query.get_or_404(moduleimpl_id) M = modimpl.to_dict() formsemestre_id = modimpl.formsemestre_id Mod = sco_edit_module.module_list(args={"module_id": modimpl.module_id})[0] sem = sco_formsemestre.get_formsemestre(formsemestre_id) F = sco_formations.formation_list(args={"formation_id": sem["formation_id"]})[0] mod_inscrits = sco_moduleimpl.do_moduleimpl_inscription_list( moduleimpl_id=M["moduleimpl_id"] ) nt: NotesTableCompat = res_sem.load_formsemestre_results(modimpl.formsemestre) mod_evals = sco_evaluation_db.do_evaluation_list({"moduleimpl_id": moduleimpl_id}) mod_evals.sort( key=lambda x: (x["numero"], x["jour"], x["heure_debut"]), reverse=True ) # la plus RECENTE en tête # sem_locked = not sem["etat"] can_edit_evals = ( sco_permissions_check.can_edit_notes( current_user, moduleimpl_id, allow_ens=sem["ens_can_edit_eval"] ) and not sem_locked ) can_edit_notes = ( sco_permissions_check.can_edit_notes(current_user, moduleimpl_id) and not sem_locked ) arrow_up, arrow_down, arrow_none = sco_groups.get_arrow_icons_tags() # module_resp = User.query.get(M["responsable_id"]) mod_type_name = scu.MODULE_TYPE_NAMES[Mod["module_type"]] H = [ html_sco_header.sco_header( page_title=f"{mod_type_name} {Mod['code']} {Mod['titre']}" ), f"""

{mod_type_name} {Mod['code']} {Mod['titre']} {"dans l'UE " + modimpl.module.ue.acronyme if modimpl.module.module_type == scu.ModuleType.MALUS else ""}

""") # 2ieme ligne: Semestre, Coef H.append("""""") # 3ieme ligne: Formation H.append( """""" % F ) # Ligne: Inscrits H.append( """") # Ligne: règle de calcul has_expression = sco_compute_moy.moduleimpl_has_expression(M) if has_expression: H.append( '") else: H.append( '") H.append( '
Responsable: {module_resp.get_nomcomplet()} ({module_resp.user_name}) """, ] try: sco_moduleimpl.can_change_module_resp(moduleimpl_id) H.append( """modifier""" % moduleimpl_id ) except: pass H.append("""""") H.append( ", ".join([sco_users.user_info(m["ens_id"])["nomprenom"] for m in M["ens"]]) ) H.append("""""") try: sco_moduleimpl.can_change_ens(moduleimpl_id) H.append( """modifier les enseignants""" % moduleimpl_id ) except: pass H.append("""
""") if sem["semestre_id"] >= 0: H.append("""Semestre: %s""" % sem["semestre_id"]) else: H.append("""""") if sem_locked: H.append(scu.icontag("lock32_img", title="verrouillé")) H.append("""""") if modimpl.module.is_apc(): H.append(_ue_coefs_html(modimpl.module.ue_coefs_list())) else: H.append( f"""Coef. dans le semestre: { "non défini" if modimpl.module.coefficient is None else modimpl.module.coefficient }""" ) H.append("""
Formation: %(titre)s
Inscrits: %d étudiants""" % len(mod_inscrits) ) if current_user.has_permission(Permission.ScoEtudInscrit): H.append( """modifier""" % M["moduleimpl_id"] ) H.append("
Règle de calcul: moyenne=%s' % M["computation_expr"] ) H.append("""inutilisée dans cette version de ScoDoc""") if sco_moduleimpl.can_change_ens(moduleimpl_id, raise_exc=False): H.append( f""" supprimer""" ) H.append("""""") H.append("
' # règle de calcul standard' ) # if sco_moduleimpl.can_change_ens(moduleimpl_id, raise_exc=False): # H.append( # f' (changer)' # ) H.append("
Absences dans ce module' % moduleimpl_id ) # Adapté à partir d'une suggestion de DS (Le Havre) # Liens saisies absences seulement si permission et date courante dans le semestre if current_user.has_permission( Permission.ScoAbsChange ) and sco_formsemestre.sem_est_courant(sem): datelundi = sco_abs.ddmmyyyy(time.strftime("%d/%m/%Y")).prev_monday() group_id = sco_groups.get_default_group(formsemestre_id) H.append( f""" Saisie Absences hebdo. """ ) H.append("
") # if not modimpl.check_apc_conformity(): H.append( """
Les poids des évaluations de ce module ne sont pas encore conformes au PN. Ses notes ne peuvent pas être prises en compte dans les moyennes d'UE.
""" ) # if has_expression and nt.expr_diagnostics: H.append(sco_formsemestre_status.html_expr_diagnostic(nt.expr_diagnostics)) # if formsemestre_has_decisions(formsemestre_id): H.append( """""" ) # H.append( """

%d évaluations : """ % (len(mod_evals), moduleimpl_id) ) # # Liste les noms de partitions partitions = sco_groups.get_partitions_list(sem["formsemestre_id"]) H.append( """Afficher les groupes de       Voir toutes les notes

""" % M ) # -------- Tableau des evaluations top_table_links = "" if can_edit_evals: top_table_links = f"""Créer nouvelle évaluation Trier par date """ if mod_evals: H.append( '" ) H.append("""""") eval_index = len(mod_evals) - 1 first_eval = True for eval in mod_evals: evaluation: Evaluation = Evaluation.query.get( eval["evaluation_id"] ) # TODO unifier etat = sco_evaluations.do_evaluation_etat( eval["evaluation_id"], partition_id=partition_id, select_first_partition=True, ) if eval["evaluation_type"] in ( scu.EVALUATION_RATTRAPAGE, scu.EVALUATION_SESSION2, ): tr_class = "mievr mievr_rattr" else: tr_class = "mievr" tr_class_1 = "mievr" if not first_eval: H.append("""""") tr_class_1 += " mievr_spaced" H.append("""""") H.append( """""") H.append("""") # H.append( """ """ % (eval["duree"], "%g" % eval["coefficient"]) ) H.append( """""") # if etat["nb_notes"] == 0: H.append("""""" % tr_class) if modimpl.module.is_apc(): H.append( f"""""" ) else: H.append('') H.append("""""") else: # il y a deja des notes saisies gr_moyennes = etat["gr_moyennes"] first_group = True for gr_moyenne in gr_moyennes: H.append("""""" % tr_class) H.append("""""") if first_group and modimpl.module.is_apc(): H.append( f"""""" ) else: H.append("""""") first_group = False if gr_moyenne["group_name"] is None: name = "Tous" # tous else: name = "Groupe %s" % gr_moyenne["group_name"] H.append( """""") first_eval = False # H.append("""
 
""" % tr_class_1) if eval["jour"]: H.append("""Le %(jour)s%(descrheure)s""" % eval) else: H.append( """Evaluation sans date""" % eval ) H.append("    %(description)s" % eval) if eval["evaluation_type"] == scu.EVALUATION_RATTRAPAGE: H.append( """rattrapage""" ) elif eval["evaluation_type"] == scu.EVALUATION_SESSION2: H.append( """session 2""" ) if etat["last_modif"]: H.append( """(dernière modif le %s)""" % etat["last_modif"].strftime("%d/%m/%Y à %Hh%M") ) H.append('') if has_expression or True: H.append( """%2d""" % eval_index ) # Fleches: H.append('') if eval_index != (len(mod_evals) - 1) and can_edit_evals: H.append( '%s' % (eval["evaluation_id"], arrow_up) ) else: H.append(arrow_none) if (eval_index > 0) and can_edit_evals: H.append( '%s' % (eval["evaluation_id"], arrow_down) ) else: H.append(arrow_none) H.append("") eval_index -= 1 H.append("""
 DuréeCoef.NotesAbsNMoyenne """ % tr_class ) if etat["evalcomplete"]: etat_txt = """(prise en compte)""" etat_descr = "notes utilisées dans les moyennes" elif eval["publish_incomplete"]: etat_txt = """(prise en compte immédiate)""" etat_descr = ( "il manque des notes, mais la prise en compte immédiate a été demandée" ) elif etat["nb_notes"] != 0: etat_txt = "(non prise en compte)" etat_descr = "il manque des notes" else: etat_txt = "" if can_edit_evals and etat_txt: etat_txt = ( '%s' % (eval["evaluation_id"], etat_descr, etat_txt) ) H.append(etat_txt) H.append("""
""" % tr_class) if can_edit_evals: H.append( """%s""" % ( eval["evaluation_id"], scu.icontag( "edit_img", alt="modifier", title="Modifier informations" ), ) ) if can_edit_notes: H.append( """%s""" % ( eval["evaluation_id"], scu.icontag( "notes_img", alt="saisie notes", title="Saisie des notes" ), ) ) if etat["nb_notes"] == 0: if can_edit_evals: H.append( """""" % eval ) H.append(scu.icontag("delete_img", alt="supprimer", title="Supprimer")) if can_edit_evals: H.append("""""") elif etat["evalcomplete"]: H.append( """%s""" % (eval["evaluation_id"], scu.icontag("status_green_img", title="ok")) ) else: if etat["evalattente"]: H.append( """%s""" % ( eval["evaluation_id"], scu.icontag( "status_greenorange_img", file_format="gif", title="notes en attente", ), ) ) else: H.append( """%s""" % ( eval["evaluation_id"], scu.icontag("status_orange_img", title="il manque des notes"), ) ) # if eval["visibulletin"]: H.append( scu.icontag( "status_visible_img", title="visible dans bulletins intermédiaires" ) ) else: H.append(" ") H.append('') if can_edit_notes: H.append( moduleimpl_evaluation_menu( eval["evaluation_id"], nbnotes=etat["nb_notes"], ) ) H.append("%s%s%(nb_notes)s / %(nb_inscrits)s %(nb_abs)s %(nb_neutre)s """ % etat ) if etat["moy"]: H.append("%s / %g" % (etat["moy"], eval["note_max"])) H.append( """  (afficher)""" % (eval["evaluation_id"],) ) else: H.append( """saisir notes""" % (eval["evaluation_id"]) ) H.append("""
{ evaluation.get_ue_poids_str()}
 { evaluation.get_ue_poids_str()}%s  """ % name ) if gr_moyenne["gr_nb_notes"] > 0: H.append("%(gr_moy)s" % gr_moyenne) H.append( """  (%s notes""" % ( eval["evaluation_id"], gr_moyenne["group_id"], gr_moyenne["gr_nb_notes"], ) ) if gr_moyenne["gr_nb_att"] > 0: H.append( """, %s en attente""" % gr_moyenne["gr_nb_att"] ) H.append(""")""") if gr_moyenne["group_id"] in etat["gr_incomplets"]: H.append("""[""") if can_edit_notes: H.append( """incomplet]""" % (eval["evaluation_id"], gr_moyenne["group_id"]) ) else: H.append("""incomplet]""") else: H.append("""  """) if can_edit_notes: H.append( """""" % (eval["evaluation_id"], gr_moyenne["group_id"]) ) H.append("pas de notes") if can_edit_notes: H.append("""""") H.append("") H.append("""
""") if sem_locked: H.append(f"""{scu.icontag("lock32_img")} semestre verrouillé""") elif can_edit_evals: H.append(top_table_links) H.append( """

Légende

Rappel : seules les notes des évaluations complètement saisies (affichées en vert) apparaissent dans les bulletins.

""" % ( scu.icontag("edit_img"), scu.icontag("notes_img"), scu.icontag("delete_img"), scu.icontag("status_orange_img"), scu.icontag("status_green_img"), scu.icontag("status_visible_img"), ) ) H.append(html_sco_header.sco_footer()) return "".join(H)