Merge branch 'ScoDoc8' of https://scodoc.org/git/viennet/ScoDoc into onedb

This commit is contained in:
Emmanuel Viennet 2021-08-12 14:50:58 +02:00
commit fa2f6ea168
16 changed files with 86 additions and 71 deletions

View File

@ -653,7 +653,9 @@ class GenTable(object):
elif format == "xls" or format == "xlsx":
xls = self.excel()
if publish:
return sco_excel.send_excel_file(REQUEST, xls, filename + ".xls")
return sco_excel.send_excel_file(
REQUEST, xls, filename + scu.XLSX_SUFFIX
)
else:
return xls
elif format == "text":

View File

@ -194,7 +194,7 @@ class JuryPE(object):
# self.add_file_to_zip(filename, self.xls.excel())
# Fabrique 1 fichier excel résultat avec 1 seule feuille => trop gros
filename = self.NOM_EXPORT_ZIP + "_jurySyntheseDict" + ".xls"
filename = self.NOM_EXPORT_ZIP + "_jurySyntheseDict" + scu.XLSX_SUFFIX
self.xlsV2 = self.table_syntheseJury(mode="multiplesheet")
if self.xlsV2:
self.add_file_to_zip(filename, self.xlsV2.excel())

View File

@ -142,7 +142,9 @@ def pe_view_sem_recap(
context, jury.syntheseJury, tag_annotation_pe
)
if sT:
jury.add_file_to_zip(jury.NOM_EXPORT_ZIP + "_annotationsPE.xls", sT.excel())
jury.add_file_to_zip(
jury.NOM_EXPORT_ZIP + "_annotationsPE" + scu.XLSX_SUFFIX, sT.excel()
)
latex_pages = {} # Dictionnaire de la forme nom_fichier => contenu_latex
for etudid in etudids:

View File

