forked from ScoDoc/DocScoDoc
Merge pull request 'with_pe_v2' (#137) from jmplace/ScoDoc-Lille:with_pe_v2 into master
Reviewed-on: https://scodoc.org/git/viennet/ScoDoc/pulls/137
This commit is contained in:
commit
4429ffd3c8
@ -33,8 +33,8 @@
|
|||||||
import os
|
import os
|
||||||
import codecs
|
import codecs
|
||||||
import re
|
import re
|
||||||
from app.pe import pe_jurype
|
|
||||||
from app.pe import pe_tagtable
|
from app.pe import pe_tagtable
|
||||||
|
from app.pe import pe_jurype
|
||||||
from app.pe import pe_tools
|
from app.pe import pe_tools
|
||||||
|
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
@ -48,7 +48,7 @@ from app.scodoc import sco_etud
|
|||||||
DEBUG = False # Pour debug et repérage des prints à changer en Log
|
DEBUG = False # Pour debug et repérage des prints à changer en Log
|
||||||
|
|
||||||
DONNEE_MANQUANTE = (
|
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:)
|
result: chaine unicode (EV:)
|
||||||
"""
|
"""
|
||||||
codelatexDebut = (
|
codelatexDebut = (
|
||||||
u"""
|
""""
|
||||||
\\begin{parcourstimeline}{**debut**}{**fin**}{**nbreSemestres**}{%d}
|
\\begin{parcourstimeline}{**debut**}{**fin**}{**nbreSemestres**}{%d}
|
||||||
"""
|
"""
|
||||||
% taille
|
% taille
|
||||||
)
|
)
|
||||||
|
|
||||||
modeleEvent = u"""
|
modeleEvent = """
|
||||||
\\parcoursevent{**nosem**}{**nomsem**}{**descr**}
|
\\parcoursevent{**nosem**}{**nomsem**}{**descr**}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
codelatexFin = u"""
|
codelatexFin = """
|
||||||
\\end{parcourstimeline}
|
\\end{parcourstimeline}
|
||||||
"""
|
"""
|
||||||
reslatex = codelatexDebut
|
reslatex = codelatexDebut
|
||||||
@ -125,13 +125,13 @@ def comp_latex_parcourstimeline(etudiant, promo, taille=17):
|
|||||||
for no_sem in range(etudiant["nbSemestres"]):
|
for no_sem in range(etudiant["nbSemestres"]):
|
||||||
descr = modeleEvent
|
descr = modeleEvent
|
||||||
nom_semestre_dans_parcours = parcours[no_sem]["nom_semestre_dans_parcours"]
|
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:
|
if no_sem % 2 == 0:
|
||||||
descr = descr.replace(u"**nomsem**", nom_semestre_dans_parcours)
|
descr = descr.replace("**nomsem**", nom_semestre_dans_parcours)
|
||||||
descr = descr.replace(u"**descr**", u"")
|
descr = descr.replace("**descr**", "")
|
||||||
else:
|
else:
|
||||||
descr = descr.replace(u"**nomsem**", u"")
|
descr = descr.replace("**nomsem**", "")
|
||||||
descr = descr.replace(u"**descr**", nom_semestre_dans_parcours)
|
descr = descr.replace("**descr**", nom_semestre_dans_parcours)
|
||||||
reslatex += descr
|
reslatex += descr
|
||||||
reslatex += codelatexFin
|
reslatex += codelatexFin
|
||||||
return reslatex
|
return reslatex
|
||||||
@ -166,7 +166,7 @@ def get_code_latex_avis_etudiant(
|
|||||||
result: chaine unicode
|
result: chaine unicode
|
||||||
"""
|
"""
|
||||||
if not donnees_etudiant or not un_avis_latex: # Cas d'un template vide
|
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)
|
# Le template latex (corps + footer)
|
||||||
code = un_avis_latex + "\n\n" + footer_latex
|
code = un_avis_latex + "\n\n" + footer_latex
|
||||||
@ -189,17 +189,17 @@ def get_code_latex_avis_etudiant(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# La macro parcourstimeline
|
# La macro parcourstimeline
|
||||||
elif tag_latex == u"parcourstimeline":
|
elif tag_latex == "parcourstimeline":
|
||||||
valeur = comp_latex_parcourstimeline(
|
valeur = comp_latex_parcourstimeline(
|
||||||
donnees_etudiant, donnees_etudiant["promo"]
|
donnees_etudiant, donnees_etudiant["promo"]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Le tag annotationPE
|
# Le tag annotationPE
|
||||||
elif tag_latex == u"annotation":
|
elif tag_latex == "annotation":
|
||||||
valeur = annotationPE
|
valeur = annotationPE
|
||||||
|
|
||||||
# Le tag bilanParTag
|
# Le tag bilanParTag
|
||||||
elif tag_latex == u"bilanParTag":
|
elif tag_latex == "bilanParTag":
|
||||||
valeur = get_bilanParTag(donnees_etudiant)
|
valeur = get_bilanParTag(donnees_etudiant)
|
||||||
|
|
||||||
# Les tags "simples": par ex. nom, prenom, civilite, ...
|
# Les tags "simples": par ex. nom, prenom, civilite, ...
|
||||||
@ -249,14 +249,14 @@ def get_annotation_PE(etudid, tag_annotation_pe):
|
|||||||
]["comment_u"]
|
]["comment_u"]
|
||||||
|
|
||||||
annotationPE = exp.sub(
|
annotationPE = exp.sub(
|
||||||
u"", annotationPE
|
"", annotationPE
|
||||||
) # Suppression du tag d'annotation PE
|
) # 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(
|
annotationPE = annotationPE.replace(
|
||||||
u"<br/>", u"\n\n"
|
"<br/>", "\n\n"
|
||||||
) # Interprète les retours chariots html
|
) # Interprète les retours chariots html
|
||||||
return annotationPE
|
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]
|
donnees_numeriques = donnees_etudiant[aggregat][groupe][tag_scodoc]
|
||||||
if champ == "rang":
|
if champ == "rang":
|
||||||
valeur = u"%s/%d" % (
|
valeur = "%s/%d" % (
|
||||||
donnees_numeriques[
|
donnees_numeriques[
|
||||||
pe_tagtable.TableTag.FORMAT_DONNEES_ETUDIANTS.index("rang")
|
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(
|
if isinstance(
|
||||||
donnees_numeriques[indice_champ], float
|
donnees_numeriques[indice_champ], float
|
||||||
): # valeur numérique avec formattage unicode
|
): # valeur numérique avec formattage unicode
|
||||||
valeur = u"%2.2f" % donnees_numeriques[indice_champ]
|
valeur = "%2.2f" % donnees_numeriques[indice_champ]
|
||||||
else:
|
else:
|
||||||
valeur = u"%s" % donnees_numeriques[indice_champ]
|
valeur = "%s" % donnees_numeriques[indice_champ]
|
||||||
|
|
||||||
return valeur
|
return valeur
|
||||||
|
|
||||||
@ -356,29 +356,27 @@ def get_bilanParTag(donnees_etudiant, groupe="groupe"):
|
|||||||
("\\textit{" + rang + "}") if note else ""
|
("\\textit{" + rang + "}") if note else ""
|
||||||
) # rang masqué si pas de notes
|
) # rang masqué si pas de notes
|
||||||
|
|
||||||
code_latex = u"\\begin{tabular}{|c|" + "|c" * (len(entete)) + "|}\n"
|
code_latex = "\\begin{tabular}{|c|" + "|c" * (len(entete)) + "|}\n"
|
||||||
code_latex += u"\\hline \n"
|
code_latex += "\\hline \n"
|
||||||
code_latex += (
|
code_latex += (
|
||||||
u" & "
|
" & "
|
||||||
+ " & ".join(["\\textbf{" + intitule + "}" for (agg, intitule, _) in entete])
|
+ " & ".join(["\\textbf{" + intitule + "}" for (agg, intitule, _) in entete])
|
||||||
+ " \\\\ \n"
|
+ " \\\\ \n"
|
||||||
)
|
)
|
||||||
code_latex += u"\\hline"
|
code_latex += "\\hline"
|
||||||
code_latex += u"\\hline \n"
|
code_latex += "\\hline \n"
|
||||||
for (i, ligne_val) in enumerate(valeurs["note"]):
|
for (i, ligne_val) in enumerate(valeurs["note"]):
|
||||||
titre = lignes[i] # règle le pb d'encodage
|
titre = lignes[i] # règle le pb d'encodage
|
||||||
|
code_latex += "\\textbf{" + titre + "} & " + " & ".join(ligne_val) + "\\\\ \n"
|
||||||
code_latex += (
|
code_latex += (
|
||||||
u"\\textbf{" + titre + u"} & " + " & ".join(ligne_val) + u"\\\\ \n"
|
" & "
|
||||||
)
|
+ " & ".join(
|
||||||
code_latex += (
|
["{\\scriptsize " + clsmt + "}" for clsmt in valeurs["rang"][i]]
|
||||||
u" & "
|
|
||||||
+ u" & ".join(
|
|
||||||
[u"{\\scriptsize " + clsmt + u"}" for clsmt in valeurs["rang"][i]]
|
|
||||||
)
|
)
|
||||||
+ u"\\\\ \n"
|
+ "\\\\ \n"
|
||||||
)
|
)
|
||||||
code_latex += u"\\hline \n"
|
code_latex += "\\hline \n"
|
||||||
code_latex += u"\\end{tabular}"
|
code_latex += "\\end{tabular}"
|
||||||
|
|
||||||
return code_latex
|
return code_latex
|
||||||
|
|
||||||
@ -397,21 +395,15 @@ def get_avis_poursuite_par_etudiant(
|
|||||||
nom = jury.syntheseJury[etudid]["nom"].replace(" ", "-")
|
nom = jury.syntheseJury[etudid]["nom"].replace(" ", "-")
|
||||||
prenom = jury.syntheseJury[etudid]["prenom"].replace(" ", "-")
|
prenom = jury.syntheseJury[etudid]["prenom"].replace(" ", "-")
|
||||||
|
|
||||||
nom_fichier = (
|
nom_fichier = scu.sanitize_filename(
|
||||||
u"avis_poursuite_"
|
"avis_poursuite_%s_%s_%s" % (nom, prenom, etudid)
|
||||||
+ pe_tools.remove_accents(nom)
|
|
||||||
+ "_"
|
|
||||||
+ pe_tools.remove_accents(prenom)
|
|
||||||
+ "_"
|
|
||||||
+ str(etudid)
|
|
||||||
)
|
)
|
||||||
if pe_tools.PE_DEBUG:
|
if pe_tools.PE_DEBUG:
|
||||||
pe_tools.pe_print("fichier latex =" + nom_fichier, type(nom_fichier))
|
pe_tools.pe_print("fichier latex =" + nom_fichier, type(nom_fichier))
|
||||||
|
|
||||||
# Entete (commentaire)
|
# Entete (commentaire)
|
||||||
|
|
||||||
contenu_latex = (
|
contenu_latex = (
|
||||||
u"%% ---- Etudiant: " + civilite_str + " " + nom + " " + prenom + u"\n"
|
"%% ---- Etudiant: " + civilite_str + " " + nom + " " + prenom + "\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
# les annnotations
|
# les annnotations
|
||||||
|
@ -1149,12 +1149,10 @@ class JuryPE(object):
|
|||||||
|
|
||||||
# **********************************************
|
# **********************************************
|
||||||
def calcul_anneePromoDUT_d_un_etudiant(self, etudid):
|
def calcul_anneePromoDUT_d_un_etudiant(self, etudid):
|
||||||
"""Calcule et renvoie la date de diplome prévue pour un étudiant fourni
|
"""Calcule et renvoie la date de diplome prévue pour un étudiant fourni avec son etudid
|
||||||
avec son etudid en fonction de sesSemestres de scolarisation
|
en fonction de sesSemestres de scolarisation"""
|
||||||
et -1 s'il n'y a pas de semestre.
|
|
||||||
"""
|
|
||||||
sesSemestres = self.get_semestresDUT_d_un_etudiant(etudid)
|
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
|
# Fonctions d'affichage pour debug
|
||||||
|
@ -167,8 +167,19 @@ def list_directory_filenames(path):
|
|||||||
def add_local_file_to_zip(zipfile, ziproot, pathname, path_in_zip):
|
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"""
|
"""Read pathname server file and add content to zip under path_in_zip"""
|
||||||
rooted_path_in_zip = os.path.join(ziproot, path_in_zip)
|
rooted_path_in_zip = os.path.join(ziproot, path_in_zip)
|
||||||
data = open(pathname).read()
|
zipfile.write(filename=pathname, arcname=rooted_path_in_zip)
|
||||||
zipfile.writestr(rooted_path_in_zip, data)
|
# data = open(pathname).read()
|
||||||
|
# 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):
|
def add_pe_stuff_to_zip(zipfile, ziproot):
|
||||||
@ -179,30 +190,16 @@ def add_pe_stuff_to_zip(zipfile, ziproot):
|
|||||||
|
|
||||||
Also copy logos
|
Also copy logos
|
||||||
"""
|
"""
|
||||||
|
register = {}
|
||||||
|
# first add standard (distrib references)
|
||||||
distrib_dir = os.path.join(REP_DEFAULT_AVIS, "distrib")
|
distrib_dir = os.path.join(REP_DEFAULT_AVIS, "distrib")
|
||||||
distrib_pathnames = list_directory_filenames(
|
add_refs_to_register(register=register, directory=distrib_dir)
|
||||||
distrib_dir
|
# then add local references (some oh them may overwrite distrib refs)
|
||||||
) # 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
|
|
||||||
|
|
||||||
local_dir = os.path.join(REP_LOCAL_AVIS, "local")
|
local_dir = os.path.join(REP_LOCAL_AVIS, "local")
|
||||||
local_pathnames = list_directory_filenames(local_dir)
|
add_refs_to_register(register=register, directory=local_dir)
|
||||||
l = len(local_dir)
|
# at this point register contains all refs (filename, pathname) to be saved
|
||||||
local_filenames = {x[l + 1 :] for x in local_pathnames}
|
for filename, pathname in register.items():
|
||||||
|
add_local_file_to_zip(zipfile, ziproot, pathname, "avis/" + filename)
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Logos: (add to logos/ directory in zip)
|
# Logos: (add to logos/ directory in zip)
|
||||||
logos_names = ["logo_header.jpg", "logo_footer.jpg"]
|
logos_names = ["logo_header.jpg", "logo_footer.jpg"]
|
||||||
|
@ -43,7 +43,6 @@ from app.scodoc import html_sco_header
|
|||||||
from app.scodoc import sco_preferences
|
from app.scodoc import sco_preferences
|
||||||
|
|
||||||
from app.pe import pe_tools
|
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_jurype
|
||||||
from app.pe import pe_avislatex
|
from app.pe import pe_avislatex
|
||||||
|
|
||||||
@ -90,7 +89,6 @@ def pe_view_sem_recap(
|
|||||||
semBase = sco_formsemestre.get_formsemestre(formsemestre_id)
|
semBase = sco_formsemestre.get_formsemestre(formsemestre_id)
|
||||||
|
|
||||||
jury = pe_jurype.JuryPE(semBase)
|
jury = pe_jurype.JuryPE(semBase)
|
||||||
|
|
||||||
# Ajout avis LaTeX au même zip:
|
# Ajout avis LaTeX au même zip:
|
||||||
etudids = list(jury.syntheseJury.keys())
|
etudids = list(jury.syntheseJury.keys())
|
||||||
|
|
||||||
@ -150,18 +148,14 @@ def pe_view_sem_recap(
|
|||||||
footer_latex,
|
footer_latex,
|
||||||
prefs,
|
prefs,
|
||||||
)
|
)
|
||||||
|
jury.add_file_to_zip("avis/" + nom_fichier + ".tex", contenu_latex)
|
||||||
jury.add_file_to_zip(
|
|
||||||
("avis/" + nom_fichier + ".tex").encode(PE_LATEX_ENCODING),
|
|
||||||
contenu_latex.encode(PE_LATEX_ENCODING),
|
|
||||||
)
|
|
||||||
latex_pages[nom_fichier] = contenu_latex # Sauvegarde dans un dico
|
latex_pages[nom_fichier] = contenu_latex # Sauvegarde dans un dico
|
||||||
|
|
||||||
# Nouvelle version : 1 fichier par étudiant avec 1 fichier appelant créée ci-dessous
|
# Nouvelle version : 1 fichier par étudiant avec 1 fichier appelant créée ci-dessous
|
||||||
doc_latex = "\n% -----\n".join(
|
doc_latex = "\n% -----\n".join(
|
||||||
["\\include{" + nom + "}" for nom in sorted(latex_pages.keys())]
|
["\\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
|
# Ajoute image, LaTeX class file(s) and modeles
|
||||||
pe_tools.add_pe_stuff_to_zip(jury.zipfile, jury.NOM_EXPORT_ZIP)
|
pe_tools.add_pe_stuff_to_zip(jury.zipfile, jury.NOM_EXPORT_ZIP)
|
||||||
|
@ -471,7 +471,10 @@ class GenTable(object):
|
|||||||
|
|
||||||
def excel(self, wb=None):
|
def excel(self, wb=None):
|
||||||
"""Simple Excel representation of the table"""
|
"""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
|
ses.rows += self.xls_before_table
|
||||||
style_bold = sco_excel.excel_make_style(bold=True)
|
style_bold = sco_excel.excel_make_style(bold=True)
|
||||||
style_base = sco_excel.excel_make_style()
|
style_base = sco_excel.excel_make_style()
|
||||||
@ -486,8 +489,6 @@ class GenTable(object):
|
|||||||
ses.append_single_cell_row(self.origin, style_base)
|
ses.append_single_cell_row(self.origin, style_base)
|
||||||
if wb is None:
|
if wb is None:
|
||||||
return ses.generate()
|
return ses.generate()
|
||||||
else:
|
|
||||||
ses.generate()
|
|
||||||
|
|
||||||
def text(self):
|
def text(self):
|
||||||
"raw text representation of the table"
|
"raw text representation of the table"
|
||||||
|
Loading…
Reference in New Issue
Block a user