From 8f2a6aa3177c5985748c0f75bf97d1fea10ecbcb Mon Sep 17 00:00:00 2001
From: Emmanuel Viennet
Date: Fri, 19 Jul 2024 18:03:24 +0200
Subject: [PATCH] Remplace sco_header par template.
---
app/scodoc/gen_tables.py | 26 +++++------
app/scodoc/sco_apogee_compare.py | 56 +++---------------------
app/scodoc/sco_debouche.py | 1 -
app/scodoc/sco_inscr_passage.py | 2 +-
app/scodoc/sco_moduleimpl_status.py | 15 +++----
app/scodoc/sco_poursuite_dut.py | 1 -
app/templates/apogee/apo_compare.j2 | 15 +++++++
app/templates/apogee/apo_compare_csv.j2 | 14 ++++++
app/templates/apogee/apo_compare_form.j2 | 23 ++++++++++
app/templates/babase.j2 | 3 ++
app/templates/sco_page.j2 | 2 +-
app/views/notes.py | 36 ++++++++++-----
12 files changed, 105 insertions(+), 89 deletions(-)
create mode 100644 app/templates/apogee/apo_compare.j2
create mode 100644 app/templates/apogee/apo_compare_csv.j2
create mode 100644 app/templates/apogee/apo_compare_form.j2
diff --git a/app/scodoc/gen_tables.py b/app/scodoc/gen_tables.py
index 2f13fdd8..9c2c2880 100644
--- a/app/scodoc/gen_tables.py
+++ b/app/scodoc/gen_tables.py
@@ -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()
diff --git a/app/scodoc/sco_apogee_compare.py b/app/scodoc/sco_apogee_compare.py
index 308403c1..c7b34d90 100644
--- a/app/scodoc/sco_apogee_compare.py
+++ b/app/scodoc/sco_apogee_compare.py
@@ -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 = """
-
-
Outil de comparaison de fichiers (maquettes CSV) Apogée.
-
-
Cet outil compare deux fichiers fournis. Aucune donnée stockée dans ScoDoc n'est utilisée.
-
-
-"""
-
-
-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"),
- """Comparaison de fichiers Apogée
- """,
- 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"),
- "Comparaison de fichiers Apogée
",
- _HELP_TXT,
- '',
- _apo_compare_csv(apo_data_a, apo_data_b),
- "
",
- """Autre comparaison
""",
- 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):
diff --git a/app/scodoc/sco_debouche.py b/app/scodoc/sco_debouche.py
index 18b62e89..a0c9d7a5 100644
--- a/app/scodoc/sco_debouche.py
+++ b/app/scodoc/sco_debouche.py
@@ -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="""""",
- init_qtip=True,
javascripts=["js/etud_info.js"],
fmt=fmt,
with_html_headers=True,
diff --git a/app/scodoc/sco_inscr_passage.py b/app/scodoc/sco_inscr_passage.py
index 2e1268ed..968c85d6 100644
--- a/app/scodoc/sco_inscr_passage.py
+++ b/app/scodoc/sco_inscr_passage.py
@@ -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()
diff --git a/app/scodoc/sco_moduleimpl_status.py b/app/scodoc/sco_moduleimpl_status.py
index 8fe8eb3f..565aa515 100644
--- a/app/scodoc/sco_moduleimpl_status.py
+++ b/app/scodoc/sco_moduleimpl_status.py
@@ -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"""
"""
)
- 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(
diff --git a/app/scodoc/sco_poursuite_dut.py b/app/scodoc/sco_poursuite_dut.py
index e3120763..628608a5 100644
--- a/app/scodoc/sco_poursuite_dut.py
+++ b/app/scodoc/sco_poursuite_dut.py
@@ -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="""""",
- init_qtip=True,
javascripts=["js/etud_info.js"],
fmt=fmt,
with_html_headers=True,
diff --git a/app/templates/apogee/apo_compare.j2 b/app/templates/apogee/apo_compare.j2
new file mode 100644
index 00000000..1ab0a7b2
--- /dev/null
+++ b/app/templates/apogee/apo_compare.j2
@@ -0,0 +1,15 @@
+{% extends "sco_page.j2" %}
+{% import 'wtf.j2' as wtf %}
+
+{% block app_content %}
+Comparaison de fichiers Apogée
+
+
+
Outil de comparaison de fichiers (maquettes CSV) Apogée.
+
+
Cet outil compare deux fichiers fournis.
+ Aucune donnée stockée dans ScoDoc n'est utilisée ni modifiée.
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/apogee/apo_compare_csv.j2 b/app/templates/apogee/apo_compare_csv.j2
new file mode 100644
index 00000000..48c2af34
--- /dev/null
+++ b/app/templates/apogee/apo_compare_csv.j2
@@ -0,0 +1,14 @@
+{% extends "apogee/apo_compare.j2" %}
+
+{% block app_content %}
+{{super()}}
+
+
+ {{content|safe}}
+
+
+
+ Autre comparaison
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/apogee/apo_compare_form.j2 b/app/templates/apogee/apo_compare_form.j2
new file mode 100644
index 00000000..713853a9
--- /dev/null
+++ b/app/templates/apogee/apo_compare_form.j2
@@ -0,0 +1,23 @@
+{% extends "apogee/apo_compare.j2" %}
+
+{% block app_content %}
+{{super()}}
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/babase.j2 b/app/templates/babase.j2
index ef58a1a7..690a460a 100644
--- a/app/templates/babase.j2
+++ b/app/templates/babase.j2
@@ -36,6 +36,9 @@
+ {% for js in javascripts %}
+
+ {% endfor %}
{%- endblock scripts %}
{%- endblock body %}