1
0
forked from ScoDoc/ScoDoc

Templatification: progress

This commit is contained in:
Emmanuel Viennet 2024-08-18 18:40:11 +02:00 committed by Iziram
parent 405533798e
commit f136b80c84
13 changed files with 102 additions and 88 deletions

View File

@ -46,10 +46,8 @@ from app.scodoc.sco_config_actions import LogoInsert
from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_exceptions import ScoValueError
from app.scodoc.sco_logos import find_logo from app.scodoc.sco_logos import find_logo
JAVASCRIPTS = html_sco_header.BOOTSTRAP_JS + []
CSSSTYLES = html_sco_header.BOOTSTRAP_CSS CSSSTYLES = html_sco_header.BOOTSTRAP_CSS
JAVASCRIPTS = html_sco_header.BOOTSTRAP_JS
# class ItemForm(FlaskForm): # class ItemForm(FlaskForm):
# """Unused Generic class to document common behavior for classes # """Unused Generic class to document common behavior for classes

View File

@ -57,7 +57,6 @@ from reportlab.lib.units import cm
from flask import render_template 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_utils as scu
from app.scodoc import sco_excel from app.scodoc import sco_excel
from app.scodoc import sco_pdf from app.scodoc import sco_pdf

View File

@ -41,10 +41,8 @@ from app.scodoc import sco_groups
from app.scodoc import sco_trombino from app.scodoc import sco_trombino
from app.scodoc import sco_archives from app.scodoc import sco_archives
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
from app.scodoc.sco_exceptions import AccessDenied, ScoValueError from app.scodoc.sco_exceptions import AccessDenied
from app.scodoc.TrivialFormulator import TrivialFormulator from app.scodoc.TrivialFormulator import TrivialFormulator
from app.scodoc import html_sco_header
from app.scodoc import sco_etud
class EtudsArchiver(sco_archives.BaseArchiver): class EtudsArchiver(sco_archives.BaseArchiver):
@ -142,9 +140,6 @@ def etud_upload_file_form(etudid):
etud = Identite.get_etud(etudid) etud = Identite.get_etud(etudid)
H = [ H = [
html_sco_header.sco_header(
page_title=f"Chargement d'un document associé à {etud.nomprenom}",
),
f"""<h2>Chargement d'un document associé à {etud.nomprenom}</h2> f"""<h2>Chargement d'un document associé à {etud.nomprenom}</h2>
<p>Le fichier ne doit pas dépasser { <p>Le fichier ne doit pas dépasser {
@ -171,8 +166,12 @@ def etud_upload_file_form(etudid):
cancelbutton="Annuler", cancelbutton="Annuler",
) )
if tf[0] == 0: if tf[0] == 0:
return "\n".join(H) + tf[1] + html_sco_header.sco_footer() return render_template(
elif tf[0] == -1: "sco_page.j2",
title=f"Chargement d'un document associé à {etud.nomprenom}",
content="\n".join(H) + tf[1],
)
if tf[0] == -1:
return flask.redirect(etud.url_fiche()) return flask.redirect(etud.url_fiche())
data = tf[2]["datafile"].read() data = tf[2]["datafile"].read()
descr = tf[2]["description"] descr = tf[2]["description"]
@ -263,9 +262,6 @@ def etudarchive_generate_excel_sample(group_id=None):
def etudarchive_import_files_form(group_id): def etudarchive_import_files_form(group_id):
"""Formulaire pour importation fichiers d'un groupe""" """Formulaire pour importation fichiers d'un groupe"""
H = [ H = [
html_sco_header.sco_header(
page_title="Import de fichiers associés aux étudiants"
),
"""<h2 class="formsemestre">Téléchargement de fichier associés aux étudiants</h2> """<h2 class="formsemestre">Téléchargement de fichier associés aux étudiants</h2>
<p>Les fichiers associés (dossiers d'admission, certificats, ...), de <p>Les fichiers associés (dossiers d'admission, certificats, ...), de
types quelconques (pdf, doc, images) sont accessibles aux utilisateurs via types quelconques (pdf, doc, images) sont accessibles aux utilisateurs via
@ -292,7 +288,6 @@ def etudarchive_import_files_form(group_id):
""" """
% group_id, % group_id,
] ]
F = html_sco_header.sco_footer()
tf = TrivialFormulator( tf = TrivialFormulator(
request.base_url, request.base_url,
scu.get_request_args(), scu.get_request_args(),
@ -313,7 +308,11 @@ def etudarchive_import_files_form(group_id):
) )
if tf[0] == 0: if tf[0] == 0:
return "\n".join(H) + tf[1] + "</li></ol>" + F return render_template(
"sco_page.j2",
title="Import de fichiers associés aux étudiants",
content="\n".join(H) + tf[1] + "</li></ol>",
)
# retrouve le semestre à partir du groupe: # retrouve le semestre à partir du groupe:
group = sco_groups.get_group(group_id) group = sco_groups.get_group(group_id)
if tf[0] == -1: if tf[0] == -1:

View File

@ -309,7 +309,7 @@ def search_etud_by_name(term: str) -> list:
# ---------- Recherche sur plusieurs département # ---------- Recherche sur plusieurs département
def search_etud_in_accessible_depts( def search_etuds_in_accessible_depts(
expnom=None, expnom=None,
) -> tuple[list[list[Identite]], list[str]]: ) -> tuple[list[list[Identite]], list[str]]:
""" """
@ -330,14 +330,14 @@ def search_etud_in_accessible_depts(
return result, accessible_depts return result, accessible_depts
def table_etud_in_accessible_depts(expnom=None): def table_etuds_in_accessible_depts(expnom=None):
""" """
Page avec table étudiants trouvés, dans tous les departements. Page avec table étudiants trouvés, dans tous les departements.
Attention: nous sommes ici au niveau de ScoDoc, pas dans un département Attention: nous sommes ici au niveau de ScoDoc, pas dans un département
""" """
result, accessible_depts = search_etud_in_accessible_depts(expnom=expnom) result, accessible_depts = search_etuds_in_accessible_depts(expnom=expnom)
H = [ H = [
f"""<div class="table_etud_in_accessible_depts"> f"""<div class="table_etuds_in_accessible_depts">
<h3>Recherche multi-département de "<tt>{expnom}</tt>"</h3> <h3>Recherche multi-département de "<tt>{expnom}</tt>"</h3>
""", """,
] ]
@ -362,7 +362,7 @@ def table_etud_in_accessible_depts(expnom=None):
rows=rows, rows=rows,
html_sortable=True, html_sortable=True,
html_class="table_leftalign", html_class="table_leftalign",
# table_id="etud_in_accessible_depts", table_id="etuds_in_accessible_depts",
) )
H.append('<div class="table_etud_in_dept">') H.append('<div class="table_etud_in_dept">')
@ -382,8 +382,10 @@ def table_etud_in_accessible_depts(expnom=None):
</div> </div>
""" """
) )
return ( return render_template(
html_sco_header.scodoc_top_html_header(page_title="Choix d'un étudiant") "base.j2",
+ "\n".join(H) title="Choix d'un étudiant",
+ html_sco_header.standard_html_footer() content="\n".join(H),
javascripts=["DataTables/datatables.min.js"],
cssstyles=["DataTables/datatables.min.css"],
) )

