ScoDoc-Lille/app/pe/pe_view.py

175 lines
6.6 KiB
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
2022-01-01 14:49:42 +01:00
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
2020-09-26 16:19:37 +02:00
#
# 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
#
##############################################################################
##############################################################################
# Module "Avis de poursuite d'étude"
# conçu et développé par Cléo Baras (IUT de Grenoble)
##############################################################################
"""ScoDoc : interface des fonctions de gestion des avis de poursuites d'étude
"""
2021-08-31 20:18:50 +02:00
from flask import send_file, request
2022-03-01 10:21:15 +01:00
from app.scodoc.sco_exceptions import ScoValueError
2021-08-31 20:18:50 +02:00
import app.scodoc.sco_utils as scu
from app.scodoc import sco_formsemestre
from app.scodoc import html_sco_header
from app.scodoc import sco_preferences
2021-09-26 10:01:20 +02:00
from app.pe import pe_tools
from app.pe import pe_jurype
from app.pe import pe_avislatex
2020-09-26 16:19:37 +02:00
2021-08-31 20:18:50 +02:00
def _pe_view_sem_recap_form(formsemestre_id):
2020-09-26 16:19:37 +02:00
H = [
html_sco_header.sco_header(page_title="Avis de poursuite d'études"),
2020-09-26 16:19:37 +02:00
"""<h2 class="formsemestre">Génération des avis de poursuites d'études</h2>
<p class="help">
Cette fonction génère un ensemble de fichiers permettant d'éditer des avis de poursuites d'études.
<br/>
De nombreux aspects sont paramétrables:
2021-07-25 16:53:10 +02:00
<a href="https://scodoc.org/AvisPoursuiteEtudes" target="_blank" rel="noopener noreferrer">
2020-09-26 16:19:37 +02:00
voir la documentation</a>.
</p>
<form method="post" action="pe_view_sem_recap" id="pe_view_sem_recap_form" enctype="multipart/form-data">
<div class="pe_template_up">
Les templates sont généralement installés sur le serveur ou dans le paramétrage de ScoDoc.<br/>
Au besoin, vous pouvez spécifier ici votre propre fichier de template (<tt>un_avis.tex</tt>):
<div class="pe_template_upb">Template: <input type="file" size="30" name="avis_tmpl_file"/></div>
<div class="pe_template_upb">Pied de page: <input type="file" size="30" name="footer_tmpl_file"/></div>
</div>
<input type="submit" value="Générer les documents"/>
<input type="hidden" name="formsemestre_id" value="{formsemestre_id}">
</form>
""".format(
formsemestre_id=formsemestre_id
),
]
return "\n".join(H) + html_sco_header.sco_footer()
2020-09-26 16:19:37 +02:00
2021-08-31 20:18:50 +02:00
# called from the web, POST or GET
2020-09-26 16:19:37 +02:00
def pe_view_sem_recap(
formsemestre_id,
avis_tmpl_file=None,
footer_tmpl_file=None,
):
2021-08-31 20:18:50 +02:00
"""Génération des avis de poursuite d'étude"""
if request.method == "GET":
return _pe_view_sem_recap_form(formsemestre_id)
prefs = sco_preferences.SemPreferences(formsemestre_id=formsemestre_id)
2020-09-26 16:19:37 +02:00
2021-08-19 10:28:35 +02:00
semBase = sco_formsemestre.get_formsemestre(formsemestre_id)
2020-09-26 16:19:37 +02:00
jury = pe_jurype.JuryPE(semBase)
2020-09-26 16:19:37 +02:00
# Ajout avis LaTeX au même zip:
2021-07-09 17:47:06 +02:00
etudids = list(jury.syntheseJury.keys())
2020-09-26 16:19:37 +02:00
# Récupération du template latex, du footer latex et du tag identifiant les annotations relatives aux PE
# (chaines unicodes, html non quoté)
template_latex = ""
# template fourni via le formulaire Web
if avis_tmpl_file:
2022-03-01 10:21:15 +01:00
try:
template_latex = avis_tmpl_file.read().decode("utf-8")
except UnicodeDecodeError as e:
raise ScoValueError(
"Données (template) invalides (caractères non UTF8 ?)"
) from e
2020-09-26 16:19:37 +02:00
else:
# template indiqué dans préférences ScoDoc ?
template_latex = pe_avislatex.get_code_latex_from_scodoc_preference(
formsemestre_id, champ="pe_avis_latex_tmpl"
2020-09-26 16:19:37 +02:00
)
template_latex = template_latex.strip()
if not template_latex:
# pas de preference pour le template: utilise fichier du serveur
template_latex = pe_avislatex.get_templates_from_distrib("avis")
# Footer:
footer_latex = ""
# template fourni via le formulaire Web
if footer_tmpl_file:
2022-03-01 10:21:15 +01:00
footer_latex = footer_tmpl_file.read().decode("utf-8")
2021-07-12 15:13:10 +02:00
footer_latex = footer_latex
2020-09-26 16:19:37 +02:00
else:
footer_latex = pe_avislatex.get_code_latex_from_scodoc_preference(
formsemestre_id, champ="pe_avis_latex_footer"
)
2020-09-26 16:19:37 +02:00
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
2020-09-26 16:19:37 +02:00
tag_annotation_pe = pe_avislatex.get_code_latex_from_scodoc_preference(
formsemestre_id, champ="pe_tag_annotation_avis_latex"
2020-09-26 16:19:37 +02:00
)
# Ajout des annotations PE dans un fichier excel
sT = pe_avislatex.table_syntheseAnnotationPE(jury.syntheseJury, tag_annotation_pe)
2020-09-26 16:19:37 +02:00
if sT:
jury.add_file_to_zip(
jury.NOM_EXPORT_ZIP + "_annotationsPE" + scu.XLSX_SUFFIX, sT.excel()
)
2020-09-26 16:19:37 +02:00
latex_pages = {} # Dictionnaire de la forme nom_fichier => contenu_latex
for etudid in etudids:
[nom_fichier, contenu_latex] = pe_avislatex.get_avis_poursuite_par_etudiant(
jury,
etudid,
template_latex,
tag_annotation_pe,
footer_latex,
prefs,
)
2021-09-27 07:16:30 +02:00
jury.add_file_to_zip("avis/" + nom_fichier + ".tex", contenu_latex)
2020-09-26 16:19:37 +02:00
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())]
)
2021-09-26 09:52:55 +02:00
jury.add_file_to_zip("avis/avis_poursuite.tex", doc_latex)
2020-09-26 16:19:37 +02:00
# Ajoute image, LaTeX class file(s) and modeles
pe_tools.add_pe_stuff_to_zip(jury.zipfile, jury.NOM_EXPORT_ZIP)
2020-09-26 16:19:37 +02:00
data = jury.get_zipped_data()
2021-08-31 20:18:50 +02:00
return send_file(
data,
mimetype="application/zip",
2021-08-31 23:31:36 +02:00
download_name=scu.sanitize_filename(jury.NOM_EXPORT_ZIP + ".zip"),
2021-08-31 20:18:50 +02:00
as_attachment=True,
)