1
0
forked from ScoDoc/ScoDoc

Remplace sco_header par template.

This commit is contained in:
Emmanuel Viennet 2024-07-19 18:03:24 +02:00
parent 4de2d63861
commit 8f2a6aa317
12 changed files with 105 additions and 89 deletions

View File

@ -55,6 +55,8 @@ from reportlab.lib.colors import Color
from reportlab.lib import styles
from reportlab.lib.units import cm
from flask import render_template
from app.scodoc import html_sco_header
from app.scodoc import sco_utils as scu
from app.scodoc import sco_excel
@ -681,16 +683,15 @@ class GenTable:
fmt="html",
page_title="",
filename=None,
cssstyles=[],
javascripts=[],
javascripts=(),
with_html_headers=True,
publish=True,
init_qtip=False,
):
"""
Build page at given format
This is a simple page with only a title and the table.
If not publish, does not set response header
If not publish, do not set response header for non HTML formats.
If with_html_headers, render a full page using ScoDoc template.
"""
if not filename:
filename = self.filename
@ -698,21 +699,16 @@ class GenTable:
html_title = self.html_title or title
if fmt == "html":
H = []
if with_html_headers:
H.append(
self.html_header
or html_sco_header.sco_header(
cssstyles=cssstyles,
page_title=page_title,
javascripts=javascripts,
init_qtip=init_qtip,
)
)
if html_title:
H.append(html_title)
H.append(self.html())
if with_html_headers:
H.append(html_sco_header.sco_footer())
return render_template(
"sco_page.j2",
content="\n".join(H),
title=page_title,
javascripts=javascripts,
)
return "\n".join(H)
elif fmt == "pdf":
pdf_objs = self.pdf()

View File

@ -43,52 +43,15 @@ Pour chaque étudiant commun:
comparer les résultats
"""
from flask import g, url_for
from flask import g, render_template, url_for
from app import log
from app.scodoc import sco_apogee_csv, sco_apogee_reader
from app.scodoc.sco_apogee_csv import ApoData
from app.scodoc.gen_tables import GenTable
from app.scodoc.sco_exceptions import ScoValueError
from app.scodoc import html_sco_header
from app.scodoc import sco_preferences
_HELP_TXT = """
<div class="help">
<p>Outil de comparaison de fichiers (maquettes CSV) Apogée.
</p>
<p>Cet outil compare deux fichiers fournis. Aucune donnée stockée dans ScoDoc n'est utilisée.
</p>
</div>
"""
def apo_compare_csv_form():
"""Form: submit 2 CSV files to compare them."""
H = [
html_sco_header.sco_header(page_title="Comparaison de fichiers Apogée"),
"""<h2>Comparaison de fichiers Apogée</h2>
<form id="apo_csv_add" action="apo_compare_csv" method="post" enctype="multipart/form-data">
""",
_HELP_TXT,
"""
<div class="apo_compare_csv_form_but">
Fichier Apogée A:
<input type="file" size="30" name="file_a"/>
</div>
<div class="apo_compare_csv_form_but">
Fichier Apogée B:
<input type="file" size="30" name="file_b"/>
</div>
<input type="checkbox" name="autodetect" checked/>autodétecter encodage</input>
<div class="apo_compare_csv_form_submit">
<input type="submit" value="Comparer ces fichiers"/>
</div>
</form>""",
html_sco_header.sco_footer(),
]
return "\n".join(H)
def apo_compare_csv(file_a, file_b, autodetect=True):
"""Page comparing 2 Apogee CSV files"""
@ -114,17 +77,12 @@ def apo_compare_csv(file_a, file_b, autodetect=True):
""",
dest_url=dest_url,
) from exc
H = [
html_sco_header.sco_header(page_title="Comparaison de fichiers Apogée"),
"<h2>Comparaison de fichiers Apogée</h2>",
_HELP_TXT,
'<div class="apo_compare_csv">',
_apo_compare_csv(apo_data_a, apo_data_b),
"</div>",
"""<p><a href="apo_compare_csv_form" class="stdlink">Autre comparaison</a></p>""",
html_sco_header.sco_footer(),
]
return "\n".join(H)
return render_template(
"apogee/apo_compare_csv.j2",
title="Comparaison de fichiers Apogée",
content=_apo_compare_csv(apo_data_a, apo_data_b),
)
def _load_apo_data(csvfile, autodetect=True):

View File

@ -76,7 +76,6 @@ def report_debouche_date(start_year=None, fmt="html"):
tab.base_url = f"{request.base_url}?start_year={start_year}"
return tab.make_page(
title="""<h2 class="formsemestre">Débouchés étudiants </h2>""",
init_qtip=True,
javascripts=["js/etud_info.js"],
fmt=fmt,
with_html_headers=True,

View File

@ -754,4 +754,4 @@ def etuds_select_box_xls(src_cat):
table_id="etuds_select_box_xls",
titles=titles,
)
return tab.excel() # tab.make_page(filename=src_cat["infos"]["filename"])
return tab.excel()

View File

