1
0
forked from ScoDoc/ScoDoc

Paramétrage des fichiers CSV Moodle

This commit is contained in:
Emmanuel Viennet 2021-04-25 10:10:46 +02:00
parent 61d47e8fad
commit bfc3557814
3 changed files with 45 additions and 9 deletions

View File

@ -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()
]
)

View File

@ -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,),
'<li><a class="stdlink" href="%s&amp;format=moodlecsv">Fichier CSV pour Moodle (groupe sélectionné)</a></li>'
% (tab.base_url,),
'<li><a class="stdlink" href="export_groups_as_moodle_csv?formsemestre_id=%s">Fichier CSV pour Moodle (tous les groupes)</a></li>'
"""<li>
<a class="stdlink" href="export_groups_as_moodle_csv?formsemestre_id=%s">Fichier CSV pour Moodle (tous les groupes)</a>
<em>(voir le paramétrage pour modifier le format des fichiers Moodle exportés)</em>
</li>"""
% 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)

View File

@ -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",