From ad46a190ab5fb61ac5244f4715f70d60212432c8 Mon Sep 17 00:00:00 2001
From: Emmanuel Viennet <emmanuel.viennet@gmail.com>
Date: Sun, 2 Oct 2022 20:44:24 +0200
Subject: [PATCH] minor code cleaning

---
 app/scodoc/TrivialFormulator.py |  7 ++-----
 app/scodoc/sco_preferences.py   | 32 +++++++++++++-------------------
 2 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/app/scodoc/TrivialFormulator.py b/app/scodoc/TrivialFormulator.py
index 522709151..0920ab0e5 100644
--- a/app/scodoc/TrivialFormulator.py
+++ b/app/scodoc/TrivialFormulator.py
@@ -543,11 +543,8 @@ class TF(object):
                 disabled_items = descr.get("disabled_items", {})
                 if vertical:
                     lem.append("<table>")
-                for i in range(len(labels)):
+                for i in range(len(labels)):  # pylint: disable=consider-using-enumerate
                     if input_type == "checkbox":
-                        # from app.scodoc.sco_utils import log # debug only
-                        # log('checkbox: values[%s] = "%s"' % (field,repr(values[field]) ))
-                        # log("descr['allowed_values'][%s] = '%s'" % (i, repr(descr['allowed_values'][i])))
                         if (
                             values[field]
                             and descr["allowed_values"][i] in values[field]
@@ -563,7 +560,7 @@ class TF(object):
                         else:
                             try:
                                 v = int(values[field])
-                            except:
+                            except (ValueError, KeyError):
                                 v = False
                         if v:
                             checked = 'checked="checked"'
diff --git a/app/scodoc/sco_preferences.py b/app/scodoc/sco_preferences.py
index 4e5a8a2f0..f63155836 100644
--- a/app/scodoc/sco_preferences.py
+++ b/app/scodoc/sco_preferences.py
@@ -2113,28 +2113,22 @@ class BasePreferences(object):
                     if "explanation" in descr:
                         del descr["explanation"]
                     if formsemestre_id:
-                        descr["explanation"] = (
-                            """ou <span class="spanlink" onclick="set_global_pref(this, '%s');">utiliser paramètre global</span>"""
-                            % pref_name
-                        )
-                    # if descr.get('only_global',False):
-                    #    # pas modifiable, donne juste la valeur courante
-                    #    descr['readonly'] = True
-                    #    descr['explanation'] = '(valeur globale, non modifiable)'
-                    # elif
+                        descr[
+                            "explanation"
+                        ] = """ou <span class="spanlink"
+                            onclick="set_global_pref(this, '{pref_name}');"
+                            >utiliser paramètre global</span>"""
                     if formsemestre_id and self.is_global(formsemestre_id, pref_name):
                         # valeur actuelle globale (ou vient d'etre supprimee localement):
                         # montre la valeur et menus pour la rendre locale
                         descr["readonly"] = True
-                        menu_global = (
-                            """<select class="tf-selglobal" onchange="sel_global(this, '%s');">
+                        menu_global = f"""<select class="tf-selglobal"
+                                onchange="sel_global(this, '{pref_name}');">
                             <option value="">Valeur définie globalement</option>
-                            <option value="create">Spécifier valeur pour ce semestre seulement</option>
+                            <option value="create">Spécifier valeur pour ce
+                            semestre seulement</option>
                         </select>
                         """
-                            % pref_name
-                        )
-                        #                         <option value="changeglobal">Changer paramètres globaux</option>
                         descr["explanation"] = menu_global
 
                     cat_elems.append((pref_name, descr))
@@ -2144,18 +2138,18 @@ class BasePreferences(object):
                 if title:
                     form.append(
                         (
-                            "sep_%s" % cat,
-                            {"input_type": "separator", "title": "<h3>%s</h3>" % title},
+                            f"sep_{cat}",
+                            {"input_type": "separator", "title": f"<h3>{title}</h3>"},
                         )
                     )
                 subtitle = cat_descr.get("subtitle", None)
                 if subtitle:
                     form.append(
                         (
-                            "sepsub_%s" % cat,
+                            f"sepsub_{cat}",
                             {
                                 "input_type": "separator",
-                                "title": '<p class="help">%s</p>' % subtitle,
+                                "title": f'<p class="help">{subtitle}</p>',
                             },
                         )
                     )