From 5ea4e741171a91f58336e742c6075896dc6505a2 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sun, 26 Sep 2021 09:52:55 +0200 Subject: [PATCH 1/6] wip poursuite d etudes --- app/pe/pe_avislatex.py | 84 ++++++++++++++++++---------------------- app/pe/pe_jurype.py | 18 ++++----- app/pe/pe_semestretag.py | 2 +- app/pe/pe_settag.py | 4 +- app/pe/pe_tools.py | 3 +- app/pe/pe_view.py | 13 +++---- 6 files changed, 56 insertions(+), 68 deletions(-) diff --git a/app/pe/pe_avislatex.py b/app/pe/pe_avislatex.py index a1cf300bc..52d353bb4 100644 --- a/app/pe/pe_avislatex.py +++ b/app/pe/pe_avislatex.py @@ -33,9 +33,9 @@ import os import codecs import re -from app.pe import pe_jurype -from app.pe import pe_tagtable -from app.pe import pe_tools +from app.scodoc import pe_jurype +from app.scodoc import pe_tagtable +from app.scodoc import pe_tools import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb @@ -48,7 +48,7 @@ from app.scodoc import sco_etud DEBUG = False # Pour debug et repérage des prints à changer en Log DONNEE_MANQUANTE = ( - u"" # Caractère de remplacement des données manquantes dans un avis PE + "" # Caractère de remplacement des données manquantes dans un avis PE ) # ---------------------------------------------------------------------------------------- @@ -102,17 +102,17 @@ def comp_latex_parcourstimeline(etudiant, promo, taille=17): result: chaine unicode (EV:) """ codelatexDebut = ( - u""" + """" \\begin{parcourstimeline}{**debut**}{**fin**}{**nbreSemestres**}{%d} """ % taille ) - modeleEvent = u""" + modeleEvent = """ \\parcoursevent{**nosem**}{**nomsem**}{**descr**} """ - codelatexFin = u""" + codelatexFin = """ \\end{parcourstimeline} """ reslatex = codelatexDebut @@ -125,13 +125,13 @@ def comp_latex_parcourstimeline(etudiant, promo, taille=17): for no_sem in range(etudiant["nbSemestres"]): descr = modeleEvent nom_semestre_dans_parcours = parcours[no_sem]["nom_semestre_dans_parcours"] - descr = descr.replace(u"**nosem**", str(no_sem + 1)) + descr = descr.replace("**nosem**", str(no_sem + 1)) if no_sem % 2 == 0: - descr = descr.replace(u"**nomsem**", nom_semestre_dans_parcours) - descr = descr.replace(u"**descr**", u"") + descr = descr.replace("**nomsem**", nom_semestre_dans_parcours) + descr = descr.replace("**descr**", "") else: - descr = descr.replace(u"**nomsem**", u"") - descr = descr.replace(u"**descr**", nom_semestre_dans_parcours) + descr = descr.replace("**nomsem**", "") + descr = descr.replace("**descr**", nom_semestre_dans_parcours) reslatex += descr reslatex += codelatexFin return reslatex @@ -166,7 +166,7 @@ def get_code_latex_avis_etudiant( result: chaine unicode """ if not donnees_etudiant or not un_avis_latex: # Cas d'un template vide - return annotationPE if annotationPE else u"" + return annotationPE if annotationPE else "" # Le template latex (corps + footer) code = un_avis_latex + "\n\n" + footer_latex @@ -189,17 +189,17 @@ def get_code_latex_avis_etudiant( ) # La macro parcourstimeline - elif tag_latex == u"parcourstimeline": + elif tag_latex == "parcourstimeline": valeur = comp_latex_parcourstimeline( donnees_etudiant, donnees_etudiant["promo"] ) # Le tag annotationPE - elif tag_latex == u"annotation": + elif tag_latex == "annotation": valeur = annotationPE # Le tag bilanParTag - elif tag_latex == u"bilanParTag": + elif tag_latex == "bilanParTag": valeur = get_bilanParTag(donnees_etudiant) # Les tags "simples": par ex. nom, prenom, civilite, ... @@ -249,14 +249,14 @@ def get_annotation_PE(etudid, tag_annotation_pe): ]["comment_u"] annotationPE = exp.sub( - u"", annotationPE + "", annotationPE ) # Suppression du tag d'annotation PE - annotationPE = annotationPE.replace(u"\r", u"") # Suppression des \r + annotationPE = annotationPE.replace("\r", "") # Suppression des \r annotationPE = annotationPE.replace( - u"
", u"\n\n" + "
", "\n\n" ) # Interprète les retours chariots html return annotationPE - return u"" # pas d'annotations + return "" # pas d'annotations # ---------------------------------------------------------------------------------------- @@ -282,7 +282,7 @@ def str_from_syntheseJury(donnees_etudiant, aggregat, groupe, tag_scodoc, champ) ): donnees_numeriques = donnees_etudiant[aggregat][groupe][tag_scodoc] if champ == "rang": - valeur = u"%s/%d" % ( + valeur = "%s/%d" % ( donnees_numeriques[ pe_tagtable.TableTag.FORMAT_DONNEES_ETUDIANTS.index("rang") ], @@ -303,9 +303,9 @@ def str_from_syntheseJury(donnees_etudiant, aggregat, groupe, tag_scodoc, champ) if isinstance( donnees_numeriques[indice_champ], float ): # valeur numérique avec formattage unicode - valeur = u"%2.2f" % donnees_numeriques[indice_champ] + valeur = "%2.2f" % donnees_numeriques[indice_champ] else: - valeur = u"%s" % donnees_numeriques[indice_champ] + valeur = "%s" % donnees_numeriques[indice_champ] return valeur @@ -356,29 +356,29 @@ def get_bilanParTag(donnees_etudiant, groupe="groupe"): ("\\textit{" + rang + "}") if note else "" ) # rang masqué si pas de notes - code_latex = u"\\begin{tabular}{|c|" + "|c" * (len(entete)) + "|}\n" - code_latex += u"\\hline \n" + code_latex = "\\begin{tabular}{|c|" + "|c" * (len(entete)) + "|}\n" + code_latex += "\\hline \n" code_latex += ( - u" & " + " & " + " & ".join(["\\textbf{" + intitule + "}" for (agg, intitule, _) in entete]) + " \\\\ \n" ) - code_latex += u"\\hline" - code_latex += u"\\hline \n" + code_latex += "\\hline" + code_latex += "\\hline \n" for (i, ligne_val) in enumerate(valeurs["note"]): titre = lignes[i] # règle le pb d'encodage code_latex += ( - u"\\textbf{" + titre + u"} & " + " & ".join(ligne_val) + u"\\\\ \n" + "\\textbf{" + titre + "} & " + " & ".join(ligne_val) + "\\\\ \n" ) code_latex += ( - u" & " - + u" & ".join( - [u"{\\scriptsize " + clsmt + u"}" for clsmt in valeurs["rang"][i]] + " & " + + " & ".join( + ["{\\scriptsize " + clsmt + "}" for clsmt in valeurs["rang"][i]] ) - + u"\\\\ \n" + + "\\\\ \n" ) - code_latex += u"\\hline \n" - code_latex += u"\\end{tabular}" + code_latex += "\\hline \n" + code_latex += "\\end{tabular}" return code_latex @@ -397,22 +397,12 @@ def get_avis_poursuite_par_etudiant( nom = jury.syntheseJury[etudid]["nom"].replace(" ", "-") prenom = jury.syntheseJury[etudid]["prenom"].replace(" ", "-") - nom_fichier = ( - u"avis_poursuite_" - + pe_tools.remove_accents(nom) - + "_" - + pe_tools.remove_accents(prenom) - + "_" - + str(etudid) - ) + nom_fichier = scu.sanitize_filename("avis_poursuite_%s_%s_%s" % (nom, prenom, etudid)) if pe_tools.PE_DEBUG: pe_tools.pe_print("fichier latex =" + nom_fichier, type(nom_fichier)) # Entete (commentaire) - - contenu_latex = ( - u"%% ---- Etudiant: " + civilite_str + " " + nom + " " + prenom + u"\n" - ) + contenu_latex = "%% ---- Etudiant: " + civilite_str + " " + nom + " " + prenom + "\n" # les annnotations annotationPE = get_annotation_PE(etudid, tag_annotation_pe=tag_annotation_pe) diff --git a/app/pe/pe_jurype.py b/app/pe/pe_jurype.py index ca2e9e52c..5fce90705 100644 --- a/app/pe/pe_jurype.py +++ b/app/pe/pe_jurype.py @@ -52,10 +52,10 @@ from app.scodoc import sco_cache from app.scodoc import sco_codes_parcours # sco_codes_parcours.NEXT -> sem suivant from app.scodoc import sco_etud from app.scodoc import sco_formsemestre -from app.pe import pe_tagtable -from app.pe import pe_tools -from app.pe import pe_semestretag -from app.pe import pe_settag +from app.scodoc import pe_tagtable +from app.scodoc import pe_tools +from app.scodoc import pe_semestretag +from app.scodoc import pe_settag # ---------------------------------------------------------------------------------------- def comp_nom_semestre_dans_parcours(sem): @@ -946,7 +946,7 @@ class JuryPE(object): return list(taglist) def get_allTagInSyntheseJury(self): - """Extrait tous les tags du dictionnaire syntheseJury trié par ordre alphabétique. [] si aucun tag""" + """Extrait tous les tags du dictionnaire syntheseJury trié par ordre alphabétique. [] si aucun tag """ allTags = set() for nom in JuryPE.PARCOURS.keys(): allTags = allTags.union(set(self.get_allTagForAggregat(nom))) @@ -1149,12 +1149,10 @@ class JuryPE(object): # ********************************************** def calcul_anneePromoDUT_d_un_etudiant(self, etudid): - """Calcule et renvoie la date de diplome prévue pour un étudiant fourni - avec son etudid en fonction de sesSemestres de scolarisation - et -1 s'il n'y a pas de semestre. - """ + """Calcule et renvoie la date de diplome prévue pour un étudiant fourni avec son etudid + en fonction de sesSemestres de scolarisation""" sesSemestres = self.get_semestresDUT_d_un_etudiant(etudid) - return max([get_annee_diplome_semestre(sem) for sem in sesSemestres] or -1) + return max([get_annee_diplome_semestre(sem) for sem in sesSemestres]) # ********************************************* # Fonctions d'affichage pour debug diff --git a/app/pe/pe_semestretag.py b/app/pe/pe_semestretag.py index a6729def9..80e256201 100644 --- a/app/pe/pe_semestretag.py +++ b/app/pe/pe_semestretag.py @@ -40,7 +40,7 @@ from app import log from app.scodoc import sco_codes_parcours from app.scodoc import sco_cache from app.scodoc import sco_tag_module -from app.pe import pe_tagtable +from app.scodoc import pe_tagtable class SemestreTag(pe_tagtable.TableTag): diff --git a/app/pe/pe_settag.py b/app/pe/pe_settag.py index 8fde8d20a..05eba20f2 100644 --- a/app/pe/pe_settag.py +++ b/app/pe/pe_settag.py @@ -36,8 +36,8 @@ Created on Fri Sep 9 09:15:05 2016 @author: barasc """ -from app.pe.pe_tools import pe_print, PE_DEBUG -from app.pe import pe_tagtable +from app.scodoc.pe_tools import pe_print, PE_DEBUG +from app.scodoc import pe_tagtable class SetTag(pe_tagtable.TableTag): diff --git a/app/pe/pe_tools.py b/app/pe/pe_tools.py index 5be8e2d98..ae00f4acc 100644 --- a/app/pe/pe_tools.py +++ b/app/pe/pe_tools.py @@ -168,6 +168,7 @@ def add_local_file_to_zip(zipfile, ziproot, pathname, path_in_zip): """Read pathname server file and add content to zip under path_in_zip""" rooted_path_in_zip = os.path.join(ziproot, path_in_zip) data = open(pathname).read() + breakpoint() zipfile.writestr(rooted_path_in_zip, data) @@ -209,7 +210,7 @@ def add_pe_stuff_to_zip(zipfile, ziproot): for f in logos_names: logo = os.path.join(scu.SCODOC_LOGOS_DIR, f) if os.path.isfile(logo): - add_local_file_to_zip(zipfile, ziproot, logo, "avis/logos/" + f) + add_local_file_to_zip(zipfile, ziproot, logo, "avis/logos/" + f, mode='rb') # ---------------------------------------------------------------------------------------- diff --git a/app/pe/pe_view.py b/app/pe/pe_view.py index 3d9c718ec..fa98e1d39 100644 --- a/app/pe/pe_view.py +++ b/app/pe/pe_view.py @@ -42,10 +42,9 @@ from app.scodoc import sco_formsemestre from app.scodoc import html_sco_header from app.scodoc import sco_preferences -from app.pe import pe_tools -from app.pe.pe_tools import PE_LATEX_ENCODING -from app.pe import pe_jurype -from app.pe import pe_avislatex +from app.scodoc import pe_tools +from app.scodoc import pe_jurype +from app.scodoc import pe_avislatex def _pe_view_sem_recap_form(formsemestre_id): @@ -152,8 +151,8 @@ def pe_view_sem_recap( ) jury.add_file_to_zip( - ("avis/" + nom_fichier + ".tex").encode(PE_LATEX_ENCODING), - contenu_latex.encode(PE_LATEX_ENCODING), + "avis/" + nom_fichier + ".tex", + contenu_latex, ) latex_pages[nom_fichier] = contenu_latex # Sauvegarde dans un dico @@ -161,7 +160,7 @@ def pe_view_sem_recap( doc_latex = "\n% -----\n".join( ["\\include{" + nom + "}" for nom in sorted(latex_pages.keys())] ) - jury.add_file_to_zip("avis/avis_poursuite.tex", doc_latex.encode(PE_LATEX_ENCODING)) + jury.add_file_to_zip("avis/avis_poursuite.tex", doc_latex) # Ajoute image, LaTeX class file(s) and modeles pe_tools.add_pe_stuff_to_zip(jury.zipfile, jury.NOM_EXPORT_ZIP) From 16b3701815111c449a839b7583dd1f959d4da59d Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sun, 26 Sep 2021 10:01:20 +0200 Subject: [PATCH 2/6] avant repare imports --- app/pe/pe_avislatex.py | 6 +++--- app/pe/pe_jurype.py | 8 ++++---- app/pe/pe_semestretag.py | 2 +- app/pe/pe_settag.py | 4 ++-- app/pe/pe_view.py | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/pe/pe_avislatex.py b/app/pe/pe_avislatex.py index 52d353bb4..bdd7a64ca 100644 --- a/app/pe/pe_avislatex.py +++ b/app/pe/pe_avislatex.py @@ -33,9 +33,9 @@ import os import codecs import re -from app.scodoc import pe_jurype -from app.scodoc import pe_tagtable -from app.scodoc import pe_tools +from app.pe import pe_tagtable +from app.pe import pe_jurype +from app.pe import pe_tools import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb diff --git a/app/pe/pe_jurype.py b/app/pe/pe_jurype.py index 5fce90705..324b4638a 100644 --- a/app/pe/pe_jurype.py +++ b/app/pe/pe_jurype.py @@ -52,10 +52,10 @@ from app.scodoc import sco_cache from app.scodoc import sco_codes_parcours # sco_codes_parcours.NEXT -> sem suivant from app.scodoc import sco_etud from app.scodoc import sco_formsemestre -from app.scodoc import pe_tagtable -from app.scodoc import pe_tools -from app.scodoc import pe_semestretag -from app.scodoc import pe_settag +from app.pe import pe_tagtable +from app.pe import pe_tools +from app.pe import pe_semestretag +from app.pe import pe_settag # ---------------------------------------------------------------------------------------- def comp_nom_semestre_dans_parcours(sem): diff --git a/app/pe/pe_semestretag.py b/app/pe/pe_semestretag.py index 80e256201..a6729def9 100644 --- a/app/pe/pe_semestretag.py +++ b/app/pe/pe_semestretag.py @@ -40,7 +40,7 @@ from app import log from app.scodoc import sco_codes_parcours from app.scodoc import sco_cache from app.scodoc import sco_tag_module -from app.scodoc import pe_tagtable +from app.pe import pe_tagtable class SemestreTag(pe_tagtable.TableTag): diff --git a/app/pe/pe_settag.py b/app/pe/pe_settag.py index 05eba20f2..8fde8d20a 100644 --- a/app/pe/pe_settag.py +++ b/app/pe/pe_settag.py @@ -36,8 +36,8 @@ Created on Fri Sep 9 09:15:05 2016 @author: barasc """ -from app.scodoc.pe_tools import pe_print, PE_DEBUG -from app.scodoc import pe_tagtable +from app.pe.pe_tools import pe_print, PE_DEBUG +from app.pe import pe_tagtable class SetTag(pe_tagtable.TableTag): diff --git a/app/pe/pe_view.py b/app/pe/pe_view.py index fa98e1d39..f44e13861 100644 --- a/app/pe/pe_view.py +++ b/app/pe/pe_view.py @@ -42,9 +42,9 @@ from app.scodoc import sco_formsemestre from app.scodoc import html_sco_header from app.scodoc import sco_preferences -from app.scodoc import pe_tools -from app.scodoc import pe_jurype -from app.scodoc import pe_avislatex +from app.pe import pe_tools +from app.pe import pe_jurype +from app.pe import pe_avislatex def _pe_view_sem_recap_form(formsemestre_id): From 9ee7dec20293204440aeb63a38ba88b3b223ecf6 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sun, 26 Sep 2021 23:27:54 +0200 Subject: [PATCH 3/6] deal with binary files (zip) --- app/pe/pe_tools.py | 5 +++-- app/scodoc/gen_tables.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/pe/pe_tools.py b/app/pe/pe_tools.py index ae00f4acc..4df97cfcb 100644 --- a/app/pe/pe_tools.py +++ b/app/pe/pe_tools.py @@ -164,11 +164,12 @@ def list_directory_filenames(path): return R -def add_local_file_to_zip(zipfile, ziproot, pathname, path_in_zip): +def add_local_file_to_zip(zipfile, ziproot, pathname, path_in_zip, mode='r'): """Read pathname server file and add content to zip under path_in_zip""" rooted_path_in_zip = os.path.join(ziproot, path_in_zip) - data = open(pathname).read() breakpoint() + with open(rooted_path_in_zip, mode=mode) as f: + data = f.read() zipfile.writestr(rooted_path_in_zip, data) diff --git a/app/scodoc/gen_tables.py b/app/scodoc/gen_tables.py index b49ab5dae..f6ac6c343 100644 --- a/app/scodoc/gen_tables.py +++ b/app/scodoc/gen_tables.py @@ -471,7 +471,10 @@ class GenTable(object): def excel(self, wb=None): """Simple Excel representation of the table""" - ses = sco_excel.ScoExcelSheet(sheet_name=self.xls_sheet_name, wb=wb) + if wb is None: + ses = sco_excel.ScoExcelSheet(sheet_name=self.xls_sheet_name, wb=wb) + else: + ses = wb.create_sheet(sheet_name=self.xls_sheet_name) ses.rows += self.xls_before_table style_bold = sco_excel.excel_make_style(bold=True) style_base = sco_excel.excel_make_style() @@ -486,8 +489,6 @@ class GenTable(object): ses.append_single_cell_row(self.origin, style_base) if wb is None: return ses.generate() - else: - ses.generate() def text(self): "raw text representation of the table" From 230c7d488e89d01a85edd29152ec7bab6572b2b7 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Mon, 27 Sep 2021 07:16:30 +0200 Subject: [PATCH 4/6] =?UTF-8?q?fonctionnel=20-=20a=20am=C3=A9liorer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/pe/pe_tools.py | 13 +++++-------- app/pe/pe_view.py | 23 +++++------------------ 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/app/pe/pe_tools.py b/app/pe/pe_tools.py index 4df97cfcb..d54de1d85 100644 --- a/app/pe/pe_tools.py +++ b/app/pe/pe_tools.py @@ -53,8 +53,6 @@ if not PE_DEBUG: def pe_print(*a, **kw): # kw is ignored. log always add a newline log(" ".join(a)) - - else: pe_print = print # print function @@ -164,13 +162,12 @@ def list_directory_filenames(path): return R -def add_local_file_to_zip(zipfile, ziproot, pathname, path_in_zip, mode='r'): +def add_local_file_to_zip(zipfile, ziproot, pathname, path_in_zip): """Read pathname server file and add content to zip under path_in_zip""" rooted_path_in_zip = os.path.join(ziproot, path_in_zip) - breakpoint() - with open(rooted_path_in_zip, mode=mode) as f: - data = f.read() - zipfile.writestr(rooted_path_in_zip, data) + zipfile.write(filename=pathname, arcname=rooted_path_in_zip) + # data = open(pathname).read() + # zipfile.writestr(rooted_path_in_zip, data) def add_pe_stuff_to_zip(zipfile, ziproot): @@ -211,7 +208,7 @@ def add_pe_stuff_to_zip(zipfile, ziproot): for f in logos_names: logo = os.path.join(scu.SCODOC_LOGOS_DIR, f) if os.path.isfile(logo): - add_local_file_to_zip(zipfile, ziproot, logo, "avis/logos/" + f, mode='rb') + add_local_file_to_zip(zipfile, ziproot, logo, "avis/logos/" + f) # ---------------------------------------------------------------------------------------- diff --git a/app/pe/pe_view.py b/app/pe/pe_view.py index f44e13861..15f8f6f88 100644 --- a/app/pe/pe_view.py +++ b/app/pe/pe_view.py @@ -89,7 +89,6 @@ def pe_view_sem_recap( semBase = sco_formsemestre.get_formsemestre(formsemestre_id) jury = pe_jurype.JuryPE(semBase) - # Ajout avis LaTeX au même zip: etudids = list(jury.syntheseJury.keys()) @@ -118,15 +117,11 @@ def pe_view_sem_recap( footer_latex = footer_tmpl_file.read() footer_latex = footer_latex else: - footer_latex = pe_avislatex.get_code_latex_from_scodoc_preference( - formsemestre_id, champ="pe_avis_latex_footer" - ) + footer_latex = pe_avislatex.get_code_latex_from_scodoc_preference(formsemestre_id, champ="pe_avis_latex_footer") footer_latex = footer_latex.strip() if not footer_latex: # pas de preference pour le footer: utilise fichier du serveur - footer_latex = pe_avislatex.get_templates_from_distrib( - "footer" - ) # fallback: footer vides + footer_latex = pe_avislatex.get_templates_from_distrib("footer") # fallback: footer vides tag_annotation_pe = pe_avislatex.get_code_latex_from_scodoc_preference( formsemestre_id, champ="pe_tag_annotation_avis_latex" @@ -135,9 +130,7 @@ def pe_view_sem_recap( # Ajout des annotations PE dans un fichier excel sT = pe_avislatex.table_syntheseAnnotationPE(jury.syntheseJury, tag_annotation_pe) if sT: - jury.add_file_to_zip( - jury.NOM_EXPORT_ZIP + "_annotationsPE" + scu.XLSX_SUFFIX, sT.excel() - ) + jury.add_file_to_zip(jury.NOM_EXPORT_ZIP + "_annotationsPE" + scu.XLSX_SUFFIX, sT.excel()) latex_pages = {} # Dictionnaire de la forme nom_fichier => contenu_latex for etudid in etudids: @@ -149,17 +142,11 @@ def pe_view_sem_recap( footer_latex, prefs, ) - - jury.add_file_to_zip( - "avis/" + nom_fichier + ".tex", - contenu_latex, - ) + jury.add_file_to_zip("avis/" + nom_fichier + ".tex", contenu_latex) latex_pages[nom_fichier] = contenu_latex # Sauvegarde dans un dico # Nouvelle version : 1 fichier par étudiant avec 1 fichier appelant créée ci-dessous - doc_latex = "\n% -----\n".join( - ["\\include{" + nom + "}" for nom in sorted(latex_pages.keys())] - ) + doc_latex = "\n% -----\n".join(["\\include{" + nom + "}" for nom in sorted(latex_pages.keys())]) jury.add_file_to_zip("avis/avis_poursuite.tex", doc_latex) # Ajoute image, LaTeX class file(s) and modeles From ccd1a0daba9f5d4a68ce4b1d972da7137aa358de Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Mon, 27 Sep 2021 07:31:59 +0200 Subject: [PATCH 5/6] refactor templates to zip --- app/pe/pe_tools.py | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/app/pe/pe_tools.py b/app/pe/pe_tools.py index d54de1d85..2e7f03188 100644 --- a/app/pe/pe_tools.py +++ b/app/pe/pe_tools.py @@ -170,6 +170,15 @@ def add_local_file_to_zip(zipfile, ziproot, pathname, path_in_zip): # zipfile.writestr(rooted_path_in_zip, data) +def add_refs_to_register(register, directory): + """Ajoute les fichiers trouvés dans directory au registre (dictionaire) sous la forme + filename => pathname + """ + length = len(directory) + for pathname in list_directory_filenames(directory): + filename = pathname[length+1:] + register[filename] = pathname + def add_pe_stuff_to_zip(zipfile, ziproot): """Add auxiliary files to (already opened) zip Put all local files found under config/doc_poursuites_etudes/local @@ -178,30 +187,16 @@ def add_pe_stuff_to_zip(zipfile, ziproot): Also copy logos """ + register = {} + # first add standard (distrib references) distrib_dir = os.path.join(REP_DEFAULT_AVIS, "distrib") - distrib_pathnames = list_directory_filenames( - distrib_dir - ) # eg /opt/scodoc/tools/doc_poursuites_etudes/distrib/modeles/toto.tex - l = len(distrib_dir) - distrib_filenames = {x[l + 1 :] for x in distrib_pathnames} # eg modeles/toto.tex - + add_refs_to_register(register=register, directory=distrib_dir) + # then add local references (some oh them may overwrite distrib refs) local_dir = os.path.join(REP_LOCAL_AVIS, "local") - local_pathnames = list_directory_filenames(local_dir) - l = len(local_dir) - local_filenames = {x[l + 1 :] for x in local_pathnames} - - for filename in distrib_filenames | local_filenames: - if filename in local_filenames: - add_local_file_to_zip( - zipfile, ziproot, os.path.join(local_dir, filename), "avis/" + filename - ) - else: - add_local_file_to_zip( - zipfile, - ziproot, - os.path.join(distrib_dir, filename), - "avis/" + filename, - ) + add_refs_to_register(register=register, directory=local_dir) + # at this point register contains all refs (filename, pathname) to be saved + for filename, pathname in register.items(): + add_local_file_to_zip(zipfile, ziproot, pathname, "avis/" + filename) # Logos: (add to logos/ directory in zip) logos_names = ["logo_header.jpg", "logo_footer.jpg"] From bb47e89e97e0f607b110fd4e858d0c3ea17760c5 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Mon, 27 Sep 2021 07:46:35 +0200 Subject: [PATCH 6/6] lustrage (blak & pylint) ; test sur autres export excel: ok --- app/pe/pe_avislatex.py | 12 +++++++----- app/pe/pe_jurype.py | 2 +- app/pe/pe_tools.py | 5 ++++- app/pe/pe_view.py | 16 ++++++++++++---- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/pe/pe_avislatex.py b/app/pe/pe_avislatex.py index bdd7a64ca..b98218eea 100644 --- a/app/pe/pe_avislatex.py +++ b/app/pe/pe_avislatex.py @@ -367,9 +367,7 @@ def get_bilanParTag(donnees_etudiant, groupe="groupe"): code_latex += "\\hline \n" for (i, ligne_val) in enumerate(valeurs["note"]): titre = lignes[i] # règle le pb d'encodage - code_latex += ( - "\\textbf{" + titre + "} & " + " & ".join(ligne_val) + "\\\\ \n" - ) + code_latex += "\\textbf{" + titre + "} & " + " & ".join(ligne_val) + "\\\\ \n" code_latex += ( " & " + " & ".join( @@ -397,12 +395,16 @@ def get_avis_poursuite_par_etudiant( nom = jury.syntheseJury[etudid]["nom"].replace(" ", "-") prenom = jury.syntheseJury[etudid]["prenom"].replace(" ", "-") - nom_fichier = scu.sanitize_filename("avis_poursuite_%s_%s_%s" % (nom, prenom, etudid)) + nom_fichier = scu.sanitize_filename( + "avis_poursuite_%s_%s_%s" % (nom, prenom, etudid) + ) if pe_tools.PE_DEBUG: pe_tools.pe_print("fichier latex =" + nom_fichier, type(nom_fichier)) # Entete (commentaire) - contenu_latex = "%% ---- Etudiant: " + civilite_str + " " + nom + " " + prenom + "\n" + contenu_latex = ( + "%% ---- Etudiant: " + civilite_str + " " + nom + " " + prenom + "\n" + ) # les annnotations annotationPE = get_annotation_PE(etudid, tag_annotation_pe=tag_annotation_pe) diff --git a/app/pe/pe_jurype.py b/app/pe/pe_jurype.py index 324b4638a..a7d302ad8 100644 --- a/app/pe/pe_jurype.py +++ b/app/pe/pe_jurype.py @@ -946,7 +946,7 @@ class JuryPE(object): return list(taglist) def get_allTagInSyntheseJury(self): - """Extrait tous les tags du dictionnaire syntheseJury trié par ordre alphabétique. [] si aucun tag """ + """Extrait tous les tags du dictionnaire syntheseJury trié par ordre alphabétique. [] si aucun tag""" allTags = set() for nom in JuryPE.PARCOURS.keys(): allTags = allTags.union(set(self.get_allTagForAggregat(nom))) diff --git a/app/pe/pe_tools.py b/app/pe/pe_tools.py index 2e7f03188..aef083982 100644 --- a/app/pe/pe_tools.py +++ b/app/pe/pe_tools.py @@ -53,6 +53,8 @@ if not PE_DEBUG: def pe_print(*a, **kw): # kw is ignored. log always add a newline log(" ".join(a)) + + else: pe_print = print # print function @@ -176,9 +178,10 @@ def add_refs_to_register(register, directory): """ length = len(directory) for pathname in list_directory_filenames(directory): - filename = pathname[length+1:] + filename = pathname[length + 1 :] register[filename] = pathname + def add_pe_stuff_to_zip(zipfile, ziproot): """Add auxiliary files to (already opened) zip Put all local files found under config/doc_poursuites_etudes/local diff --git a/app/pe/pe_view.py b/app/pe/pe_view.py index 15f8f6f88..14efdada3 100644 --- a/app/pe/pe_view.py +++ b/app/pe/pe_view.py @@ -117,11 +117,15 @@ def pe_view_sem_recap( footer_latex = footer_tmpl_file.read() footer_latex = footer_latex else: - footer_latex = pe_avislatex.get_code_latex_from_scodoc_preference(formsemestre_id, champ="pe_avis_latex_footer") + footer_latex = pe_avislatex.get_code_latex_from_scodoc_preference( + formsemestre_id, champ="pe_avis_latex_footer" + ) footer_latex = footer_latex.strip() if not footer_latex: # pas de preference pour le footer: utilise fichier du serveur - footer_latex = pe_avislatex.get_templates_from_distrib("footer") # fallback: footer vides + footer_latex = pe_avislatex.get_templates_from_distrib( + "footer" + ) # fallback: footer vides tag_annotation_pe = pe_avislatex.get_code_latex_from_scodoc_preference( formsemestre_id, champ="pe_tag_annotation_avis_latex" @@ -130,7 +134,9 @@ def pe_view_sem_recap( # Ajout des annotations PE dans un fichier excel sT = pe_avislatex.table_syntheseAnnotationPE(jury.syntheseJury, tag_annotation_pe) if sT: - jury.add_file_to_zip(jury.NOM_EXPORT_ZIP + "_annotationsPE" + scu.XLSX_SUFFIX, sT.excel()) + jury.add_file_to_zip( + jury.NOM_EXPORT_ZIP + "_annotationsPE" + scu.XLSX_SUFFIX, sT.excel() + ) latex_pages = {} # Dictionnaire de la forme nom_fichier => contenu_latex for etudid in etudids: @@ -146,7 +152,9 @@ def pe_view_sem_recap( latex_pages[nom_fichier] = contenu_latex # Sauvegarde dans un dico # Nouvelle version : 1 fichier par étudiant avec 1 fichier appelant créée ci-dessous - doc_latex = "\n% -----\n".join(["\\include{" + nom + "}" for nom in sorted(latex_pages.keys())]) + doc_latex = "\n% -----\n".join( + ["\\include{" + nom + "}" for nom in sorted(latex_pages.keys())] + ) jury.add_file_to_zip("avis/avis_poursuite.tex", doc_latex) # Ajoute image, LaTeX class file(s) and modeles