@ -1266,8 +1266,8 @@ def export_csv_to_apogee(
nf += 1
log_filename = "scodoc-" + basename + ".log.txt"
nar_filename = basename + "-nar.xls"
cr_filename = basename + "-decisions.xls"
nar_filename = basename + "-nar" + scu.XLSX_SUFFIX
cr_filename = basename + "-decisions" + scu.XLSX_SUFFIX
logf = StringIO()
logf.write("export_to_apogee du %s\n\n" % time.ctime())

View File

@ -235,7 +235,13 @@ class BaseArchiver(object):
REQUEST.RESPONSE.setHeader("content-type", scu.XML_MIMETYPE)
return data
elif ext == ".xls":
return sco_excel.sendExcelFile(REQUEST, data, filename)
return sco_excel.send_excel_file(
REQUEST, data, filename, mime=scu.XLS_MIMETYPE
)
elif ext == ".xlsx":
return sco_excel.send_excel_file(
REQUEST, data, filename, mime=scu.XLSX_MIMETYPE
)
elif ext == ".csv":
return scu.sendCSVFile(REQUEST, data, filename)
elif ext == ".pdf":
@ -295,7 +301,7 @@ def do_formsemestre_archive(
context, REQUEST, formsemestre_id, format="xls"
)
if data:
PVArchive.store(archive_id, "Tableau_moyennes.xls", data)
PVArchive.store(archive_id, "Tableau_moyennes" + scu.XLSX_SUFFIX, data)
# Tableau recap notes en HTML (pour tous les etudiants, n'utilise pas les groupes)
data, _, _ = make_formsemestre_recapcomplet(
context, REQUEST, formsemestre_id, format="html", disable_etudlink=True
@ -327,7 +333,7 @@ def do_formsemestre_archive(
context, formsemestre_id, format="xls", REQUEST=REQUEST, publish=False
)
if data:
PVArchive.store(archive_id, "Decisions_Jury.xls", data)
PVArchive.store(archive_id, "Decisions_Jury" + scu.XLSX_SUFFIX, data)
# Classeur bulletins (PDF)
data, _ = sco_bulletins_pdf.get_formsemestre_bulletins_pdf(
context, formsemestre_id, REQUEST, version=bulVersion

View File

@ -256,7 +256,9 @@ def etudarchive_generate_excel_sample(context, group_id=None, REQUEST=None):
extra_cols=["fichier_a_charger"],
REQUEST=REQUEST,
)
return sco_excel.sendExcelFile(REQUEST, data, "ImportFichiersEtudiants.xls")
return sco_excel.send_excel_file(
REQUEST, data, "ImportFichiersEtudiants" + scu.XLSX_SUFFIX
)
def etudarchive_import_files_form(context, group_id, REQUEST=None):

View File

@ -56,7 +56,7 @@ class COLORS(Enum):
LIGHT_YELLOW = "FFFFFF99"
def send_excel_file(request, data, filename):
def send_excel_file(request, data, filename, mime=scu.XLSX_MIMETYPE):
"""publication fichier.
(on ne doit rien avoir émis avant, car ici sont générés les entetes)
"""
@ -65,7 +65,7 @@ def send_excel_file(request, data, filename):
.replace("&", "")
.replace(" ", "_")
)
request.RESPONSE.setHeader("content-type", scu.XLSX_MIMETYPE)
request.RESPONSE.setHeader("content-type", mime)
request.RESPONSE.setHeader(
"content-disposition", 'attachment; filename="%s"' % filename
)
@ -131,6 +131,7 @@ class ScoExcelBook:
...
steam = wb.generate()
"""
def __init__(self):
self.sheets = [] # list of sheets
@ -139,7 +140,7 @@ class ScoExcelBook:
self.sheets.append(sheet)
def generate(self):
""" génération d'un stream binaire représentant la totalité du classeur.
"""génération d'un stream binaire représentant la totalité du classeur.
retourne le flux
"""
wb = Workbook(write_only=True)
@ -206,6 +207,7 @@ class ScoExcelSheet:
ligne de haut en bas et cellules de gauche à droite (i.e. A1, A2, .. B1, B2, ..)
* pour finit appel de la méthode de génération
"""
def __init__(self, sheet_name="feuille", default_style=None, wb=None):
"""Création de la feuille.
sheet_name -- le nom de la feuille
@ -557,7 +559,7 @@ def _excel_to_list(filelike): # we may need 'encoding' argument ?
wb = load_workbook(filename=filelike, read_only=True, data_only=True)
except:
log("Excel_to_list: failure to import document")
open("/tmp/last_scodoc_import_failure.xls", "w").write(filelike)
open("/tmp/last_scodoc_import_failure" + scu.XLSX_SUFFIX, "w").write(filelike)
raise ScoValueError(
"Fichier illisible: assurez-vous qu'il s'agit bien d'un document Excel !"
)

View File

@ -803,8 +803,8 @@ def groups_table(
L = [dicttakestr(m, keys) for m in groups_infos.members]
title = "etudiants_%s" % groups_infos.groups_filename
xls = sco_excel.Excel_SimpleTable(titles=titles, lines=L, SheetName=title)
filename = title + ".xls"
xls = sco_excel.excel_simple_table(titles=titles, lines=L, sheet_name=title)
filename = title + scu.XLSX_SUFFIX
return sco_excel.send_excel_file(REQUEST, xls, filename)
else:
raise ValueError("unsupported format")

View File

@ -49,8 +49,8 @@ def generate_excel_sample():
style = sco_excel.Excel_MakeStyle(bold=True)
titles = TITLES
titlesStyles = [style] * len(titles)
return sco_excel.Excel_SimpleTable(
titles=titles, titlesStyles=titlesStyles, SheetName="Utilisateurs ScoDoc"
return sco_excel.excel_simple_table(
titles=titles, titlesStyles=titlesStyles, sheet_name="Utilisateurs ScoDoc"
)

View File

@ -322,11 +322,11 @@ def do_placement(context, REQUEST):
maxlines = sem_preferences.get("feuille_placement_positions")
if placement_method == "xls":
filename = "placement_%s_%s.xls" % (evalname, gr_title_filename)
filename = f"placement_{evalname}_{gr_title_filename}{scu.XLSX_SUFFIX}"
xls = Excel_feuille_placement(
E, desceval, listetud, columns, space, maxlines, building, room, numbering
)
return sco_excel.sendExcelFile(REQUEST, xls, filename)
return sco_excel.send_excel_file(REQUEST, xls, filename)
else:
nbcolumns = int(columns)
@ -663,8 +663,8 @@ def Excel_feuille_placement(
li = 0
line = 0
dt = time.strftime("%d/%m/%Y a %Hh%M")
ws0.write(li, 0, u"Feuille placement etudiants éditée le %s" % dt, style_titres)
ws1.write(li, 0, u"Feuille placement etudiants éditée le %s" % dt, style_titres)
ws0.write(li, 0, "Feuille placement etudiants éditée le %s" % dt, style_titres)
ws1.write(li, 0, "Feuille placement etudiants éditée le %s" % dt, style_titres)
for desceval in description:
if line % 2 == 0:
li += 2
@ -677,41 +677,39 @@ def Excel_feuille_placement(
ws0.write(
li,
0,
u"Date : %s - Horaire : %s à %s"
% (E["jour"], E["heure_debut"], E["heure_fin"]),
"Date : %s - Horaire : %s à %s" % (E["jour"], E["heure_debut"], E["heure_fin"]),
style_titres,
)
ws1.write(
li,
0,
u"Date : %s - Horaire : %s à %s"
% (E["jour"], E["heure_debut"], E["heure_fin"]),
"Date : %s - Horaire : %s à %s" % (E["jour"], E["heure_debut"], E["heure_fin"]),
style_titres,
)
li += 1
# entetes colonnes - feuille0
for col in range(nbcolumns):
ws0.write(li, col + 1, u"colonne %s" % (col + 1), style2b)
ws0.write(li, col + 1, "colonne %s" % (col + 1), style2b)
# entetes colonnes - feuille1
if numbering == "coordinate":
ws1.write(li, 0, u"Nom", style2bi)
ws1.write(li, 1, u"Prénom", style2bi)
ws1.write(li, 2, u"Colonne", style2bi)
ws1.write(li, 3, u"Ligne", style2bi)
ws1.write(li, 0, "Nom", style2bi)
ws1.write(li, 1, "Prénom", style2bi)
ws1.write(li, 2, "Colonne", style2bi)
ws1.write(li, 3, "Ligne", style2bi)
ws1.write(li, 5, u"Nom", style2bi)
ws1.write(li, 6, u"Prénom", style2bi)
ws1.write(li, 7, u"Colonne", style2bi)
ws1.write(li, 8, u"Ligne", style2bi)
ws1.write(li, 5, "Nom", style2bi)
ws1.write(li, 6, "Prénom", style2bi)
ws1.write(li, 7, "Colonne", style2bi)
ws1.write(li, 8, "Ligne", style2bi)
else:
ws1.write(li, 0, u"Nom", style2bi)
ws1.write(li, 1, u"Prénom", style2bi)
ws1.write(li, 2, u"Place", style2bi)
ws1.write(li, 0, "Nom", style2bi)
ws1.write(li, 1, "Prénom", style2bi)
ws1.write(li, 2, "Place", style2bi)
ws1.write(li, 4, u"Nom", style2bi)
ws1.write(li, 5, u"Prénom", style2bi)
ws1.write(li, 6, u"Place", style2bi)
ws1.write(li, 4, "Nom", style2bi)
ws1.write(li, 5, "Prénom", style2bi)
ws1.write(li, 6, "Place", style2bi)
# etudiants
line = 1
@ -751,7 +749,7 @@ def Excel_feuille_placement(
ws0.write(li0 + 2, col, " ", style1bb)
else:
ws0.write(
li0 + 2, col, u"place %s" % (col + (line - 1) * nbcolumns), style1bb
li0 + 2, col, "place %s" % (col + (line - 1) * nbcolumns), style1bb
)
# ws0.write(li+3,col, ' ', style1bm )
# ws0.write(li+4,col, ' ', style1bb )
@ -793,21 +791,21 @@ def Excel_feuille_placement(
nbcol = 0
col = 0
if numbering == "coordinate":
ws1.write(li, 0, u"Nom", style2bi)
ws1.write(li, 1, u"Prénom", style2bi)
ws1.write(li, 2, u"Colonne", style2bi)
ws1.write(li, 3, u"Ligne", style2bi)
ws1.write(li, 0, "Nom", style2bi)
ws1.write(li, 1, "Prénom", style2bi)
ws1.write(li, 2, "Colonne", style2bi)
ws1.write(li, 3, "Ligne", style2bi)
ws1.write(li, 5, u"Nom", style2bi)
ws1.write(li, 6, u"Prénom", style2bi)
ws1.write(li, 7, u"Colonne", style2bi)
ws1.write(li, 8, u"Ligne", style2bi)
ws1.write(li, 5, "Nom", style2bi)
ws1.write(li, 6, "Prénom", style2bi)
ws1.write(li, 7, "Colonne", style2bi)
ws1.write(li, 8, "Ligne", style2bi)
else:
ws1.write(li, 0, u"Nom", style2bi)
ws1.write(li, 1, u"Prénom", style2bi)
ws1.write(li, 2, u"Place", style2bi)
ws1.write(li, 0, "Nom", style2bi)
ws1.write(li, 1, "Prénom", style2bi)
ws1.write(li, 2, "Place", style2bi)
ws1.write(li, 4, u"Nom", style2bi)
ws1.write(li, 5, u"Prénom", style2bi)
ws1.write(li, 6, u"Place", style2bi)
ws1.write(li, 4, "Nom", style2bi)
ws1.write(li, 5, "Prénom", style2bi)
ws1.write(li, 6, "Place", style2bi)
return wb.savetostr()

View File

@ -190,14 +190,14 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
titles.append("Autorisations")
# titles.append('Assidu')
L.append(titles)
style_bold = sco_excel.Excel_MakeStyle(bold=True)
style_center = sco_excel.Excel_MakeStyle(halign="center")
style_boldcenter = sco_excel.Excel_MakeStyle(bold=True, halign="center")
style_moy = sco_excel.Excel_MakeStyle(
style_bold = sco_excel.excel_make_style(bold=True)
style_center = sco_excel.excel_make_style(halign="center")
style_boldcenter = sco_excel.excel_make_style(bold=True, halign="center")
style_moy = sco_excel.excel_make_style(
bold=True, halign="center", bgcolor="lightyellow"
)
style_note = sco_excel.Excel_MakeStyle(halign="right")
style_note_bold = sco_excel.Excel_MakeStyle(halign="right", bold=True)
style_note = sco_excel.excel_make_style(halign="right")
style_note_bold = sco_excel.excel_make_style(halign="right", bold=True)
if prev_moy:
tit_prev_moy = "Moy " + sp
col_prev_moy = titles.index(tit_prev_moy)
@ -315,4 +315,4 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
xls = L.gen_workbook()
return sco_excel.sendExcelFile(REQUEST, xls, "PrepaJury%s.xls" % sn)
return sco_excel.send_excel_file(REQUEST, xls, f"PrepaJury{sn}{scu.XLSX_SUFFIX}")

View File

@ -216,7 +216,7 @@ def do_formsemestre_recapcomplet(
elif format == "csv":
return scu.sendCSVFile(REQUEST, data, filename)
elif format[:3] == "xls":
return sco_excel.sendExcelFile(REQUEST, data, filename)
return sco_excel.send_excel_file(REQUEST, data, filename)
elif format == "json":
return scu.sendJSON(REQUEST, data)
else:
@ -776,15 +776,15 @@ def make_formsemestre_recapcomplet(
semname = sem["titre_num"].replace(" ", "_")
date = time.strftime("%d-%m-%Y")
if format == "xls":
filename = "notes_modules-%s-%s.xls" % (semname, date)
filename = "notes_modules-%s-%s%s" % (semname, date, scu.XLSX_SUFFIX)
else:
filename = "notes_modules_evals-%s-%s.xls" % (semname, date)
xls = sco_excel.Excel_SimpleTable(
filename = "notes_modules_evals-%s-%s%s" % (semname, date, scu.XLSX_SUFFIX)
xls = sco_excel.excel_simple_table(
titles=["etudid", "code_nip"] + F[0][:-2],
lines=[
[x[-1], x[-2]] + x[:-2] for x in F[1:]
], # reordonne cols (etudid et nip en 1er)
SheetName="notes %s %s" % (semname, date),
sheet_name="notes %s %s" % (semname, date),
)
return xls, filename, "xls"
else:

View File

@ -143,7 +143,7 @@ def formsemestre_synchro_etuds(
base_url=base_url,
read_only=read_only,
)
return sco_excel.sendExcelFile(REQUEST, xls, filename + ".xls")
return sco_excel.send_excel_file(REQUEST, xls, filename + scu.XLSX_SUFFIX)
H = [header]
if not submitted:

View File

@ -491,7 +491,7 @@ def photos_generate_excel_sample(context, group_ids=[], REQUEST=None):
extra_cols=["fichier_photo"],
REQUEST=REQUEST,
)
return sco_excel.sendExcelFile(REQUEST, data, "ImportPhotos.xls")
return sco_excel.send_excel_file(REQUEST, data, "ImportPhotos" + scu.XLSX_SUFFIX)
def photos_import_files_form(context, group_ids=[], REQUEST=None):

View File

@ -302,6 +302,7 @@ CSV_LINESEP = "\n"
CSV_MIMETYPE = "text/comma-separated-values"
XLS_MIMETYPE = "application/vnd.ms-excel"
XLSX_MIMETYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
XLSX_SUFFIX = ".xlsx"
PDF_MIMETYPE = "application/pdf"
XML_MIMETYPE = "text/xml"
JSON_MIMETYPE = "application/json"

View File

@ -1876,7 +1876,7 @@ def import_generate_excel_sample(context, REQUEST, with_codesemestre="1"):
data = sco_import_etuds.sco_import_generate_excel_sample(
format, with_codesemestre, exclude_cols=["photo_filename"], REQUEST=REQUEST
)
return sco_excel.sendExcelFile(REQUEST, data, "ImportEtudiants.xls")
return sco_excel.send_excel_file(REQUEST, data, "ImportEtudiants" + scu.XLSX_SUFFIX)
# --- Données admission
@ -1895,7 +1895,9 @@ def import_generate_admission_sample(context, REQUEST, formsemestre_id):
context=context,
REQUEST=REQUEST,
)
return sco_excel.sendExcelFile(REQUEST, data, "AdmissionEtudiants.xls")
return sco_excel.send_excel_file(
REQUEST, data, "AdmissionEtudiants" + scu.XLSX_SUFFIX
)
# --- Données admission depuis fichier excel (version nov 2016)