From bfc35578147e0e1146ac190db56d2c96d8f3c5b0 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 25 Apr 2021 10:10:46 +0200 Subject: [PATCH] =?UTF-8?q?Param=C3=A9trage=20des=20fichiers=20CSV=20Moodl?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen_tables.py | 11 ++++++++--- sco_groups_view.py | 19 ++++++++++++++----- sco_preferences.py | 24 +++++++++++++++++++++++- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/gen_tables.py b/gen_tables.py index 4e013c67..3f5a95ef 100644 --- a/gen_tables.py +++ b/gen_tables.py @@ -123,6 +123,7 @@ class GenTable: pdf_col_widths=None, xml_outer_tag="table", xml_row_tag="row", + text_with_titles=False, # CSV with header line text_fields_separator="\t", preferences=None, ): @@ -173,6 +174,7 @@ class GenTable: self.xml_row_tag = xml_row_tag # TEXT parameters self.text_fields_separator = text_fields_separator + self.text_with_titles = text_with_titles # if preferences: self.preferences = preferences @@ -265,8 +267,7 @@ class GenTable: def get_titles_list(self): "list of titles" - l = [] - return l + [self.titles.get(cid, "") for cid in self.columns_ids] + return [self.titles.get(cid, "") for cid in self.columns_ids] def gen(self, format="html", columns_ids=None): """Build representation of the table in the specified format. @@ -479,10 +480,14 @@ class GenTable: def text(self): "raw text representation of the table" + if self.text_with_titles: + headline = [self.get_titles_list()] + else: + headline = [] return "\n".join( [ self.text_fields_separator.join([x for x in line]) - for line in self.get_data_list() + for line in headline + self.get_data_list() ] ) diff --git a/sco_groups_view.py b/sco_groups_view.py index fa806f08..6336d970 100644 --- a/sco_groups_view.py +++ b/sco_groups_view.py @@ -578,6 +578,7 @@ def groups_table( else: filename = "etudiants_%s" % groups_infos.groups_filename + prefs = context.get_preferences(groups_infos.formsemestre_id) tab = GenTable( rows=groups_infos.members, columns_ids=columns_ids, @@ -591,8 +592,9 @@ def groups_table( html_class="table_leftalign table_listegroupe", xml_outer_tag="group_list", xml_row_tag="etud", - text_fields_separator=",", # pour csvmoodle - preferences=context.get_preferences(groups_infos.formsemestre_id), + text_fields_separator=prefs["moodle_csv_separator"], + text_with_titles=prefs["moodle_csv_with_headerline"], + preferences=prefs, ) # if format == "html": @@ -672,7 +674,10 @@ def groups_table( % (tab.base_url,), '
  • Fichier CSV pour Moodle (groupe sélectionné)
  • ' % (tab.base_url,), - '
  • Fichier CSV pour Moodle (tous les groupes)
  • ' + """
  • + Fichier CSV pour Moodle (tous les groupes) + (voir le paramétrage pour modifier le format des fichiers Moodle exportés) +
  • """ % groups_infos.formsemestre_id, ] ) @@ -959,6 +964,7 @@ def export_groups_as_moodle_csv(context, formsemestre_id=None, REQUEST=None): sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) moodle_sem_name = sem["session_id"] + columns_ids = ("email", "semestre_groupe") T = [] for partition_id in partitions_etud_groups: partition = sco_groups.get_partition(context, partition_id) @@ -973,11 +979,14 @@ def export_groups_as_moodle_csv(context, formsemestre_id=None, REQUEST=None): elts.append(group_name) T.append({"email": etud["email"], "semestre_groupe": "-".join(elts)}) # Make table + prefs = context.get_preferences(formsemestre_id) tab = GenTable( rows=T, columns_ids=("email", "semestre_groupe"), filename=moodle_sem_name + "-moodle", - text_fields_separator=",", - preferences=context.get_preferences(formsemestre_id), + titles={x: x for x in columns_ids}, + text_fields_separator=prefs["moodle_csv_separator"], + text_with_titles=prefs["moodle_csv_with_headerline"], + preferences=prefs, ) return tab.make_page(context, format="csv", REQUEST=REQUEST) diff --git a/sco_preferences.py b/sco_preferences.py index 3b356cf5..88869693 100644 --- a/sco_preferences.py +++ b/sco_preferences.py @@ -175,7 +175,7 @@ PREF_CATEGORIES = ( ), ( "feuilles", - {"title": "Mise en forme des feuilles (Absences, Trombinoscopes, ...)"}, + {"title": "Mise en forme des feuilles (Absences, Trombinoscopes, Moodle, ...)"}, ), ("pe", {"title": "Avis de poursuites d'études"}), ("edt", {"title": "Connexion avec le logiciel d'emplois du temps"}), @@ -1644,6 +1644,28 @@ Année scolaire: %(anneescolaire)s "only_global": True, }, ), + # Exports pour Moodle: + ( + "moodle_csv_with_headerline", + { + "initvalue": 0, + "title": "Inclure une ligne d'en-têtes dans les fichiers CSV pour Moodle", + "input_type": "boolcheckbox", + "labels": ["non", "oui"], + "only_global": True, + "category": "feuilles", + }, + ), + ( + "moodle_csv_separator", + { + "initvalue": ",", + "title": "séparateur de colonnes dans les fichiers CSV pour Moodle", + "size": 2, + "only_global": True, + "category": "feuilles", + }, + ), # Experimental: avis poursuite d'études ( "NomResponsablePE",