From 3c38ef4cc08178d3df7dc8975f86b4cb3ce3c2b0 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sat, 16 Oct 2021 14:30:35 +0200 Subject: [PATCH] fix true_false --- app/scodoc/sco_excel.py | 37 ++++++++++++++++++++++++----------- app/scodoc/sco_groups_view.py | 8 +------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/scodoc/sco_excel.py b/app/scodoc/sco_excel.py index 2ae5b59c2..586b48b73 100644 --- a/app/scodoc/sco_excel.py +++ b/app/scodoc/sco_excel.py @@ -288,9 +288,31 @@ class ScoExcelSheet: value -- contenu de la cellule (texte, numérique, booléen ou date) style -- style par défaut (dictionnaire cf. excel_make_style) de la feuille si non spécifié """ - if isinstance(value, datetime.datetime): - value = value.replace(tzinfo=None) # make date naive (cf https://openpyxl.readthedocs.io/en/latest/datetime.html#timezones) - cell = WriteOnlyCell(self.ws, value or "") + # adapatation des valeurs si nécessaire + if value is None: + value = "" + elif value is True: + value = 1 + elif value is False: + value = 0 + elif isinstance(value, datetime.datetime): + value = value.replace( + tzinfo=None + ) # make date naive (cf https://openpyxl.readthedocs.io/en/latest/datetime.html#timezones) + + # création de la cellule + cell = WriteOnlyCell(self.ws, value) + + # test datatype to overwrite datetime format + if isinstance(value, datetime.date): + cell.data_type = "d" + cell.number_format = FORMAT_DATE_DDMMYY + elif isinstance(value, int) or isinstance(value, float): + cell.data_type = "n" + else: + cell.data_type = "s" + + # recopie des styles if style is None: style = self.default_style if "font" in style: @@ -312,14 +334,7 @@ class ScoExcelSheet: lines = comment.splitlines() cell.comment.width = 7 * max([len(line) for line in lines]) cell.comment.height = 20 * len(lines) - # test datatype at the end so that datetime format may be overwritten - if isinstance(value, datetime.date): - cell.data_type = "d" - cell.number_format = FORMAT_DATE_DDMMYY - elif isinstance(value, int) or isinstance(value, float): - cell.data_type = "n" - else: - cell.data_type = "s" + return cell def make_row(self, values: list, style=None, comments=None): diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index 4fd4e7d62..9a28d8d79 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -777,13 +777,7 @@ def groups_table( m["parcours"] = Se.get_parcours_descr() m["codeparcours"], _ = sco_report.get_codeparcoursetud(etud) - def dicttakestr(d, keys): - r = [] - for k in keys: - r.append(str(d.get(k, ""))) - return r - - L = [dicttakestr(m, keys) for m in groups_infos.members] + L = [[m.get(k, "") for k in keys] for m in groups_infos.members] title = "etudiants_%s" % groups_infos.groups_filename xls = sco_excel.excel_simple_table(titles=titles, lines=L, sheet_name=title) filename = title