View File

@ -46,7 +46,6 @@ from app.models import (
UniteEns, UniteEns,
Scolog, Scolog,
) )
from app.scodoc import html_sco_header
from app.scodoc import htmlutils from app.scodoc import htmlutils
from app.scodoc import sco_cache from app.scodoc import sco_cache
from app.scodoc import codes_cursus from app.scodoc import codes_cursus
@ -82,12 +81,8 @@ def moduleimpl_inscriptions_edit(
# -- check permission (and lock) # -- check permission (and lock)
if not modimpl.can_change_inscriptions(): if not modimpl.can_change_inscriptions():
return # can_change_inscriptions raises exception return # can_change_inscriptions raises exception
header = html_sco_header.sco_header(
page_title="Inscription au module",
)
footer = html_sco_header.sco_footer()
H = [ H = [
header,
f"""<h2>Inscriptions au module <a class="stdlink" href="{ f"""<h2>Inscriptions au module <a class="stdlink" href="{
url_for("notes.moduleimpl_status", scodoc_dept=g.scodoc_dept, url_for("notes.moduleimpl_status", scodoc_dept=g.scodoc_dept,
moduleimpl_id=moduleimpl_id) moduleimpl_id=moduleimpl_id)
@ -215,8 +210,9 @@ def moduleimpl_inscriptions_edit(
) )
) )
# #
H.append(footer) return render_template(
return "\n".join(H) "sco_page.j2", title="Inscriptions au module", content="\n".join(H)
)
def _make_menu(partitions: list[dict], title="", check="true") -> str: def _make_menu(partitions: list[dict], title="", check="true") -> str:

View File

