Merge pull request 'export/import notes ; gentables' (#94) from jmplace/ScoDoc-Lille:repair into ScoDoc8

Reviewed-on: https://scodoc.org/git/viennet/ScoDoc/pulls/94
This commit is contained in:
Emmanuel Viennet 2021-08-11 11:54:38 +02:00
commit 09d131a85d
4 changed files with 791 additions and 686 deletions

View File

@ -279,7 +279,7 @@ class GenTable(object):
""" """
if format == "html": if format == "html":
return self.html() return self.html()
elif format == "xls": elif format == "xls" or format == "xlsx":
return self.excel() return self.excel()
elif format == "text" or format == "csv": elif format == "text" or format == "csv":
return self.text() return self.text()
@ -465,22 +465,24 @@ class GenTable(object):
return "\n".join(H) return "\n".join(H)
def excel(self, wb=None): def excel(self, wb=None):
"Simple Excel representation of the table" """Simple Excel representation of the table"""
L = sco_excel.ScoExcelSheet(sheet_name=self.xls_sheet_name) ses = sco_excel.ScoExcelSheet(sheet_name=self.xls_sheet_name, wb=wb)
style_bold = sco_excel.Excel_MakeStyle(bold=True) ses.rows += self.xls_before_table
style_bold = sco_excel.excel_make_style(bold=True)
L.cells += self.xls_before_table style_base = sco_excel.excel_make_style()
L.set_style(style_bold, li=len(L.cells)) ses.append_row(ses.make_row(self.get_titles_list(), style_bold))
L.append(self.get_titles_list()) for line in self.get_data_list():
L.cells += [[x for x in line] for line in self.get_data_list()] ses.append_row(ses.make_row(line, style_base))
if self.caption: if self.caption:
L.append([]) # empty line ses.append_blank_row() # empty line
L.append([self.caption]) ses.append_single_cell_row(self.caption, style_base)
if self.origin: if self.origin:
L.append([]) # empty line ses.append_blank_row() # empty line
L.append([self.origin]) ses.append_single_cell_row(self.origin, style_base)
if wb is None:
return L.gen_workbook(wb=wb) return ses.generate_standalone()
else:
ses.generate_embeded()
def text(self): def text(self):
"raw text representation of the table" "raw text representation of the table"
@ -648,10 +650,10 @@ class GenTable(object):
return scu.sendPDFFile(REQUEST, doc, filename + ".pdf") return scu.sendPDFFile(REQUEST, doc, filename + ".pdf")
else: else:
return doc return doc
elif format == "xls": elif format == "xls" or format == "xlsx":
xls = self.excel() xls = self.excel()
if publish: if publish:
return sco_excel.sendExcelFile(REQUEST, xls, filename + ".xls") return sco_excel.send_excel_file(REQUEST, xls, filename + ".xls")
else: else:
return xls return xls
elif format == "text": elif format == "text":

File diff suppressed because it is too large Load Diff

View File

@ -29,6 +29,7 @@
Formulaire revu en juillet 2016 Formulaire revu en juillet 2016
""" """
import sys
import time import time
import datetime import datetime
import psycopg2 import psycopg2
@ -178,8 +179,7 @@ def do_evaluation_upload_xls(context, REQUEST):
# XXX imaginer un redirect + msg erreur # XXX imaginer un redirect + msg erreur
raise AccessDenied("Modification des notes impossible pour %s" % authuser) raise AccessDenied("Modification des notes impossible pour %s" % authuser)
# #
data = REQUEST.form["notefile"].read() diag, lines = sco_excel.excel_file_to_list(REQUEST.form["notefile"])
diag, lines = sco_excel.Excel_to_list(data)
try: try:
if not lines: if not lines:
raise InvalidNoteValue() raise InvalidNoteValue()
@ -224,7 +224,7 @@ def do_evaluation_upload_xls(context, REQUEST):
ni += 1 ni += 1
except: except:
diag.append( diag.append(
'Erreur: feuille invalide ! (erreur ligne %d)<br/>"%s"' 'Erreur: Ligne invalide ! (erreur ligne %d)<br/>"%s"'
% (ni, str(lines[ni])) % (ni, str(lines[ni]))
) )
raise InvalidNoteValue() raise InvalidNoteValue()
@ -629,7 +629,7 @@ def saisie_notes_tableur(context, evaluation_id, group_ids=[], REQUEST=None):
H.append( H.append(
"""<div class="saisienote_etape2"> """<div class="saisienote_etape2">
<span class="titredivsaisienote">Etape 2 : chargement d'un fichier de notes</span>""" #' <span class="titredivsaisienote">Etape 2 : chargement d'un fichier de notes</span>""" # '
) )
nf = TrivialFormulator( nf = TrivialFormulator(
@ -702,7 +702,7 @@ def saisie_notes_tableur(context, evaluation_id, group_ids=[], REQUEST=None):
<li><a class="stdlink" href="evaluation_suppress_alln?evaluation_id=%s">Effacer toutes les notes de cette évaluation</a> (ceci permet ensuite de supprimer l'évaluation si besoin) <li><a class="stdlink" href="evaluation_suppress_alln?evaluation_id=%s">Effacer toutes les notes de cette évaluation</a> (ceci permet ensuite de supprimer l'évaluation si besoin)
</li>""" </li>"""
% (evaluation_id, evaluation_id) % (evaluation_id, evaluation_id)
) #' ) # '
H.append( H.append(
"""<li><a class="stdlink" href="moduleimpl_status?moduleimpl_id=%(moduleimpl_id)s">Revenir au module</a></li> """<li><a class="stdlink" href="moduleimpl_status?moduleimpl_id=%(moduleimpl_id)s">Revenir au module</a></li>
<li><a class="stdlink" href="saisie_notes?evaluation_id=%(evaluation_id)s">Revenir au formulaire de saisie</a></li> <li><a class="stdlink" href="saisie_notes?evaluation_id=%(evaluation_id)s">Revenir au formulaire de saisie</a></li>
@ -805,8 +805,8 @@ def feuille_saisie_notes(context, evaluation_id, group_ids=[], REQUEST=None):
) )
filename = "notes_%s_%s.xls" % (evalname, gr_title_filename) filename = "notes_%s_%s.xls" % (evalname, gr_title_filename)
xls = sco_excel.Excel_feuille_saisie(E, sem["titreannee"], description, lines=L) xls = sco_excel.excel_feuille_saisie(E, sem["titreannee"], description, lines=L)
return sco_excel.sendExcelFile(REQUEST, xls, filename) return sco_excel.send_excel_file(REQUEST, xls, filename)
def has_existing_decision(context, M, E, etudid): def has_existing_decision(context, M, E, etudid):

View File

@ -1551,6 +1551,7 @@ sco_publish(
"/saisie_notes_tableur", "/saisie_notes_tableur",
sco_saisie_notes.saisie_notes_tableur, sco_saisie_notes.saisie_notes_tableur,
Permission.ScoEnsView, Permission.ScoEnsView,
methods=["GET", "POST"],
) )
sco_publish( sco_publish(
"/feuille_saisie_notes", "/feuille_saisie_notes",