avannt merge

This commit is contained in:
Jean-Marie Place 2024-06-24 06:30:52 +02:00
parent f976b2fdb0
commit 75f01a0d9e
5 changed files with 2106 additions and 245 deletions

View File

@ -161,7 +161,10 @@ def excel_make_style(
) )
style["font"] = font style["font"] = font
if bgcolor: if bgcolor:
style["fill"] = PatternFill(fill_type="solid", fgColor=bgcolor.value) if isinstance(bgcolor, str):
style["fill"] = PatternFill(fill_type="solid", fgColor=bgcolor)
else:
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:
@ -348,15 +351,21 @@ class ScoExcelSheet:
return cell return cell
def make_row(self, values: list, style=None, comments=None) -> list: def make_row(self, values: list, styles=None, comments=None) -> list:
"build a row" "build a row"
# TODO make possible differents styles in a row # TODO make possible differents styles in a row
if comments is None: if comments is None:
comments = [None] * len(values) comments = [None] * len(values)
return [ if isinstance(styles, list):
self.make_cell(value, style, comment) return [
for value, comment in zip(values, comments) self.make_cell(value, style, comment)
] for value, style, comment in zip(values, styles, comments)
]
else:
return [
self.make_cell(value, style, comment)
for value, comment in zip(values, comments)
]
def append_single_cell_row(self, value: any, style=None): def append_single_cell_row(self, value: any, style=None):
"""construit une ligne composée d'une seule cellule et l'ajoute à la feuille. """construit une ligne composée d'une seule cellule et l'ajoute à la feuille.

221
app/scodoc/sco_excel_add.py Normal file
View File

@ -0,0 +1,221 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
# Copyright (c) 1999 - 2019 Emmanuel Viennet. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Emmanuel Viennet emmanuel.viennet@viennet.net
#
##############################################################################
""" Excel file handling
"""
# from sco_utils import *
# from sco_excel import *
import time, datetime
from openpyxl.styles import Font, Alignment, PatternFill, Side, Border
from app.scodoc.sco_excel import COLORS, ScoExcelSheet
def make_font(
bold=False,
italic=False,
font_name=None,
font_size=None,
color=COLORS.BLACK.value,
style=None,
uline=False,
):
font = None
if bold or italic or font_name or font_size:
font = Font()
if bold:
font.bold = bold
if uline:
font.underline = Font.UNDERLINE_SINGLE
if italic:
font.italic = italic
font.name = font_name if font_name else "Arial"
if font_size:
font.height = 20 * font_size
if color:
font.color = color
if font and style:
style["font"] = font
return font
def make_alignment(halign=None, valign=None, orientation=None, style=None):
alignment = None
if halign or valign or orientation:
alignment = Alignment()
if halign:
alignment.horz = halign
if valign:
alignment.vert = valign
if orientation:
alignment.rota = orientation
if alignment and style:
breakpoint()
style["alignment"] = alignment
return alignment
def make_numfmt(fmt, style=None):
if fmt and style:
style["num_format_str"] = fmt
def make_pattern(bgcolor, style=None):
pattern = PatternFill(fill_type="solid", fgColor=bgcolor)
if pattern and style:
style["fill"] = pattern
return pattern
Sides = {
"none": Side(border_style=None),
"thin": Side(border_style="thin"),
"medium": Side(border_style="medium"),
"thick": Side(border_style="thick"),
"filet": Side(border_style="hair"),
}
def make_borders(left=None, top=None, bottom=None, right=None, style=None):
border = None
if left or right or top or bottom:
border = Border()
if left:
border.left = Sides[left]
if right:
border.right = Sides[right]
if top:
border.top = Sides[top]
if bottom:
border.bottom = Sides[bottom]
if border and style:
style["border"] = border
return border
#
#
# def Excel_MakeStyle(
# bold=False,
# italic=False,
# color="black",
# bgcolor=None,
# halign=None,
# valign=None,
# orientation=None,
# font_name=None,
# font_size=None,
# ):
# style = XFStyle()
# make_font(bold, italic, font_name, font_size, color, style=style)
# make_alignment(halign, valign, orientation, style=style)
# make_pattern(bgcolor, style=style)
# return style
#
#
# class ScoExcelSheetExt(ScoExcelSheet):
# def __init__(self, sheet_name="feuille", default_style=None):
# ScoExcelSheet.__init__(self, sheet_name, default_style)
# self.cols_width = {}
# self.row_height = {}
# self.merged = []
# self.panes_frozen = False
# self.horz_split_pos = 0
# self.vert_split_pos = 0
#
# def set_panes(self, panes_frozen=True, horz_split_pos=0, vert_split_pos=0):
# self.panes_frozen = panes_frozen
# self.horz_split_pos = horz_split_pos
# self.vert_split_pos = vert_split_pos
#
# def set_cols_width(self, cols_width):
# self.cols_width = cols_width
#
# def set_row_height(self, row_height):
# self.row_height = row_height
#
# def add_merged(self, first_row, last_row, first_col, last_col, value, style):
# self.merged.append((first_row, last_row, first_col, last_col, value, style))
#
# def gen_workbook(self, wb=None):
# """Generates and returns a workbook from stored data.
# If wb, add a sheet (tab) to the existing workbook (in this case, returns None).
# """
# if wb == None:
# wb = Workbook() # Création du fichier
# sauvegarde = True
# else:
# sauvegarde = False
# ws0 = wb.add_sheet(self.sheet_name.decode(SCO_ENCODING))
# li = 0
# for l in self.cells:
# co = 0
# for c in l:
# # safety net: allow only str, int and float
# if type(c) == LongType:
# c = int(c) # assume all ScoDoc longs fits in int !
# elif type(c) not in (IntType, FloatType):
# c = str(c).decode(SCO_ENCODING)
#
# ws0.write(li, co, c, self.get_cell_style(li, co))
# co += 1
# li += 1
# for first_row, last_row, first_col, last_col, value, style in self.merged:
# ws0.write_merge(
# first_row,
# last_row,
# first_col,
# last_col,
# str(value).decode(SCO_ENCODING),
# style,
# )
# for col_no in range(len(self.cols_width)):
# width = self.cols_width[col_no]
# ws0.col(col_no).width = abs(width) * 110 / 3
# if width < 0:
# ws0.col(col_no).hidden = True
# row_styles = {}
# for row_no in range(len(self.row_height)):
# height = self.row_height[row_no]
# if height not in row_styles:
# fnt = Font()
# fnt.height = height * 12
# row_styles[height] = XFStyle()
# row_styles[height].font = fnt
# ws0.row(row_no).set_style(row_styles[height]) # Excel way
# ws0.row(row_no).height = height * 19 / 2 # Libre-Office compatibilité
# if self.panes_frozen:
# ws0.panes_frozen = self.panes_frozen
# ws0.horz_split_pos = self.vert_split_pos
# ws0.vert_split_pos = self.horz_split_pos
# if sauvegarde:
# return wb.savetostr()
# else:
# return None