@ -30,7 +30,7 @@
import math
import datetime
from flask import g, url_for
from flask import g, render_template, url_for
from flask_login import current_user
from app import db
@ -45,7 +45,6 @@ from app.scodoc.codes_cursus import UE_SPORT
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_evaluations
from app.scodoc import sco_groups
@ -253,11 +252,6 @@ def moduleimpl_status(moduleimpl_id=None, partition_id=None):
module_resp = db.session.get(User, modimpl.responsable_id)
mod_type_name = scu.MODULE_TYPE_NAMES[module.module_type]
H = [
html_sco_header.sco_header(
page_title=f"{mod_type_name} {module.code} {module.titre}",
javascripts=["js/etud_info.js"],
init_qtip=True,
),
f"""<h2 class="formsemestre">{mod_type_name}
<tt>{module.code}</tt> {module.titre}
{"dans l'UE " + modimpl.module.ue.acronyme
@ -564,8 +558,11 @@ def moduleimpl_status(moduleimpl_id=None, partition_id=None):
</p>
"""
)
H.append(html_sco_header.sco_footer())
return "".join(H)
return render_template(
"sco_page.j2",
content="".join(H),
title=f"{mod_type_name} {module.code} {module.titre}",
)
def _ligne_evaluation(

View File

@ -233,7 +233,6 @@ def formsemestre_poursuite_report(formsemestre_id, fmt="html"):
tab.base_url = "%s?formsemestre_id=%s" % (request.base_url, formsemestre_id)
return tab.make_page(
title="""<h2 class="formsemestre">Poursuite d'études</h2>""",
init_qtip=True,
javascripts=["js/etud_info.js"],
fmt=fmt,
with_html_headers=True,

View File

@ -0,0 +1,15 @@
{% extends "sco_page.j2" %}
{% import 'wtf.j2' as wtf %}
{% block app_content %}
<h1>Comparaison de fichiers Apogée</h1>
<div class="help">
<p>Outil de comparaison de fichiers (maquettes CSV) Apogée.
</p>
<p>Cet outil compare deux fichiers fournis.
Aucune donnée stockée dans ScoDoc n'est utilisée ni modifiée.
</p>
</div>
{% endblock %}

View File

@ -0,0 +1,14 @@
{% extends "apogee/apo_compare.j2" %}
{% block app_content %}
{{super()}}
<div class="apo_compare_csv">
{{content|safe}}
</div>
<p>
<a href="apo_compare_csv_form" class="stdlink">Autre comparaison</a>
</p>
{% endblock %}

View File

@ -0,0 +1,23 @@
{% extends "apogee/apo_compare.j2" %}
{% block app_content %}
{{super()}}
<form id="apo_csv_add" action="apo_compare_csv" method="post" enctype="multipart/form-data">
<div class="apo_compare_csv_form_but">
Fichier Apogée A:
<input type="file" size="30" name="file_a"/>
</div>
<div class="apo_compare_csv_form_but">
Fichier Apogée B:
<input type="file" size="30" name="file_b"/>
</div>
<label>
<input type="checkbox" name="autodetect" checked/> autodétecter encodage
</label>
<div class="apo_compare_csv_form_submit">
<input type="submit" value="Comparer ces fichiers"/>
</div>
</form>
{% endblock %}

View File

@ -36,6 +36,9 @@
<script>
const SCO_TIMEZONE = "{{ scu.TIME_ZONE }}";
</script>
{% for js in javascripts %}
<script src="{{scu.STATIC_DIR}}/{{js}}"></script>
{% endfor %}
{%- endblock scripts %}
{%- endblock body %}
</body>

View File

@ -36,7 +36,7 @@
<div class="sco-app-content">
{% block app_content %}
page vide
{{ content | safe }}
{% endblock %}
</div>
</div>

View File

@ -2439,18 +2439,30 @@ sco_publish(
Permission.EditApogee,
)
sco_publish(
"/apo_compare_csv_form",
sco_apogee_compare.apo_compare_csv_form,
Permission.ScoView,
methods=["GET", "POST"],
)
sco_publish(
"/apo_compare_csv",
sco_apogee_compare.apo_compare_csv,
Permission.ScoView,
methods=["GET", "POST"],
)
@bp.route("/apo_compare_csv_form")
@scodoc
@permission_required(Permission.ScoView)
def apo_compare_csv_form():
"Choix de fichiers Apogée à comparer"
return render_template(
"apogee/apo_compare_form.j2", title="Comparaison de fichiers Apogée"
)
@bp.route("/apo_compare_csv", methods=["POST"])
@scodoc
@permission_required(Permission.ScoView)
def apo_compare_csv():
"Page comparaison 2 fichiers CSV"
try:
file_a = request.files["file_a"]
file_b = request.files["file_b"]
autodetect = request.form.get("autodetect", False)
except KeyError as exc:
raise ScoValueError("invalid arguments") from exc
return sco_apogee_compare.apo_compare_csv(file_a, file_b, autodetect=autodetect)
# ------------- INSCRIPTIONS: PASSAGE D'UN SEMESTRE A UN AUTRE
sco_publish(