@ -47,7 +47,6 @@ from app.models import (
) )
from app.scodoc import ( from app.scodoc import (
codes_cursus, codes_cursus,
html_sco_header,
htmlutils, htmlutils,
sco_archives_etud, sco_archives_etud,
sco_bac, sco_bac,
@ -628,8 +627,10 @@ def fiche_etud(etudid=None):
</div> </div>
""" """
) )
header = html_sco_header.sco_header( return render_template(
page_title=f"Fiche étudiant {etud.nomprenom}", "sco_page.j2",
content=tmpl % info,
title=f"Fiche étudiant {etud.nomprenom}",
cssstyles=[ cssstyles=[
"libjs/jQuery-tagEditor/jquery.tag-editor.css", "libjs/jQuery-tagEditor/jquery.tag-editor.css",
"css/jury_but.css", "css/jury_but.css",
@ -644,7 +645,6 @@ def fiche_etud(etudid=None):
"js/etud_debouche.js", "js/etud_debouche.js",
], ],
) )
return header + tmpl % info + html_sco_header.sco_footer()
def _format_adresse(adresse: Adresse | None) -> dict: def _format_adresse(adresse: Adresse | None) -> dict:
@ -874,10 +874,6 @@ def etud_info_html(etudid, with_photo="1", debug=False):
H += "</div>" H += "</div>"
if debug: if debug:
return ( return render_template("sco_page.j2", title="debug", content=H)
html_sco_header.standard_html_header()
+ H return H
+ html_sco_header.standard_html_footer()
)
else:
return H

View File

@ -483,7 +483,7 @@ span.dept_cache {
color: rgb(194, 5, 5); color: rgb(194, 5, 5);
} }
div.table_etud_in_accessible_depts { div.table_etuds_in_accessible_depts {
margin-left: 3em; margin-left: 3em;
margin-bottom: 2em; margin-bottom: 2em;
} }

View File

@ -10,6 +10,10 @@
{%- endblock metas %} {%- endblock metas %}
{%- block styles %} {%- block styles %}
<link type="text/css" rel="stylesheet"
href="{{scu.STATIC_DIR}}/libjs/jquery-ui-1.10.4.custom/css/smoothness/jquery-ui-1.10.4.custom.min.css" />
<link type="text/css" rel="stylesheet"
href="{{scu.STATIC_DIR}}/libjs/timepicker-1.3.5/jquery.timepicker.min.css" />
<!-- Bootstrap --> <!-- Bootstrap -->
<link href="{{scu.STATIC_DIR}}/libjs/bootstrap/css/bootstrap.css" rel="stylesheet"> <link href="{{scu.STATIC_DIR}}/libjs/bootstrap/css/bootstrap.css" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="{{scu.STATIC_DIR}}/libjs/bootstrap-multiselect-1.1.2/bootstrap-multiselect.min.css"> <link type="text/css" rel="stylesheet" href="{{scu.STATIC_DIR}}/libjs/bootstrap-multiselect-1.1.2/bootstrap-multiselect.min.css">

View File

