From 81fab97018e840e349e443a53d9afb613c465468 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 23 Feb 2024 19:03:02 +0100 Subject: [PATCH] 2 small fixes --- app/scodoc/sco_abs_billets.py | 6 +++--- app/scodoc/sco_abs_notification.py | 12 +++++++++--- app/scodoc/sco_bulletins_pdf.py | 16 +++++++++------- sco_version.py | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/scodoc/sco_abs_billets.py b/app/scodoc/sco_abs_billets.py index 4a9da0af8..330524736 100644 --- a/app/scodoc/sco_abs_billets.py +++ b/app/scodoc/sco_abs_billets.py @@ -124,9 +124,9 @@ def table_billets( else: billet_dict["nomprenom"] = billet.etudiant.nomprenom billet_dict["_nomprenom_order"] = billet.etudiant.sort_key - billet_dict[ - "_nomprenom_td_attrs" - ] = f'id="{billet.etudiant.id}" class="etudinfo"' + billet_dict["_nomprenom_td_attrs"] = ( + f'id="{billet.etudiant.id}" class="etudinfo"' + ) if with_links: billet_dict["_nomprenom_target"] = url_for( "scolar.fiche_etud", diff --git a/app/scodoc/sco_abs_notification.py b/app/scodoc/sco_abs_notification.py index c29dba2d0..ba729e278 100644 --- a/app/scodoc/sco_abs_notification.py +++ b/app/scodoc/sco_abs_notification.py @@ -34,7 +34,7 @@ Il suffit d'appeler abs_notify() après chaque ajout d'absence. import datetime from typing import Optional -from flask import g, url_for +from flask import flash, g, url_for from flask_mail import Message from app import db @@ -46,7 +46,6 @@ from app.models.etudiants import Identite from app.models.events import Scolog from app.models.formsemestre import FormSemestre import app.scodoc.notesdb as ndb -from app.scodoc import sco_etud from app.scodoc import sco_preferences from app.scodoc import sco_utils as scu @@ -283,10 +282,17 @@ def abs_notification_message( ) template = prefs["abs_notification_mail_tmpl"] + txt = "" if template: - txt = prefs["abs_notification_mail_tmpl"] % values + try: + txt = prefs["abs_notification_mail_tmpl"] % values + except KeyError: + flash("Mail non envoyé: format invalide (voir paramétrage)") + log("abs_notification_message: invalid key in abs_notification_mail_tmpl") + txt = "" else: log("abs_notification_message: empty template, not sending message") + if not txt: return None subject = f"""[ScoDoc] Trop d'absences pour {etud.nomprenom}""" diff --git a/app/scodoc/sco_bulletins_pdf.py b/app/scodoc/sco_bulletins_pdf.py index f3975e84b..80cee3a4d 100644 --- a/app/scodoc/sco_bulletins_pdf.py +++ b/app/scodoc/sco_bulletins_pdf.py @@ -65,7 +65,6 @@ from app.models import FormSemestre, Identite from app.scodoc import ( codes_cursus, sco_cache, - sco_groups_view, sco_pdf, sco_preferences, ) @@ -114,7 +113,8 @@ def assemble_bulletins_pdf( return data -def replacement_function(match): +def replacement_function(match) -> str: + "remplace logo par balise html img" balise = match.group(1) name = match.group(3) logo = find_logo(logoname=name, dept_id=g.scodoc_dept_id) @@ -235,12 +235,14 @@ def get_formsemestre_bulletins_pdf( ) etuds = formsemestre.get_inscrits(include_demdef=True, order=True) - if groups_infos is not None: + if groups_infos is None: + gr_key = "" + else: etudids = {m["etudid"] for m in groups_infos.members} etuds = [etud for etud in etuds if etud.id in etudids] - cache_key = ( - str(formsemestre_id) + "_" + version + "_" + groups_infos.get_groups_key() - ) + gr_key = groups_infos.get_groups_key() + + cache_key = str(formsemestre_id) + "_" + version + "_" + gr_key cached = sco_cache.SemBulletinsPDFCache.get(cache_key) if cached: return cached[1], cached[0] @@ -276,7 +278,7 @@ def get_formsemestre_bulletins_pdf( sco_pdf.PDFLOCK.release() # date_iso = time.strftime("%Y-%m-%d") - filename = "bul-%s-%s.pdf" % (formsemestre.titre_num(), date_iso) + filename = f"bul-{formsemestre.titre_num()}-{date_iso}.pdf" filename = scu.unescape_html(filename).replace(" ", "_").replace("&", "") # fill cache sco_cache.SemBulletinsPDFCache.set( diff --git a/sco_version.py b/sco_version.py index b8048a3b8..2b38021dc 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.6.943" +SCOVERSION = "9.6.944" SCONAME = "ScoDoc"