From ec108a445400ba0561e5b60dfe06281609c3a834 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 13 Jan 2022 21:13:09 +0100 Subject: [PATCH 1/4] geb_tables: meilleur msg erreur si template pdf invalide --- app/scodoc/gen_tables.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/scodoc/gen_tables.py b/app/scodoc/gen_tables.py index a9ed10aa..2ac3c398 100644 --- a/app/scodoc/gen_tables.py +++ b/app/scodoc/gen_tables.py @@ -58,6 +58,7 @@ from app.scodoc import sco_utils as scu from app.scodoc import sco_excel from app.scodoc import sco_pdf from app.scodoc import sco_xml +from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_pdf import SU from app import log @@ -539,17 +540,18 @@ class GenTable(object): # # titles = ["%s" % x for x in self.get_titles_list()] pdf_style_list = [] - Pt = [ - [Paragraph(SU(str(x)), CellStyle) for x in line] - for line in ( - self.get_data_list( - pdf_mode=True, - pdf_style_list=pdf_style_list, - with_titles=True, - omit_hidden_lines=True, - ) - ) - ] + data_list = self.get_data_list( + pdf_mode=True, + pdf_style_list=pdf_style_list, + with_titles=True, + omit_hidden_lines=True, + ) + try: + Pt = [ + [Paragraph(SU(str(x)), CellStyle) for x in line] for line in data_list + ] + except ValueError as exc: + raise ScoValueError(f"Erreur dans un format pdf:
{str(exc)}") from exc pdf_style_list += self.pdf_table_style T = Table(Pt, repeatRows=1, colWidths=self.pdf_col_widths, style=pdf_style_list) From 55bd15a67b8f4fc8a5159317bb810dba8e88f6ac Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 13 Jan 2022 21:36:56 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Fix:=20script=20migration=20si=20tables=20e?= =?UTF-8?q?ntreprises=20ScoDoc=207=20incoh=C3=A9rentes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/import_scodoc7_dept.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/import_scodoc7_dept.py b/tools/import_scodoc7_dept.py index cedf0a93..597b9baf 100644 --- a/tools/import_scodoc7_dept.py +++ b/tools/import_scodoc7_dept.py @@ -389,6 +389,7 @@ def convert_object( new_ref = None elif is_table and table_name in { "notes_semset_formsemestre", + "entreprise_contact", }: # pour anciennes installs où des relations n'avait pas été déclarées clés étrangères # eg: notes_semset_formsemestre.semset_id n'était pas une clé From b6cedbd6b62c38e964327a8dfffde44d69c4f089 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 13 Jan 2022 22:36:40 +0100 Subject: [PATCH 3/4] introducing ScoPDFFormatError for friendlier PDF errors --- app/scodoc/gen_tables.py | 4 ++-- app/scodoc/sco_exceptions.py | 15 +++++++++++++++ app/scodoc/sco_groups_view.py | 2 +- app/scodoc/sco_preferences.py | 2 +- app/scodoc/sco_trombino_tours.py | 6 +++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/scodoc/gen_tables.py b/app/scodoc/gen_tables.py index 2ac3c398..85554555 100644 --- a/app/scodoc/gen_tables.py +++ b/app/scodoc/gen_tables.py @@ -58,7 +58,7 @@ from app.scodoc import sco_utils as scu from app.scodoc import sco_excel from app.scodoc import sco_pdf from app.scodoc import sco_xml -from app.scodoc.sco_exceptions import ScoValueError +from app.scodoc.sco_exceptions import ScoPDFFormatError from app.scodoc.sco_pdf import SU from app import log @@ -551,7 +551,7 @@ class GenTable(object): [Paragraph(SU(str(x)), CellStyle) for x in line] for line in data_list ] except ValueError as exc: - raise ScoValueError(f"Erreur dans un format pdf:
{str(exc)}") from exc + raise ScoPDFFormatError(str(exc)) from exc pdf_style_list += self.pdf_table_style T = Table(Pt, repeatRows=1, colWidths=self.pdf_col_widths, style=pdf_style_list) diff --git a/app/scodoc/sco_exceptions.py b/app/scodoc/sco_exceptions.py index c563c93e..d975766e 100644 --- a/app/scodoc/sco_exceptions.py +++ b/app/scodoc/sco_exceptions.py @@ -60,6 +60,21 @@ class ScoFormatError(ScoValueError): pass +class ScoPDFFormatError(ScoValueError): + "erreur génération PDF (templates platypus, ...)" + + def __init__(self, msg, dest_url=None): + super().__init__( + f"""Erreur dans un format pdf: +

{msg}

+