@ -57,7 +57,7 @@
</ul> </ul>
</div> </div>
</div> </div>
</nav> </nav>
{% endblock %} {% endblock %}
@ -67,7 +67,7 @@
{# application content needs to be provided in the app_content block #} {# application content needs to be provided in the app_content block #}
<div class="container"> <div class="container">
{% block app_content %}{% endblock %} {% block app_content %}{{ content | safe }}{% endblock %}
</div> </div>
<script> <script>

View File

@ -3,10 +3,6 @@
{% block styles %} {% block styles %}
{{super()}} {{super()}}
<link type="text/css" rel="stylesheet"
href="{{scu.STATIC_DIR}}/libjs/jquery-ui-1.10.4.custom/css/smoothness/jquery-ui-1.10.4.custom.min.css" />
<link type="text/css" rel="stylesheet"
href="{{scu.STATIC_DIR}}/libjs/timepicker-1.3.5/jquery.timepicker.min.css" />
<link rel="stylesheet" href="{{scu.STATIC_DIR}}/css/scodoc.css"> <link rel="stylesheet" href="{{scu.STATIC_DIR}}/css/scodoc.css">
<link rel="stylesheet" href="{{scu.STATIC_DIR}}/css/scodoc97.css"> <link rel="stylesheet" href="{{scu.STATIC_DIR}}/css/scodoc97.css">
<link href="{{scu.STATIC_DIR}}/css/menu.css" rel="stylesheet" type="text/css" /> <link href="{{scu.STATIC_DIR}}/css/menu.css" rel="stylesheet" type="text/css" />

View File

@ -45,8 +45,8 @@
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<form action="{{url_for('scodoc.table_etud_in_accessible_depts')}}" method="POST"> <form action="{{url_for('scodoc.table_etuds_in_accessible_depts')}}">
<b>Chercher étudiant:</b> <b>Chercher étudiant&nbsp;:</b>
<input type="text" name="expnom" width="12" spellcheck="false" value=""> <input type="text" name="expnom" width="12" spellcheck="false" value="">
<input type="submit" value="Chercher"> <input type="submit" value="Chercher">
<br />(entrer une partie du nom ou le code NIP, cherche dans tous les départements autorisés) <br />(entrer une partie du nom ou le code NIP, cherche dans tous les départements autorisés)

View File

@ -45,7 +45,6 @@ from flask import (
url_for, url_for,
) )
from flask import request from flask import request
import flask_login
from flask_login.utils import login_required, current_user from flask_login.utils import login_required, current_user
from PIL import Image as PILImage from PIL import Image as PILImage
@ -54,13 +53,9 @@ from werkzeug.exceptions import BadRequest, NotFound
from app import db, log from app import db, log
from app import entreprises from app import entreprises
from app.auth.models import User, Role from app.auth.models import Role
from app.auth.cas import set_cas_configuration from app.auth.cas import set_cas_configuration
from app.decorators import ( from app.decorators import admin_required
admin_required,
scodoc7func,
scodoc,
)
from app.forms.generic import SimpleConfirmationForm from app.forms.generic import SimpleConfirmationForm
from app.forms.main import config_logos, config_main from app.forms.main import config_logos, config_main
from app.forms.main.activate_entreprises import ActivateEntreprisesForm from app.forms.main.activate_entreprises import ActivateEntreprisesForm
@ -112,9 +107,9 @@ def index():
) )
# Renvoie les url /ScoDoc/RT/ vers /ScoDoc/RT/Scolarite @bp.route("/ScoDoc/<string:scodoc_dept>/")
@bp.route("/ScoDoc/<scodoc_dept>/") def index_dept(scodoc_dept: str):
def index_dept(scodoc_dept): "Renvoie les url /ScoDoc/RT/ vers /ScoDoc/RT/Scolarite"
return redirect(url_for("scolar.index_html", scodoc_dept=scodoc_dept)) return redirect(url_for("scolar.index_html", scodoc_dept=scodoc_dept))
@ -518,11 +513,14 @@ def activate_entreprises():
) )
@bp.route("/ScoDoc/table_etud_in_accessible_depts", methods=["POST"]) @bp.route("/ScoDoc/table_etuds_in_accessible_depts")
@login_required @login_required
def table_etud_in_accessible_depts(): def table_etuds_in_accessible_depts():
"""recherche étudiants sur plusieurs départements""" """recherche étudiants sur plusieurs départements"""
return sco_find_etud.table_etud_in_accessible_depts(expnom=request.form["expnom"]) expnom = request.args.get("expnom")
if not expnom:
raise ScoValueError("paramètre manquant: expnom")
return sco_find_etud.table_etuds_in_accessible_depts(expnom=expnom)
# Fonction d'API accessible sans aucun authentification # Fonction d'API accessible sans aucun authentification

View File

