forked from ScoDoc/ScoDoc
Merge branch 'ScoDoc8' of https://scodoc.org/git/viennet/ScoDoc into onedb
This commit is contained in:
commit
98747c3e8e
@ -136,8 +136,13 @@ class ScoExcelBook:
|
|||||||
self.sheets = [] # list of sheets
|
self.sheets = [] # list of sheets
|
||||||
|
|
||||||
def create_sheet(self, sheet_name="feuille", default_style=None):
|
def create_sheet(self, sheet_name="feuille", default_style=None):
|
||||||
|
"""Crée une nouvelle feuille dans ce classeur
|
||||||
|
sheet_name -- le nom de la feuille
|
||||||
|
default_style -- le style par défaut
|
||||||
|
"""
|
||||||
sheet = ScoExcelSheet(sheet_name, default_style)
|
sheet = ScoExcelSheet(sheet_name, default_style)
|
||||||
self.sheets.append(sheet)
|
self.sheets.append(sheet)
|
||||||
|
return sheet
|
||||||
|
|
||||||
def generate(self):
|
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.
|
||||||
@ -161,6 +166,8 @@ def excel_make_style(
|
|||||||
halign=None,
|
halign=None,
|
||||||
valign=None,
|
valign=None,
|
||||||
format_number=None,
|
format_number=None,
|
||||||
|
font_name="Arial",
|
||||||
|
size=10,
|
||||||
):
|
):
|
||||||
"""Contruit un style.
|
"""Contruit un style.
|
||||||
Les couleurs peuvent être spécfiées soit par une valeur de COLORS,
|
Les couleurs peuvent être spécfiées soit par une valeur de COLORS,
|
||||||
@ -169,30 +176,32 @@ def excel_make_style(
|
|||||||
bgcolor -- la couleur de fond
|
bgcolor -- la couleur de fond
|
||||||
halign -- alignement horizontal ("left", "right", "center")
|
halign -- alignement horizontal ("left", "right", "center")
|
||||||
valign -- alignement vertical ("top", "bottom", "center")
|
valign -- alignement vertical ("top", "bottom", "center")
|
||||||
format_number -- formattage du contenu ("general", "@", ...)
|
format_number -- formattage du contenu ("General", "@", ...)
|
||||||
|
font_name -- police
|
||||||
|
size -- taille de police
|
||||||
"""
|
"""
|
||||||
style = {}
|
style = {}
|
||||||
font = Font(name="Arial", bold=bold, italic=italic, color=color.value)
|
font = Font(name=font_name, bold=bold, italic=italic, color=color.value, size=size)
|
||||||
style["font"] = font
|
style["font"] = font
|
||||||
if bgcolor:
|
if bgcolor:
|
||||||
style["fill"] = PatternFill(fill_type="solid", bgColor=bgcolor.value)
|
style["fill"] = PatternFill(fill_type="solid", fgColor=bgcolor.value)
|
||||||
if halign or valign:
|
if halign or valign:
|
||||||
al = Alignment()
|
al = Alignment()
|
||||||
if halign:
|
if halign:
|
||||||
al.horz = {
|
al.horizontal = {
|
||||||
"left": "left",
|
"left": "left",
|
||||||
"right": "right",
|
"right": "right",
|
||||||
"center": "center",
|
"center": "center",
|
||||||
}[halign]
|
}[halign]
|
||||||
if valign:
|
if valign:
|
||||||
al.vert = {
|
al.vertical = {
|
||||||
"top": "top",
|
"top": "top",
|
||||||
"bottom": "bottom",
|
"bottom": "bottom",
|
||||||
"center": "center",
|
"center": "center",
|
||||||
}[valign]
|
}[valign]
|
||||||
style["alignment"] = al
|
style["alignment"] = al
|
||||||
if format_number is None:
|
if format_number is None:
|
||||||
style["format_number"] = "general"
|
style["format_number"] = "General"
|
||||||
else:
|
else:
|
||||||
style["format_number"] = format_number
|
style["format_number"] = format_number
|
||||||
return style
|
return style
|
||||||
@ -244,9 +253,11 @@ class ScoExcelSheet:
|
|||||||
def make_cell(self, value: any = None, style=None):
|
def make_cell(self, value: any = None, style=None):
|
||||||
"""Construit une cellule.
|
"""Construit une cellule.
|
||||||
value -- contenu de la cellule (texte ou numérique)
|
value -- contenu de la cellule (texte ou numérique)
|
||||||
style -- style par défaut de la feuille si non spécifié
|
style -- style par défaut (dictionnaire cf. excel_make_style) de la feuille si non spécifié
|
||||||
"""
|
"""
|
||||||
cell = WriteOnlyCell(self.ws, value or "")
|
cell = WriteOnlyCell(self.ws, value or "")
|
||||||
|
# if style is not None and "fill" in style:
|
||||||
|
# toto()
|
||||||
if style is None:
|
if style is None:
|
||||||
style = self.default_style
|
style = self.default_style
|
||||||
if "font" in style:
|
if "font" in style:
|
||||||
@ -261,7 +272,7 @@ class ScoExcelSheet:
|
|||||||
cell.alignment = style["alignment"]
|
cell.alignment = style["alignment"]
|
||||||
return cell
|
return cell
|
||||||
|
|
||||||
def make_row(self, values: list, style):
|
def make_row(self, values: list, style=None):
|
||||||
return [self.make_cell(value, style) for value in values]
|
return [self.make_cell(value, style) for value in values]
|
||||||
|
|
||||||
def append_single_cell_row(self, value: any, style=None):
|
def append_single_cell_row(self, value: any, style=None):
|
||||||
@ -437,7 +448,7 @@ def excel_feuille_saisie(e, titreannee, description, lines):
|
|||||||
}
|
}
|
||||||
style_notes = {
|
style_notes = {
|
||||||
"font": font_bold,
|
"font": font_bold,
|
||||||
"number_format": "general",
|
"number_format": "General",
|
||||||
"fill": fill_light_yellow,
|
"fill": fill_light_yellow,
|
||||||
"border": border_top,
|
"border": border_top,
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ from app.scodoc import sco_codes_parcours
|
|||||||
from app.scodoc import VERSION
|
from app.scodoc import VERSION
|
||||||
from app.scodoc import sco_etud
|
from app.scodoc import sco_etud
|
||||||
from app.scodoc import sco_preferences
|
from app.scodoc import sco_preferences
|
||||||
|
from app.scodoc.sco_excel import ScoExcelSheet
|
||||||
|
|
||||||
|
|
||||||
def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
||||||
@ -129,9 +130,9 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
|||||||
main_partition_id, ""
|
main_partition_id, ""
|
||||||
)
|
)
|
||||||
# absences:
|
# absences:
|
||||||
nbabs, nbabsjust = sco_abs.get_abs_count(etudid, sem)
|
e_nbabs, e_nbabsjust = sco_abs.get_abs_count(etudid, sem)
|
||||||
nbabs[etudid] = nbabs
|
nbabs[etudid] = e_nbabs
|
||||||
nbabsjust[etudid] = nbabs - nbabsjust
|
nbabsjust[etudid] = e_nbabs - e_nbabsjust
|
||||||
|
|
||||||
# Codes des UE "semestre précédent":
|
# Codes des UE "semestre précédent":
|
||||||
ue_prev_codes = list(prev_moy_ue.keys())
|
ue_prev_codes = list(prev_moy_ue.keys())
|
||||||
@ -153,10 +154,26 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
|||||||
if prev_moy: # si qq chose dans precedent
|
if prev_moy: # si qq chose dans precedent
|
||||||
sp = "S%s" % (sid - 1)
|
sp = "S%s" % (sid - 1)
|
||||||
|
|
||||||
L = sco_excel.ScoExcelSheet(sheet_name="Prepa Jury %s" % sn)
|
ws = sco_excel.ScoExcelSheet(sheet_name="Prepa Jury %s" % sn)
|
||||||
L.append(["Feuille préparation Jury %s" % scu.unescape_html(sem["titreannee"])])
|
# génération des styles
|
||||||
L.append([]) # empty line
|
style_bold = sco_excel.excel_make_style(size=10, 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=sco_excel.COLORS.LIGHT_YELLOW
|
||||||
|
)
|
||||||
|
style_note = sco_excel.excel_make_style(halign="right", format_number="General")
|
||||||
|
style_note_bold = sco_excel.excel_make_style(
|
||||||
|
halign="right", bold=True, format_number="General"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Première ligne
|
||||||
|
ws.append_single_cell_row(
|
||||||
|
"Feuille préparation Jury %s" % scu.unescape_html(sem["titreannee"]), style_bold
|
||||||
|
)
|
||||||
|
ws.append_blank_row()
|
||||||
|
|
||||||
|
# Ligne de titre
|
||||||
titles = ["Rang"]
|
titles = ["Rang"]
|
||||||
if sco_preferences.get_preference("prepa_jury_nip"):
|
if sco_preferences.get_preference("prepa_jury_nip"):
|
||||||
titles.append("NIP")
|
titles.append("NIP")
|
||||||
@ -174,7 +191,6 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
|||||||
"Parcours",
|
"Parcours",
|
||||||
"Groupe",
|
"Groupe",
|
||||||
]
|
]
|
||||||
|
|
||||||
if prev_moy: # si qq chose dans precedent
|
if prev_moy: # si qq chose dans precedent
|
||||||
titles += [prev_ue_acro[x][1] for x in ue_prev_codes] + [
|
titles += [prev_ue_acro[x][1] for x in ue_prev_codes] + [
|
||||||
"Moy %s" % sp,
|
"Moy %s" % sp,
|
||||||
@ -189,15 +205,7 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
|||||||
if autorisations:
|
if autorisations:
|
||||||
titles.append("Autorisations")
|
titles.append("Autorisations")
|
||||||
# titles.append('Assidu')
|
# titles.append('Assidu')
|
||||||
L.append(titles)
|
ws.append_row(ws.make_row(titles, style_boldcenter))
|
||||||
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_make_style(halign="right")
|
|
||||||
style_note_bold = sco_excel.excel_make_style(halign="right", bold=True)
|
|
||||||
if prev_moy:
|
if prev_moy:
|
||||||
tit_prev_moy = "Moy " + sp
|
tit_prev_moy = "Moy " + sp
|
||||||
col_prev_moy = titles.index(tit_prev_moy)
|
col_prev_moy = titles.index(tit_prev_moy)
|
||||||
@ -205,9 +213,6 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
|||||||
col_moy = titles.index(tit_moy)
|
col_moy = titles.index(tit_moy)
|
||||||
col_abs = titles.index("Abs")
|
col_abs = titles.index("Abs")
|
||||||
|
|
||||||
L.set_style(style_bold, li=0)
|
|
||||||
L.set_style(style_boldcenter, li=2)
|
|
||||||
|
|
||||||
def fmt(x):
|
def fmt(x):
|
||||||
"reduit les notes a deux chiffres"
|
"reduit les notes a deux chiffres"
|
||||||
x = scu.fmt_note(x, keep_numeric=False)
|
x = scu.fmt_note(x, keep_numeric=False)
|
||||||
@ -218,13 +223,15 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
|||||||
|
|
||||||
i = 1 # numero etudiant
|
i = 1 # numero etudiant
|
||||||
for etudid in etudids:
|
for etudid in etudids:
|
||||||
|
cells = []
|
||||||
etud = nt.identdict[etudid]
|
etud = nt.identdict[etudid]
|
||||||
l = [str(i)]
|
cells.append(ws.make_cell(str(i)))
|
||||||
if sco_preferences.get_preference("prepa_jury_nip"):
|
if sco_preferences.get_preference("prepa_jury_nip"):
|
||||||
l.append(etud["code_nip"])
|
cells.append(ws.make_cell(etud["code_nip"]))
|
||||||
if sco_preferences.get_preference("prepa_jury_ine"):
|
if sco_preferences.get_preference("prepa_jury_ine"):
|
||||||
l.append(etud["code_ine"])
|
cells.append(ws.make_cell(["code_ine"]))
|
||||||
l += [
|
cells += ws.make_row(
|
||||||
|
[
|
||||||
etudid,
|
etudid,
|
||||||
etud["civilite_str"],
|
etud["civilite_str"],
|
||||||
sco_etud.format_nom(etud["nom"]),
|
sco_etud.format_nom(etud["nom"]),
|
||||||
@ -236,53 +243,53 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
|||||||
parcours[etudid],
|
parcours[etudid],
|
||||||
groupestd[etudid],
|
groupestd[etudid],
|
||||||
]
|
]
|
||||||
co = len(l)
|
)
|
||||||
|
co = len(cells)
|
||||||
if prev_moy:
|
if prev_moy:
|
||||||
for ue_acro in ue_prev_codes:
|
for ue_acro in ue_prev_codes:
|
||||||
l.append(fmt(prev_moy_ue.get(ue_acro, {}).get(etudid, "")))
|
cells.append(
|
||||||
L.set_style(style_note, li=i + 2, co=co)
|
ws.make_cell(
|
||||||
|
fmt(prev_moy_ue.get(ue_acro, {}).get(etudid, "")), style_note
|
||||||
|
)
|
||||||
|
)
|
||||||
co += 1
|
co += 1
|
||||||
l.append(fmt(prev_moy.get(etudid, "")))
|
cells.append(
|
||||||
l.append(prev_code.get(etudid, ""))
|
ws.make_cell(fmt(prev_moy.get(etudid, "")), style_bold)
|
||||||
# L.set_style(style_bold, li=i+2, co=col_prev_moy+1) # moy gen prev
|
) # moy gen prev
|
||||||
# L.set_style(style_moy, li=i+2, co=col_prev_moy+2) # decision prev
|
cells.append(
|
||||||
L.set_style(style_bold, li=i + 2, co=col_prev_moy) # moy gen prev
|
ws.make_cell(fmt(prev_code.get(etudid, "")), style_moy)
|
||||||
L.set_style(style_moy, li=i + 2, co=col_prev_moy + 1) # decision prev
|
) # decision prev
|
||||||
co += 2
|
co += 2
|
||||||
|
|
||||||
for ue_acro in ue_codes:
|
for ue_acro in ue_codes:
|
||||||
l.append(fmt(moy_ue.get(ue_acro, {}).get(etudid, "")))
|
cells.append(
|
||||||
L.set_style(style_note, li=i + 2, co=co)
|
ws.make_cell(fmt(moy_ue.get(ue_acro, {}).get(etudid, "")), style_note)
|
||||||
|
)
|
||||||
co += 1
|
co += 1
|
||||||
l.append(fmt(moy.get(etudid, "")))
|
cells.append(ws.make_cell(fmt(moy.get(etudid, "")), style_note_bold)) # moy gen
|
||||||
# L.set_style(style_note_bold, li=i+2, co=col_moy+1) # moy gen
|
|
||||||
L.set_style(style_note_bold, li=i + 2, co=col_moy) # moy gen
|
|
||||||
co += 1
|
co += 1
|
||||||
if moy_inter:
|
if moy_inter:
|
||||||
l.append(fmt(moy_inter.get(etudid, "")))
|
cells.append(ws.make_cell(fmt(moy_inter.get(etudid, "")), style_note))
|
||||||
L.set_style(style_note, li=i + 2, co=co)
|
cells.append(ws.make_cell(str(nbabs.get(etudid, "")), style_center))
|
||||||
l.append(fmt(str(nbabs.get(etudid, ""))))
|
cells.append(ws.make_cell(str(nbabsjust.get(etudid, "")), style_center))
|
||||||
l.append(fmt(str(nbabsjust.get(etudid, ""))))
|
|
||||||
if code:
|
if code:
|
||||||
l.append(code.get(etudid, ""))
|
cells.append(ws.make_cell(code.get(etudid, ""), style_moy))
|
||||||
if autorisations:
|
cells.append(ws.make_cell(autorisations.get(etudid, ""), style_moy))
|
||||||
l.append(autorisations.get(etudid, ""))
|
|
||||||
# l.append(assidu.get(etudid, ''))
|
# l.append(assidu.get(etudid, ''))
|
||||||
L.append(l)
|
ws.append_row(cells)
|
||||||
i += 1
|
i += 1
|
||||||
L.set_style(style_center, li=i + 1, co=col_abs) # absences
|
|
||||||
L.set_style(style_center, li=i + 1, co=col_abs + 1) # absences injustifiées
|
|
||||||
L.set_style(style_moy, li=i + 1, co=col_abs + 2) # décision semestre
|
|
||||||
L.set_style(style_center, li=i + 1, co=col_abs + 3) # Autorisations
|
|
||||||
#
|
#
|
||||||
L.append([""])
|
ws.append_blank_row()
|
||||||
# Explications des codes
|
# Explications des codes
|
||||||
codes = list(sco_codes_parcours.CODES_EXPL.keys())
|
codes = list(sco_codes_parcours.CODES_EXPL.keys())
|
||||||
codes.sort()
|
codes.sort()
|
||||||
L.append(["Explication des codes"])
|
ws.append_single_cell_row("Explication des codes")
|
||||||
for code in codes:
|
for code in codes:
|
||||||
L.append(["", "", "", code, sco_codes_parcours.CODES_EXPL[code]])
|
ws.append_row(
|
||||||
L.append(
|
ws.make_row(["", "", "", code, sco_codes_parcours.CODES_EXPL[code]])
|
||||||
|
)
|
||||||
|
ws.append_row(
|
||||||
|
ws.make_row(
|
||||||
[
|
[
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
@ -291,18 +298,18 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
|||||||
"indique que le semestre a déjà servi à en compenser un autre",
|
"indique que le semestre a déjà servi à en compenser un autre",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
)
|
||||||
# UE : Correspondances acronyme et titre complet
|
# UE : Correspondances acronyme et titre complet
|
||||||
L.append([""])
|
ws.append_blank_row()
|
||||||
L.append(["Titre des UE"])
|
ws.append_single_cell_row("Titre des UE")
|
||||||
if prev_moy:
|
if prev_moy:
|
||||||
for ue in ntp.get_ues(filter_sport=True):
|
for ue in ntp.get_ues(filter_sport=True):
|
||||||
L.append(["", "", "", ue["acronyme"], ue["titre"]])
|
ws.append_row(ws.make_row(["", "", "", ue["acronyme"], ue["titre"]]))
|
||||||
for ue in nt.get_ues(filter_sport=True):
|
for ue in nt.get_ues(filter_sport=True):
|
||||||
L.append(["", "", "", ue["acronyme"], ue["titre"]])
|
ws.append_row(ws.make_row(["", "", "", ue["acronyme"], ue["titre"]]))
|
||||||
#
|
#
|
||||||
L.append([""])
|
ws.append_blank_row()
|
||||||
L.append(
|
ws.append_single_cell_row(
|
||||||
[
|
|
||||||
"Préparé par %s le %s sur %s pour %s"
|
"Préparé par %s le %s sur %s pour %s"
|
||||||
% (
|
% (
|
||||||
VERSION.SCONAME,
|
VERSION.SCONAME,
|
||||||
@ -310,9 +317,6 @@ def feuille_preparation_jury(context, formsemestre_id, REQUEST):
|
|||||||
REQUEST.BASE0,
|
REQUEST.BASE0,
|
||||||
REQUEST.AUTHENTICATED_USER,
|
REQUEST.AUTHENTICATED_USER,
|
||||||
)
|
)
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
xls = ws.generate_standalone()
|
||||||
xls = L.gen_workbook()
|
|
||||||
|
|
||||||
return sco_excel.send_excel_file(REQUEST, xls, f"PrepaJury{sn}{scu.XLSX_SUFFIX}")
|
return sco_excel.send_excel_file(REQUEST, xls, f"PrepaJury{sn}{scu.XLSX_SUFFIX}")
|
||||||
|
Loading…
Reference in New Issue
Block a user