View File

@ -0,0 +1,175 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
# Copyright (c) 1999 - 2019 Emmanuel Viennet. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Emmanuel Viennet emmanuel.viennet@viennet.net
#
##############################################################################
""" Excel file formatting
"""
# from sco_excel_add import *
import copy
from enum import IntFlag, Enum
from app.scodoc.sco_excel import excel_make_style
from app.scodoc.sco_excel_add import make_font, make_pattern, make_numfmt, make_borders
class CellBorder(IntFlag):
TOP = 1 << 0
BOTTOM = 1 << 1
LEFT = 1 << 2
RIGHT = 1 << 3
# Liste des modificateurs de format
class CellFormat(IntFlag):
# Mise en Forme usuelle
FMT_CAP_UE = 1 << 4 # UE capitalisée
FMT_MOY = 1 << 5 # Moyenne de semestre
FMT_UE = 1 << 6 # Acquisition d'UE sans validation semestre
# Mise en Forme sur le contenu
EMPHASE_PREC = 1 << 7 # Cause échec de semestre
EMPHASE_ATB = 1 << 8 # Cause échec de semestre
EMPHASE_UEACQ = 1 << 9 # Cause échec de semestre
EMPHASE_ATT = 1 << 10 # Cause échec de semestre
EMPHASE_ABS = 1 << 11 # Absences
EMPHASE_COMP = 1 << 12 # Cause échec de semestre
# Mise en forme numérique
PRECISE = 1 << 20 # Précision de l'affichage
GRAYED = 1 << 22 # Grisé horizontal
# Color palette at : https://groups.google.com/g/python-excel/c/cePI-ojUJfc/m/dH72A-rm6_gJ
class CellColor(Enum):
COLOR_PREC = "D2B48C" # TAN
COLOR_ATB = "93CCEA" # LIGHT CORNFLOWER BLUE
COLOR_ATT = "FE8DB1" # LIGHT ORANGE
COLOR_COMP = "90EE90" # LIGHT GREEN
COLOR_UEACQ = "90EE90" # LIGHT GREEN
COLOR_ABS = "44845E" # LIGHT YELLOW
def format_note(valeur, warning, seuil, mini=True):
if seuil is not None:
if isinstance(valeur, (int, float)):
if mini:
diff = valeur - seuil
else:
diff = seuil - valeur
if -0.20 < diff < 0:
warning += CellFormat.PRECISE
return warning
class Formatter:
def __init__(self):
self.style_table = {}
self.last_rank = None
self.left_borders = []
self.right_borders = []
self.default_top = "none"
self.default_bottom = "none"
self.default_left = "none"
self.default_right = "none"
self.default_format = None
# def add_category(self, left, right):
# self.left_borders.append(left)
# self.right_borders.append(right)
def set_borders_default(self, left="none", top="none", bottom="none", right="none"):
self.default_bottom = bottom
self.default_left = left
self.default_right = right
self.default_top = top
def borders(self, li, co):
index = 0
index |= CellBorder.TOP if li == 0 else 0
index |= CellBorder.BOTTOM if self.last_rank and li == self.last_rank else 0
index |= CellBorder.LEFT if co in self.left_borders else 0
index |= CellBorder.RIGHT if co in self.right_borders else 0
return index
def get_style(self, index=0):
if index not in self.style_table:
border_enable = "filet"
if self.default_format:
style = copy.copy(self.default_format)
else:
style = excel_make_style()
make_font(
style=style,
font_name="Calibri",
font_size=9,
bold=(CellFormat.FMT_MOY & index),
uline=(CellFormat.FMT_CAP_UE & index),
)
make_borders(
style=style, left="none", right="none", top="filet", bottom="filet"
)
if index & CellFormat.EMPHASE_ATB:
make_pattern(style=style, bgcolor=CellColor.COLOR_ATB.value)
elif index & CellFormat.EMPHASE_ATT:
make_pattern(style=style, bgcolor=CellColor.COLOR_ATT.value)
elif index & CellFormat.EMPHASE_PREC:
make_pattern(style=style, bgcolor=CellColor.COLOR_PREC.value)
elif index & CellFormat.EMPHASE_COMP:
make_pattern(style=style, bgcolor=CellColor.COLOR_COMP.value)
elif index & CellFormat.EMPHASE_UEACQ:
make_pattern(style=style, bgcolor=CellColor.COLOR_UEACQ.value)
elif index & CellFormat.EMPHASE_ABS:
make_pattern(style=style, bgcolor=CellColor.COLOR_ABS.value)
# elif not index & GRAYED:
# make_pattern(style=style, bgcolor=0x43)
if index & (CellFormat.FMT_CAP_UE | CellFormat.FMT_UE | CellFormat.FMT_MOY):
if index & CellFormat.PRECISE:
make_numfmt("#0.00", style)
else:
make_numfmt("#0.0", style)
top = border_enable if index & CellBorder.TOP else self.default_top
bottom = border_enable if index & CellBorder.BOTTOM else self.default_bottom
left = border_enable if index & CellBorder.LEFT else self.default_left
right = border_enable if index & CellBorder.RIGHT else self.default_right
make_borders(style=style, top=top, left=left, right=right, bottom=bottom)
self.style_table[index] = style
return self.style_table[index]
def width(self, item):
if item is None:
return 1
else:
compte = 0
for subitem in item.values():
compte += self.width(subitem)
return compte
def set_default_format(self, default_format):
self.default_format = default_format

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,7 @@
import collections import collections
import logging import logging
import time import time
from enum import Enum
from openpyxl.styles.numbers import FORMAT_NUMBER_00 from openpyxl.styles.numbers import FORMAT_NUMBER_00
@ -56,6 +57,307 @@ from app.scodoc import sco_cursus
from app.scodoc import sco_preferences from app.scodoc import sco_preferences
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
import sco_version import sco_version
from app.scodoc.sco_excel import excel_make_style, COLORS
from app.scodoc.sco_excel_add import make_pattern
from app.scodoc.sco_prepajury_formats import Formatter
COLORS = {
"ETUDIANT": ["FFFF99"],
"BUT1": ["95B3D7", "B8CCE4", "DCE6F1"],
"BUT2": ["C4D79B", "D8E4BC", "EBF1DE"],
"BUT3": ["FABF8F", "FCD5B4", "FDE9D9"],
"RECAP": ["D9D9D9"],
}
CATEGORIES = {
"ETUDIANT": {
"Id": None,
"NIP": None,
"civ": None,
"Nom": None,
"Prénom": None,
"Régime": None,
"Cursus": None,
"Absences": {
"Tot.": None,
"Non Just": None,
},
},
"BUT1": {
"+<comp 1>": {
"+UE 1.1": {
"Note": None,
"Rés.": None,
},
"+UE 2.1": {
"Note": None,
"Rés.": None,
},
"BCC 1": {
"Note": None,
"Rés.": None,
},
},
"+<comp 2>": {
"+UE 1.2": {
"Note": None,
"Rés.": None,
},
"+UE 2.2": {
"Note": None,
"Rés.": None,
},
"BCC 2": {
"Note": None,
"Rés.": None,
},
},
"+<comp 3>": {
"+UE 1.3": {
"Note": None,
"Rés.": None,
},
"+UE 2.3": {
"Note": None,
"Rés.": None,
},
"BCC 3": {
"Note": None,
"Rés.": None,
},
},
"+<comp 4>": {
"+UE 1.4": {
"Note": None,
"Rés.": None,
},
"+UE 2.4": {
"Note": None,
"Rés.": None,
},
"BCC 4": {
"Note": None,
"Rés.": None,
},
},
"+<comp 5>": {
"+UE 1.5": {
"Note": None,
"Rés.": None,
},
"+UE 2.5": {
"Note": None,
"Rés.": None,
},
"BCC 5": {
"Note": None,
"Rés.": None,
},
},
"+<comp 6>": {
"+UE 1.6": {
"Note": None,
"Rés.": None,
},
"+UE 2.6": {
"Note": None,
"Rés.": None,
},
"BCC 6": {
"Note": None,
"Rés.": None,
},
},
"Nb RCUE": None,
"Moy.": None,
"Rés.": None,
},
"BUT2": {
"+<comp 1>": {
"+UE 3.1": {
"Note": None,
"Rés.": None,
},
"+UE 4.1": {
"Note": None,
"Rés.": None,
},
"BCC 4": {
"Note": None,
"Rés.": None,
},
},
"+<comp 2>": {
"+UE 3.2": {
"Note": None,
"Rés.": None,
},
"+UE 4.2": {
"Note": None,
"Rés.": None,
},
"BCC 4": {
"Note": None,
"Rés.": None,
},
},
"+<comp 3>": {
"+UE 3.3": {
"Note": None,
"Rés.": None,
},
"+UE 4.3": {
"Note": None,
"Rés.": None,
},
"BCC 4": {
"Note": None,
"Rés.": None,
},
},
"+<comp 4>": {
"+UE 3.4": {
"Note": None,
"Rés.": None,
},
"+UE 4.4": {
"Note": None,
"Rés.": None,
},
"BCC 4": {
"Note": None,
"Rés.": None,
},
},
"+<comp 5>": {
"+UE 3.5": {
"Note": None,
"Rés.": None,
},
"+UE 4.5": {
"Note": None,
"Rés.": None,
},
"BCC 5": {
"Note": None,
"Rés.": None,
},
},
"+<comp 6>": {
"+UE 3.6": {
"Note": None,
"Rés.": None,
},
"+UE 4.6": {
"Note": None,
"Rés.": None,
},
"BCC 6": {
"Note": None,
"Rés.": None,
},
},
"Nb RCUE": None,
"Moy.": None,
"Rés.": None,
"DUT": None,
},
"BUT3": {
"+<comp 1>": {
"+UE 5.1": {
"Note": None,
"Rés.": None,
},
"+UE 6.1": {
"Note": None,
"Rés.": None,
},
"BCC 1": {
"Note": None,
"Rés.": None,
},
},
"+<comp 2>": {
"+UE 5.2": {
"Note": None,
"Rés.": None,
},
"+UE 6.2": {
"Note": None,
"Rés.": None,
},
"BCC 2": {
"Note": None,
"Rés.": None,
},
},
"+<comp 3>": {
"+UE 5.3": {
"Note": None,
"Rés.": None,
},
"+UE 6.3": {
"Note": None,
"Rés.": None,
},
"BCC 3": {
"Note": None,
"Rés.": None,
},
},
"+<comp 4>": {
"+UE 5.4": {
"Note": None,
"Rés.": None,
},
"+UE 6.4": {
"Note": None,
"Rés.": None,
},
"BCC 4": {
"Note": None,
"Rés.": None,
},
},
"+<comp 5>": {
"+UE 5.5": {
"Note": None,
"Rés.": None,
},
"+UE 6.5": {
"Note": None,
"Rés.": None,
},
"BCC 5": {
"Note": None,
"Rés.": None,
},
},
"+<comp 6>": {
"+UE 5.6": {
"Note": None,
"Rés.": None,
},
"+UE 6.6": {
"Note": None,
"Rés.": None,
},
"BCC 6": {
"Note": None,
"Rés.": None,
},
},
"Nb RCUE": None,
"Moy.": None,
"Rés.": None,
"BUT": None,
},
"RECAP": {
"Devenir": None,
"Etape": None,
"Remarque": None,
},
}
class IndexApc: class IndexApc:
@ -85,13 +387,17 @@ class Export:
main_partition_id = sco_groups.formsemestre_get_main_partition(formsemestre_id) main_partition_id = sco_groups.formsemestre_get_main_partition(formsemestre_id)
self.etuds = self.nt.get_inscrits(order_by="moy") self.etuds = self.nt.get_inscrits(order_by="moy")
self.formation_code = self.formsemestre.formation.formation_code self.formation_code = self.formsemestre.formation.formation_code
self.dept_name = scu.unescape_html(
sco_preferences.get_preference("DeptName", formsemestre_id)
)
self.parcours = {} self.parcours = {}
self.competences = {} self.competences = {}
self.data_etud = {} self.data_etud = {}
self.data_sems = {} self.data_sems = {}
self.data_comp = {} self.data_comp = {}
self.load_data() self.load_data()
breakpoint() self.formatteur = Formatter()
self.build_formator()
def load_parcours(self): def load_parcours(self):
for etud in self.etuds: for etud in self.etuds:
@ -127,6 +433,16 @@ class Export:
else: else:
current_app.logger.info(f"{etud.id}: Changement de parcours: ") current_app.logger.info(f"{etud.id}: Changement de parcours: ")
def load_etu(self, etud):
# etudid=str(etudid),
# code_nip=etud.code_nip or "",
# code_ine=etud.code_ine or "",
# nom=quote_xml_attr(etud.nom),
# prenom=quote_xml_attr(etud.prenom),
# civilite=quote_xml_attr(etud.civilite_str),
# sexe=quote_xml_attr(etud.civilite_str), # compat
pass
def load_data(self): def load_data(self):
self.load_parcours() self.load_parcours()
for etud in self.etuds: for etud in self.etuds:
@ -134,107 +450,112 @@ class Export:
self.data_etud[etud.id]["etud"] = etud self.data_etud[etud.id]["etud"] = etud
self.data_etud[etud.id]["sems"] = {} self.data_etud[etud.id]["sems"] = {}
session = sco_cursus.get_situation_etud_cursus(etud, self.formsemestre_id) session = sco_cursus.get_situation_etud_cursus(etud, self.formsemestre_id)
breakpoint()
self.data_etud[etud.id]["cursus"] = session.parcours
self.load_formsemestre(etud, session) self.load_formsemestre(etud, session)
breakpoint()
def build_formator(self):
self.formatteur = Formatter()
self.formatteur.set_default_format(
excel_make_style(font_name="Calibri", size=9)
)
self.formatteur.set_borders_default(
left="none", right="none", top="filet", bottom="filet"
)
self.formatteur.last_rank = 10 # len(lignes)
# self.formatteur.set_categories(CATEGORIES)
def header_format(self, styles, items, row_no, left, color, level):
if row_no <= 4:
if items is None:
# styles[row_no].append(color[level])
styles[row_no].append(excel_make_style(bgcolor=color[level]))
self.header_format(styles, None, row_no + 1, left, color, level)
return 1
else:
color = items.get("COLOR", color)
compte = 0
for item in items:
if item in COLORS:
color = COLORS[item]
detail = items[item]
if item[0] == "+":
level2 = level + 1
else:
level2 = level
styles[row_no].append(excel_make_style(bgcolor=color[level2]))
nbelt = self.header_format(
styles,
detail,
row_no + 1,
left + compte,
color,
level2,
)
for _ in range(1, nbelt):
styles[row_no].append(excel_make_style(bgcolor=color[level2]))
compte += nbelt
# current_app.logger.info(f" {row_no}, {left}, {nbelt} ")
# sheet.ws.merge_cells(
# start_row=row_no + 1,
# end_row=row_no + 1,
# start_column=left + 1,
# end_column=left + nbelt + 1,
# )
return compte
else:
return 1
def header_append(self, raws, items, row_no):
if row_no <= 4:
if items is None:
raws[row_no].append("")
self.header_append(raws, None, row_no + 1)
return 1
else:
compte = 0
for item in items:
if item != "COLOR":
detail = items[item]
if item[0] != "+":
raws[row_no].append(item)
else:
raws[row_no].append(item[1:])
nbelt = self.header_append(raws, detail, row_no + 1)
for _ in range(1, nbelt):
raws[row_no].append("")
compte += nbelt
return compte
else:
return 1
def write_header(self, sheet):
raws = [[], [], [], [], []]
styles = [[], [], [], [], []]
col_no = 0
raw_no = 0
self.header_format(styles, CATEGORIES, 0, 0, ["FFFF00"], 0)
self.header_append(raws, CATEGORIES, 0)
for i in range(0, 4):
sheet.append_row(
sheet.make_row(
raws[i],
styles[i],
# style=excel_make_style(
# font_name="Calibri", size=12, bold=False, bgcolor="D0FFFF"
# ),
)
)
sheet.ws.merge_cells(start_row=9, end_row=8, start_column=1, end_column=10)
def feuille_preparation_lille(formsemestre_id): def feuille_preparation_lille(formsemestre_id):
"""Feuille excel pour préparation des jurys classiques. """Feuille excel pour préparation des jurys classiques."""
Non adaptée pour le BUT.
"""
export = Export(formsemestre_id) export = Export(formsemestre_id)
prev_moy_ue = collections.defaultdict(dict) # ue_code_s : { etudid : moy ue }
prev_ue_acro = {} # ue_code_s : acronyme (à afficher)
prev_moy = {} # moyennes gen sem prec
moy_ue = collections.defaultdict(dict) # ue_acro : moyennes { etudid : moy ue }
ue_acro = {} # ue_code_s : acronyme (à afficher)
moy = {} # moyennes gen
moy_inter = {} # moyenne gen. sur les 2 derniers semestres
code = {} # decision existantes s'il y en a
autorisations = {}
prev_code = {} # decisions sem prec
assidu = {}
parcours = {} # etudid : parcours, sous la forme S1, S2, S2, S3
groupestd = {} # etudid : nom groupe principal
nbabs = {}
nbabsjust = {}
for etud in etuds:
Se = sco_cursus.get_situation_etud_cursus(etud, formsemestre_id)
if Se.prev_formsemestre:
ntp: NotesTableCompat = res_sem.load_formsemestre_results(
Se.prev_formsemestre
)
for ue in ntp.get_ues_stat_dict(filter_sport=True):
ue_status = ntp.get_etud_ue_status(etud.id, ue["ue_id"])
ue_code_s = (
ue["ue_code"] + "_%s" % ntp.sem["semestre_id"]
) # code indentifiant l'UE
prev_moy_ue[ue_code_s][etud.id] = ue_status["moy"] if ue_status else ""
prev_ue_acro[ue_code_s] = (ue["numero"], ue["acronyme"], ue["titre"])
prev_moy[etud.id] = ntp.get_etud_moy_gen(etud.id)
prev_decision = ntp.get_etud_decision_sem(etud.id)
if prev_decision:
prev_code[etud.id] = prev_decision["code"]
if prev_decision["compense_formsemestre_id"]:
prev_code[etud.id] += "+" # indique qu'il a servi a compenser
moy[etud.id] = nt.get_etud_moy_gen(etud.id) sheet = sco_excel.ScoExcelSheet(sheet_name=f"Prepation Jury")
for ue in nt.get_ues_stat_dict(filter_sport=True):
ue_status = nt.get_etud_ue_status(etud.id, ue["ue_id"])
ue_code_s = f'{ue["ue_code"]}_{nt.sem["semestre_id"]}'
moy_ue[ue_code_s][etud.id] = ue_status["moy"] if ue_status else ""
ue_acro[ue_code_s] = (ue["numero"], ue["acronyme"], ue["titre"])
if Se.prev_formsemestre:
try:
moy_inter[etud.id] = (moy[etud.id] + prev_moy[etud.id]) / 2.0
except (KeyError, TypeError):
pass
decision = nt.get_etud_decision_sem(etud.id)
if decision:
code[etud.id] = decision["code"]
if decision["compense_formsemestre_id"]:
code[etud.id] += "+" # indique qu'il a servi a compenser
assidu[etud.id] = {False: "Non", True: "Oui"}.get(decision["assidu"], "")
autorisations_etud = ScolarAutorisationInscription.query.filter_by(
etudid=etud.id, origin_formsemestre_id=formsemestre_id
).all()
autorisations[etud.id] = ", ".join(
[f"S{x.semestre_id}" for x in autorisations_etud]
)
# parcours:
parcours[etud.id] = Se.get_cursus_descr()
# groupe principal (td)
groupestd[etud.id] = etud_groups.get(etud.id, {}).get(main_partition_id, "")
# absences:
_, nbabsjust[etud.id], nbabs[etud.id] = sco_assiduites.get_assiduites_count(
etud.id, sem
)
# Codes des UE "semestre précédent":
ue_prev_codes = list(prev_moy_ue.keys())
ue_prev_codes.sort(
key=lambda x, prev_ue_acro=prev_ue_acro: prev_ue_acro[ # pylint: disable=undefined-variable
x
]
)
# Codes des UE "semestre courant":
ue_codes = list(moy_ue.keys())
ue_codes.sort(
key=lambda x, ue_acro=ue_acro: ue_acro[x] # pylint: disable=undefined-variable
)
sid = sem["semestre_id"]
sn = sp = ""
if sid >= 0:
sn = f"S{sid}"
if prev_moy: # si qq chose dans precedent
sp = f"S{sid - 1}"
sheet = sco_excel.ScoExcelSheet(sheet_name=f"Prepa Jury {sn}")
# génération des styles # génération des styles
style_bold = sco_excel.excel_make_style(size=10, bold=True) style_bold = sco_excel.excel_make_style(size=10, bold=True)
style_center = sco_excel.excel_make_style(halign="center") style_center = sco_excel.excel_make_style(halign="center")
style_boldcenter = sco_excel.excel_make_style(bold=True, halign="center") style_boldcenter = sco_excel.excel_make_style(bold=True, halign="center")
@ -249,10 +570,11 @@ def feuille_preparation_lille(formsemestre_id):
) )
# Première ligne # Première ligne
sheet.append_single_cell_row( # sheet.append_single_cell_row(
"Feuille préparation Jury %s" % scu.unescape_html(sem["titreannee"]), style_bold # "Feuille préparation Jury %s" % scu.unescape_html(sem["titreannee"]), style_bold
) # )
sheet.append_blank_row() sheet.append_blank_row()
export.write_header(sheet)
# Ligne de titre # Ligne de titre
titles = ["Rang"] titles = ["Rang"]
@ -260,154 +582,138 @@ def feuille_preparation_lille(formsemestre_id):
titles.append("NIP") titles.append("NIP")
if sco_preferences.get_preference("prepa_jury_ine"): if sco_preferences.get_preference("prepa_jury_ine"):
titles.append("INE") titles.append("INE")
titles += [ # if prev_moy: # si qq chose dans precedent
"etudid", # titles += [prev_ue_acro[x][1] for x in ue_prev_codes] + [
"Civ.", # f"Moy {sp}",
"Nom", # f"Décision {sp}",
"Prénom", # ]
"Naissance", # titles += [ue_acro[x][1] for x in ue_codes] + [f"Moy {sn}"]
"Bac", # if moy_inter:
"Spe", # titles += [f"Moy {sp}-{sn}"]
"Rg Adm", # titles += ["Abs", "Abs Injust."]
"Parcours", # if code:
"Groupe", # titles.append("Proposit. {sn}")
] # if autorisations:
if prev_moy: # si qq chose dans precedent # titles.append("Autorisations")
titles += [prev_ue_acro[x][1] for x in ue_prev_codes] + [ # # titles.append('Assidu')
f"Moy {sp}", # sheet.append_row(sheet.make_row(titles, style_boldcenter))
f"Décision {sp}", # def fmt(x):
] # "reduit les notes a deux chiffres"
titles += [ue_acro[x][1] for x in ue_codes] + [f"Moy {sn}"] # x = scu.fmt_note(x, keep_numeric=False)
if moy_inter: # try:
titles += [f"Moy {sp}-{sn}"] # return float(x)
titles += ["Abs", "Abs Injust."] # except:
if code: # return x
titles.append("Proposit. {sn}")
if autorisations:
titles.append("Autorisations")
# titles.append('Assidu')
sheet.append_row(sheet.make_row(titles, style_boldcenter))
# if prev_moy:
# tit_prev_moy = "Moy " + sp
# # col_prev_moy = titles.index(tit_prev_moy)
# tit_moy = "Moy " + sn
# col_moy = titles.index(tit_moy)
# col_abs = titles.index("Abs")
def fmt(x):
"reduit les notes a deux chiffres"
x = scu.fmt_note(x, keep_numeric=False)
try:
return float(x)
except:
return x
i = 1 # numero etudiant
for etud in etuds:
cells = []
cells.append(sheet.make_cell(str(i)))
if sco_preferences.get_preference("prepa_jury_nip"):
cells.append(sheet.make_cell(etud.code_nip))
if sco_preferences.get_preference("prepa_jury_ine"):
cells.append(sheet.make_cell(etud.code_ine))
cells += sheet.make_row(
[
etud.id,
etud.civilite_str,
scu.format_nom(etud.nom),
scu.format_prenom(etud.prenom),
etud.date_naissance,
etud.admission.bac if etud.admission else "",
etud.admission.specialite if etud.admission else "",
etud.admission.classement if etud.admission else "",
parcours[etud.id],
groupestd[etud.id],
]
)
co = len(cells)
if prev_moy:
for ue_acro in ue_prev_codes:
cells.append(
sheet.make_cell(
fmt(prev_moy_ue.get(ue_acro, {}).get(etud.id, "")), style_note
)
)
co += 1
cells.append(
sheet.make_cell(fmt(prev_moy.get(etud.id, "")), style_bold)
) # moy gen prev
cells.append(
sheet.make_cell(fmt(prev_code.get(etud.id, "")), style_moy)
) # decision prev
co += 2
for ue_acro in ue_codes:
cells.append(
sheet.make_cell(
fmt(moy_ue.get(ue_acro, {}).get(etud.id, "")), style_note
)
)
co += 1
cells.append(
sheet.make_cell(fmt(moy.get(etud.id, "")), style_note_bold)
) # moy gen
co += 1
if moy_inter:
cells.append(sheet.make_cell(fmt(moy_inter.get(etud.id, "")), style_note))
cells.append(sheet.make_cell(nbabs.get(etud.id, ""), style_center))
cells.append(sheet.make_cell(nbabsjust.get(etud.id, ""), style_center))
if code:
cells.append(sheet.make_cell(code.get(etud.id, ""), style_moy))
cells.append(sheet.make_cell(autorisations.get(etud.id, ""), style_moy))
# l.append(assidu.get(etud.id, ''))
sheet.append_row(cells)
i += 1
# #
sheet.append_blank_row() # i = 1 # numero etudiant
# Explications des codes # for etud in etuds:
codes = list(codes_cursus.CODES_EXPL.keys()) # cells = []
codes.sort() # cells.append(sheet.make_cell(str(i)))
sheet.append_single_cell_row("Explication des codes") # if sco_preferences.get_preference("prepa_jury_nip"):
for code in codes: # cells.append(sheet.make_cell(etud.code_nip))
sheet.append_row( # if sco_preferences.get_preference("prepa_jury_ine"):
sheet.make_row(["", "", "", code, codes_cursus.CODES_EXPL[code]]) # cells.append(sheet.make_cell(etud.code_ine))
) # cells += sheet.make_row(
sheet.append_row( # [
sheet.make_row( # etud.id,
[ # etud.civilite_str,
"", # scu.format_nom(etud.nom),
"", # scu.format_prenom(etud.prenom),
"", # etud.date_naissance,
"ADM+", # etud.admission.bac if etud.admission else "",
"indique que le semestre a déjà servi à en compenser un autre", # etud.admission.specialite if etud.admission else "",
] # etud.admission.classement if etud.admission else "",
) # parcours[etud.id],
) # groupestd[etud.id],
# ]
# )
# co = len(cells)
# if prev_moy:
# for ue_acro in ue_prev_codes:
# cells.append(
# sheet.make_cell(
# fmt(prev_moy_ue.get(ue_acro, {}).get(etud.id, "")), style_note
# )
# )
# co += 1
# cells.append(
# sheet.make_cell(fmt(prev_moy.get(etud.id, "")), style_bold)
# ) # moy gen prev
# cells.append(
# sheet.make_cell(fmt(prev_code.get(etud.id, "")), style_moy)
# ) # decision prev
# co += 2
#
# for ue_acro in ue_codes:
# cells.append(
# sheet.make_cell(
# fmt(moy_ue.get(ue_acro, {}).get(etud.id, "")), style_note
# )
# )
# co += 1
# cells.append(
# sheet.make_cell(fmt(moy.get(etud.id, "")), style_note_bold)
# ) # moy gen
# co += 1
# if moy_inter:
# cells.append(sheet.make_cell(fmt(moy_inter.get(etud.id, "")), style_note))
# cells.append(sheet.make_cell(nbabs.get(etud.id, ""), style_center))
# cells.append(sheet.make_cell(nbabsjust.get(etud.id, ""), style_center))
# if code:
# cells.append(sheet.make_cell(code.get(etud.id, ""), style_moy))
# cells.append(sheet.make_cell(autorisations.get(etud.id, ""), style_moy))
# # l.append(assidu.get(etud.id, ''))
# sheet.append_row(cells)
# i += 1
# #
# sheet.append_blank_row()
# # Explications des codes
# codes = list(codes_cursus.CODES_EXPL.keys())
# codes.sort()
# sheet.append_single_cell_row("Explication des codes")
# for code in codes:
# sheet.append_row(
# sheet.make_row(["", "", "", code, codes_cursus.CODES_EXPL[code]])
# )
# sheet.append_row(
# sheet.make_row(
# [
# "",
# "",
# "",
# "ADM+",
# "indique que le semestre a déjà servi à en compenser un autre",
# ]
# )
# )
# UE : Correspondances acronyme et titre complet # UE : Correspondances acronyme et titre complet
sheet.append_blank_row() sheet.append_blank_row()
sheet.append_single_cell_row("Titre des UE")
if prev_moy: # sheet.append_single_cell_row("Titre des UE")
for ue in ntp.get_ues_stat_dict(filter_sport=True): # if prev_moy:
sheet.append_row(sheet.make_row(["", "", "", ue["acronyme"], ue["titre"]])) # for ue in ntp.get_ues_stat_dict(filter_sport=True):
for ue in nt.get_ues_stat_dict(filter_sport=True): # sheet.append_row(sheet.make_row(["", "", "", ue["acronyme"], ue["titre"]]))
sheet.append_row(sheet.make_row(["", "", "", ue["acronyme"], ue["titre"]])) # for ue in nt.get_ues_stat_dict(filter_sport=True):
# # sheet.append_row(sheet.make_row(["", "", "", ue["acronyme"], ue["titre"]]))
sheet.append_blank_row() # #
sheet.append_single_cell_row( # sheet.append_blank_row()
"Préparé par %s le %s sur %s pour %s" # sheet.append_single_cell_row(
% ( # "Préparé par %s le %s sur %s pour %s"
sco_version.SCONAME, # % (
time.strftime(scu.DATE_FMT), # sco_version.SCONAME,
request.url_root, # time.strftime(scu.DATE_FMT),
current_user, # request.url_root,
) # current_user,
) # )
# )
xls = sheet.generate() xls = sheet.generate()
flash("Feuille préparation jury générée") flash("Feuille préparation jury générée")
return scu.send_file( return scu.send_file(
xls, xls,
f"PrepaJury{sn}", f"PrepaJury",
scu.XLSX_SUFFIX, scu.XLSX_SUFFIX,
mime=scu.XLSX_MIMETYPE, mime=scu.XLSX_MIMETYPE,
) )