@ -221,12 +221,7 @@ def create_user_form(user_name=None, edit=0, all_roles=True):
initvalues = {} initvalues = {}
edit = int(edit) edit = int(edit)
all_roles = int(all_roles) all_roles = int(all_roles)
H = [ H = []
html_sco_header.sco_header(
javascripts=["js/user_form.js"],
)
]
F = html_sco_header.sco_footer()
the_user: User = None the_user: User = None
if edit: if edit:
if not user_name: if not user_name:
@ -603,7 +598,11 @@ def create_user_form(user_name=None, edit=0, all_roles=True):
cancelbutton="Annuler", cancelbutton="Annuler",
) )
if tf[0] == 0: if tf[0] == 0:
return "\n".join(H) + "\n" + tf[1] + F return render_template(
"base.j2",
content="\n".join(H) + "\n" + tf[1],
javascripts=["js/user_form.js"],
)
elif tf[0] == -1: elif tf[0] == -1:
return flask.redirect(url_for("users.index_html", scodoc_dept=g.scodoc_dept)) return flask.redirect(url_for("users.index_html", scodoc_dept=g.scodoc_dept))
else: else:
@ -645,7 +644,12 @@ def create_user_form(user_name=None, edit=0, all_roles=True):
err_msg = f"identifiant {user_name} déjà utilisé" err_msg = f"identifiant {user_name} déjà utilisé"
if err_msg: if err_msg:
H.append(tf_error_message(f"""Erreur: {err_msg}""")) H.append(tf_error_message(f"""Erreur: {err_msg}"""))
return "\n".join(H) + "\n" + tf[1] + F return render_template(
"base.j2",
content="\n".join(H) + "\n" + tf[1],
javascripts=["js/user_form.js"],
)
if not edit_only_roles: if not edit_only_roles:
ok_modif, msg = sco_users.check_modif_user( ok_modif, msg = sco_users.check_modif_user(
edit, edit,
@ -660,8 +664,11 @@ def create_user_form(user_name=None, edit=0, all_roles=True):
) )
if not ok_modif: if not ok_modif:
H.append(tf_error_message(msg)) H.append(tf_error_message(msg))
return "\n".join(H) + "\n" + tf[1] + F return render_template(
"base.j2",
content="\n".join(H) + "\n" + tf[1],
javascripts=["js/user_form.js"],
)
if "date_expiration" in vals: if "date_expiration" in vals:
try: try:
if vals["date_expiration"]: if vals["date_expiration"]:
@ -670,12 +677,20 @@ def create_user_form(user_name=None, edit=0, all_roles=True):
) )
if vals["date_expiration"] < datetime.datetime.now(): if vals["date_expiration"] < datetime.datetime.now():
H.append(tf_error_message("date expiration passée")) H.append(tf_error_message("date expiration passée"))
return "\n".join(H) + "\n" + tf[1] + F return render_template(
"base.j2",
content="\n".join(H) + "\n" + tf[1],
javascripts=["js/user_form.js"],
)
else: else:
vals["date_expiration"] = None vals["date_expiration"] = None
except ValueError: except ValueError:
H.append(tf_error_message("date expiration invalide")) H.append(tf_error_message("date expiration invalide"))
return "\n".join(H) + "\n" + tf[1] + F return render_template(
"base.j2",
content="\n".join(H) + "\n" + tf[1],
javascripts=["js/user_form.js"],
)
if edit: # modif utilisateur (mais pas password ni user_name !) if edit: # modif utilisateur (mais pas password ni user_name !)
if (not can_choose_dept) and "dept" in vals: if (not can_choose_dept) and "dept" in vals:
@ -727,7 +742,11 @@ def create_user_form(user_name=None, edit=0, all_roles=True):
msg = tf_error_message( msg = tf_error_message(
"identifiant invalide (pas d'accents ni de caractères spéciaux)" "identifiant invalide (pas d'accents ni de caractères spéciaux)"
) )
return "\n".join(H) + msg + "\n" + tf[1] + F return render_template(
"base.j2",
content="\n".join(H) + msg + "\n" + tf[1],
javascripts=["js/user_form.js"],
)
# Traitement initial (mode) : 3 cas # Traitement initial (mode) : 3 cas
# cf énumération Mode # cf énumération Mode
# A: envoi de welcome + procedure de reset # A: envoi de welcome + procedure de reset
@ -754,12 +773,20 @@ def create_user_form(user_name=None, edit=0, all_roles=True):
msg = tf_error_message( msg = tf_error_message(
"""Les deux mots de passes ne correspondent pas !""" """Les deux mots de passes ne correspondent pas !"""
) )
return "\n".join(H) + msg + "\n" + tf[1] + F return render_template(
"base.j2",
content="\n".join(H) + msg + "\n" + tf[1],
javascripts=["js/user_form.js"],
)
if not is_valid_password(vals["password"]): if not is_valid_password(vals["password"]):
msg = tf_error_message( msg = tf_error_message(
"""Mot de passe trop simple, recommencez !""" """Mot de passe trop simple, recommencez !"""
) )
return "\n".join(H) + msg + "\n" + tf[1] + F return render_template(
"base.j2",
content="\n".join(H) + msg + "\n" + tf[1],
javascripts=["js/user_form.js"],
)
# Département: # Département:
if not can_choose_dept: if not can_choose_dept:
vals["dept"] = auth_dept vals["dept"] = auth_dept
@ -1000,13 +1027,12 @@ def form_change_password(user_name=None):
# check access # check access
if not can_handle_passwd(user): if not can_handle_passwd(user):
return "\n".join( return render_template(
[ "base.j2",
html_sco_header.sco_header(), content="<p>Vous n'avez pas la permission de changer ce mot de passe</p>",
"<p>Vous n'avez pas la permission de changer ce mot de passe</p>", title="Accès refusé",
html_sco_header.sco_footer(),
]
) )
form = ChangePasswordForm(user_name=user.user_name, email=user.email) form = ChangePasswordForm(user_name=user.user_name, email=user.email)
destination = url_for( destination = url_for(
"users.user_info_page", "users.user_info_page",