diff --git a/app/pe/pe_avislatex.py b/app/pe/pe_avislatex.py index 5ff20464f..e260853a5 100644 --- a/app/pe/pe_avislatex.py +++ b/app/pe/pe_avislatex.py @@ -218,6 +218,17 @@ def get_code_latex_avis_etudiant( return code +def get_annotations(etudids, tag_annotation_pe): + annotations = {} # etudid -> ( general, [ ecole -> specifique ] ) + ecoles = set() + for etudid in etudids: # parcours des étudiants + generale, specifiques = get_annotation_PE(etudid, tag_annotation_pe) + annotations[etudid] = (generale, specifiques) + for ecole in specifiques.keys(): + ecoles.add(ecole) + return ecoles, annotations + + # ---------------------------------------------------------------------------------------- def get_annotation_PE(etudid, tag_annotation_pe): """Renvoie l'annotation PE dans la liste de ces annotations ; @@ -225,8 +236,8 @@ def get_annotation_PE(etudid, tag_annotation_pe): (cf. .get_preferences -> pe_tag_annotation_avis_latex). Result: chaine unicode - Modif JMP retourne une liste d'annotations par ecole - ou [""] si pas d'annotation enregistrée + patch JMP + Result: { : wspecifique> } """ if tag_annotation_pe: cnx = ndb.GetDBConnexion() @@ -257,19 +268,14 @@ def get_annotation_PE(etudid, tag_annotation_pe): annotationPE = annotationPE.replace( "
", "\n\n" ) # Interprète les retours chariots html - - # Patch JMP build dictionnary of annotations - split = annotationPE.split("@") - globale = split[0] - if len(split) < 2: - return globale, None + splitted = annotationPE.split("@") + generale = splitted[0] specifiques = {} - for specifique in split[1:]: - ecole, annotation = specifique.split(":", 1) - specifiques[ecole] = f"{globale}\n{specifique}\n" - return globale, specifiques - - return "", None # pas d'annotations + for slice in splitted[1:]: + ecole, specifique = slice.split(":", 1) + specifiques[ecole] = specifique + return generale, specifiques + return "", {} # pas d'annotations # ---------------------------------------------------------------------------------------- @@ -394,15 +400,52 @@ def get_bilanParTag(donnees_etudiant, groupe="groupe"): return code_latex -def get_avis_pousuite_par_etudiant_par_ecole( - jury, - etudid, - template_latex, - footer_latex, - prefs, - ecole, - annotation, +def get_avis_poursuite_par_etudiant( + jury, etudid, template_latex, tag_annotation_pe, footer_latex, prefs ): + if pe_tools.PE_DEBUG: + pe_tools.pe_print( + "avis etudiant: " + jury.syntheseJury[etudid]["nom"] + " " + str(etudid) + ) + + generale, specifiques = get_annotation_PE(etudid, tag_annotation_pe) + results = [] + if len(specifiques) == 0: + annotation = generale + results.append( + get_avis_poursuite_par_candidature( + jury, template_latex, footer_latex, prefs, etudid, annotation + ) + ) + else: + for ecole, specifique in specifiques.items(): + annotation = f"{generale}\n{ecole}:{specifique}" + results.append( + get_avis_poursuite_par_candidature( + jury, template_latex, footer_latex, prefs, etudid, annotation, ecole + ) + ) + return results + + +# candidature = etudiant x ecole +# ---------------------------------------------------------------------------------------- +def get_avis_poursuite_par_candidature( + jury, template_latex, footer_latex, prefs, etudid, annotation, ecole="" +): + """Renvoie un nom de fichier et le contenu de l'avis latex d'un étudiant dont l'etudid est fourni. + result: [ chaine unicode, chaine unicode ] + """ + if pe_tools.PE_DEBUG: + pe_tools.pe_print( + "avis candidature: " + + jury.syntheseJury[etudid]["nom"] + + " " + + str(etudid) + + " " + + ecole + ) + civilite_str = jury.syntheseJury[etudid]["civilite_str"] nom = jury.syntheseJury[etudid]["nom"].replace(" ", "-") prenom = jury.syntheseJury[etudid]["prenom"].replace(" ", "-") @@ -412,72 +455,20 @@ def get_avis_pousuite_par_etudiant_par_ecole( ) if pe_tools.PE_DEBUG: pe_tools.pe_print("fichier latex =" + nom_fichier, type(nom_fichier)) - # Entete (commentaire) + # Entete (commentaire) contenu_latex = ( "%% ---- Etudiant: " + civilite_str + " " + nom + " " + prenom + "\n" ) # le LaTeX avis = get_code_latex_avis_etudiant( - jury.syntheseJury[etudid], - template_latex, - annotation, - footer_latex, - prefs, + jury.syntheseJury[etudid], template_latex, annotation, footer_latex, prefs ) # if pe_tools.PE_DEBUG: pe_tools.pe_print(avis, type(avis)) contenu_latex += avis + "\n" - return [nom_fichier, contenu_latex] - - -# ---------------------------------------------------------------------------------------- -def get_avis_poursuite_par_etudiant( - jury, etudid, template_latex, tag_annotation_pe, footer_latex, prefs -): - """Renvoie un nom de fichier et le contenu de l'avis latex d'un étudiant dont l'etudid est fourni. - result: [ chaine unicode, chaine unicode ] - Patch JMP: Renvoi une liste d'éléments comme décrit ci-dessus (1 élément par destination aka avis spécifique - """ - if pe_tools.PE_DEBUG: - pe_tools.pe_print(jury.syntheseJury[etudid]["nom"] + " " + str(etudid)) - - # les annotations - globale, specifiques = get_annotation_PE( - etudid, tag_annotation_pe=tag_annotation_pe - ) - if pe_tools.PE_DEBUG: - pe_tools.pe_print(globale, type(globale)) - pe_tools.pe_print(specifiques, type(specifiques)) - - returns = [] - if specifiques is None: - returns.append( - get_avis_pousuite_par_etudiant_par_ecole( - jury, - etudid, - template_latex, - footer_latex, - prefs, - "", - globale, - ) - ) - else: - for ecole in specifiques.keys(): - returns.append( - get_avis_pousuite_par_etudiant_par_ecole( - jury, - etudid, - template_latex, - footer_latex, - prefs, - ecole, - specifiques[ecole], - ) - ) - return returns + return nom_fichier, contenu_latex def get_templates_from_distrib(template="avis"): @@ -531,12 +522,16 @@ def table_syntheseAnnotationPE(syntheseJury, tag_annotation_pe): maxParcours = max( [syntheseJury[etudid]["nbSemestres"] for etudid in etudids] ) # le nombre de semestre le + grand + # calcul de l'inventaire des annotations + ecoles, annotations = get_annotations(etudids, tag_annotation_pe) infos = ["civilite", "nom", "prenom", "age", "nbSemestres"] entete = ["etudid"] entete.extend(infos) entete.extend(["P%d" % i for i in range(1, maxParcours + 1)]) # ajout du parcours entete.append("Annotation PE") + for ecole in sorted(ecoles): + entete.append(ecole) columns_ids = entete # les id et les titres de colonnes sont ici identiques titles = {i: i for i in columns_ids} @@ -561,8 +556,10 @@ def table_syntheseAnnotationPE(syntheseJury, tag_annotation_pe): n += 1 # L'annotation PE - globale, _ = get_annotation_PE(etudid, tag_annotation_pe=tag_annotation_pe) - row["Annotation PE"] = globale + generale, specifiques = annotations[etudid] + row["Annotation PE"] = generale + for ecole in sorted(ecoles): + row[ecole] = specifiques.get(ecole, "") rows.append(row) T = GenTable( diff --git a/app/pe/pe_view.py b/app/pe/pe_view.py index 7f9f31d5e..f6477d091 100644 --- a/app/pe/pe_view.py +++ b/app/pe/pe_view.py @@ -145,15 +145,15 @@ def pe_view_sem_recap( latex_pages = {} # Dictionnaire de la forme nom_fichier => contenu_latex for etudid in etudids: - les_avis = pe_avislatex.get_avis_poursuite_par_etudiant( + for fichier_latex in pe_avislatex.get_avis_poursuite_par_etudiant( jury, etudid, template_latex, tag_annotation_pe, footer_latex, prefs, - ) - for nom_fichier, contenu_latex in les_avis: + ): + nom_fichier, contenu_latex = fichier_latex jury.add_file_to_zip("avis/" + nom_fichier + ".tex", contenu_latex) latex_pages[nom_fichier] = contenu_latex # Sauvegarde dans un dico