Vérifiez les paramètres (polices de caractères, balisage) + dans les paramètres ou préférences. +

+ """, + dest_url=dest_url, + ) + + class ScoInvalidDept(ScoValueError): """departement invalide""" diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index 603627d1..df4c55e9 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -815,7 +815,7 @@ def tab_absences_html(groups_infos, etat=None): % (groups_infos.base_url, groups_infos.groups_titles), """
  • Trombinoscope en PDF
  • """ % groups_infos.groups_query_args, - """
  • Trombinoscope en PDF (format "IUT de Tours", beta)
  • """ + """
  • Trombinoscope en PDF (format "IUT de Tours")
  • """ % groups_infos.groups_query_args, """
  • Feuille relevé absences hebdomadaire (beta)
  • """ % groups_infos.groups_query_args, diff --git a/app/scodoc/sco_preferences.py b/app/scodoc/sco_preferences.py index da3e1a4e..b38fb736 100644 --- a/app/scodoc/sco_preferences.py +++ b/app/scodoc/sco_preferences.py @@ -762,7 +762,7 @@ class BasePreferences(object): { "initvalue": "Helvetica", "title": "Police de caractère principale", - "explanation": "pour les pdf", + "explanation": "pour les pdf (Helvetica est recommandée)", "size": 25, "category": "pdf", }, diff --git a/app/scodoc/sco_trombino_tours.py b/app/scodoc/sco_trombino_tours.py index e7f2266f..3861bb74 100644 --- a/app/scodoc/sco_trombino_tours.py +++ b/app/scodoc/sco_trombino_tours.py @@ -44,6 +44,7 @@ from app.scodoc import sco_groups_view from app.scodoc import sco_preferences from app.scodoc import sco_trombino from app.scodoc import sco_etud +from app.scodoc.sco_exceptions import ScoPDFFormatError from app.scodoc.sco_pdf import * @@ -268,7 +269,10 @@ def pdf_trombino_tours( preferences=sco_preferences.SemPreferences(), ) ) - document.build(objects) + try: + document.build(objects) + except (ValueError, KeyError) as exc: + raise ScoPDFFormatError(str(exc)) from exc data = report.getvalue() return scu.sendPDFFile(data, filename) From fa99cbf3d02a0ed6ed2c5c1e3b541aec181a537c Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 13 Jan 2022 23:30:25 +0100 Subject: [PATCH 4/4] =?UTF-8?q?Fix=20#269.=20Utilisateurs=20avec=20logins?= =?UTF-8?q?=20num=C3=A9riques.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/views/users.py b/app/views/users.py index af4a721e..cc9b9db0 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -151,6 +151,8 @@ def user_info(user_name, format="json"): @scodoc7func def create_user_form(user_name=None, edit=0, all_roles=1): "form. création ou edition utilisateur" + if user_name is not None: # scodoc7func converti en int ! + user_name = str(user_name) auth_dept = current_user.dept from_mail = current_user.email initvalues = {} @@ -745,6 +747,8 @@ def user_info_page(user_name=None): """ from app.scodoc.sco_permissions_check import can_handle_passwd + if user_name is not None: # scodoc7func converti en int ! + user_name = str(user_name) # peut on divulguer ces infos ? if not can_handle_passwd(current_user, allow_admindepts=True): raise AccessDenied("Vous n'avez pas la permission de voir cette page") @@ -753,7 +757,7 @@ def user_info_page(user_name=None): if not user_name: user = current_user else: - user = User.query.filter_by(user_name=str(user_name)).first() + user = User.query.filter_by(user_name=user_name).first() if not user: raise ScoValueError("invalid user_name") @@ -802,6 +806,8 @@ def form_change_password(user_name=None): """Formulaire de changement mot de passe de l'utilisateur user_name. Un utilisateur peut toujours changer son propre mot de passe. """ + if user_name is not None: # scodoc7func converti en int ! + user_name = str(user_name) if not user_name: user = current_user else: @@ -850,6 +856,8 @@ def form_change_password(user_name=None): @scodoc7func def change_password(user_name, password, password2): "Change the password for user given by user_name" + if user_name is not None: # scodoc7func converti en int ! + user_name = str(user_name) u = User.query.filter_by(user_name=user_name).first() # Check access permission if not can_handle_passwd(u): @@ -909,6 +917,8 @@ def change_password(user_name, password, password2): @permission_required(Permission.ScoUsersAdmin) def toggle_active_user(user_name: str = None): """Change active status of a user account""" + if user_name is not None: # scodoc7func converti en int ! + user_name = str(user_name) u = User.query.filter_by(user_name=user_name).first() if not u: raise ScoValueError("invalid user_name")