avant upgrade

This commit is contained in:
Jean-Marie Place 2024-06-24 06:41:26 +02:00
commit 9a6a90862c
5 changed files with 2197 additions and 264 deletions

View File

@ -161,7 +161,10 @@ def excel_make_style(
)
style["font"] = font
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:
al = Alignment()
if halign:
@ -348,15 +351,21 @@ class ScoExcelSheet:
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"
# TODO make possible differents styles in a row
if comments is None:
comments = [None] * len(values)
return [
self.make_cell(value, style, comment)
for value, comment in zip(values, comments)
]
if isinstance(styles, list):
return [
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):
"""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

@ -5,7 +5,7 @@
#
# Gestion scolarite IUT
#
# Copyright (c) 1999 - 2023 Emmanuel Viennet. All rights reserved.
# Copyright (c) 1999 - 2024 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
@ -28,18 +28,27 @@
"""Feuille excel pour préparation des jurys classiques (non BUT)
"""
import collections
import logging
import time
from enum import Enum
from openpyxl.styles.numbers import FORMAT_NUMBER_00
from flask import flash
from flask import flash, current_app
from flask import request
from flask_login import current_user
from app import db
from app.comp import res_sem
from app.comp.res_compat import NotesTableCompat
from app.models import FormSemestre, Identite, ScolarAutorisationInscription
from app.scodoc import sco_assiduites, codes_cursus
from app.models import (
FormSemestre,
Identite,
ScolarAutorisationInscription,
ApcParcours,
)
from app.scodoc import sco_assiduites
from app.scodoc import codes_cursus
from app.scodoc import sco_groups
from app.scodoc import sco_etud
from app.scodoc import sco_excel
@ -48,121 +57,505 @@ from app.scodoc import sco_cursus
from app.scodoc import sco_preferences
import app.scodoc.sco_utils as scu
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:
def __init__(self):
self.niveau: int = None
self.rcue: int = None
self.semestre: int = None
def __init__(self, niveau):
self.__init__()
self.niveau = niveau
def __init__(self, niveau, ue):
self.__init__(niveau)
def __init__(self, niveau, ue, semestre):
self.__init__(niveau, ue)
self.semestre = semestre
class Export:
def __init__(self, formsemestre_id):
self.formsemestre_id: int = formsemestre_id
self.formsemestre: FormSemestre = FormSemestre.get_formsemestre(formsemestre_id)
self.nt: NotesTableCompat = res_sem.load_formsemestre_results(self.formsemestre)
etud_groups = sco_groups.formsemestre_get_etud_groupnames(formsemestre_id)
main_partition_id = sco_groups.formsemestre_get_main_partition(formsemestre_id)
self.etuds = self.nt.get_inscrits(order_by="moy")
self.formation_code = self.formsemestre.formation.formation_code
self.dept_name = scu.unescape_html(
sco_preferences.get_preference("DeptName", formsemestre_id)
)
self.parcours = {}
self.competences = {}
self.data_etud = {}
self.data_sems = {}
self.data_comp = {}
self.load_data()
self.formatteur = Formatter()
self.build_formator()
def load_parcours(self):
for etud in self.etuds:
parcours_id = self.nt.etuds_parcour_id[etud.id]
if parcours_id is not None and parcours_id not in self.data_comp:
parcours = db.session.get(ApcParcours, parcours_id)
self.data_comp[parcours_id] = parcours
def load_formsemestre_data(self, formsemestre: FormSemestre):
sem_id = formsemestre.id
self.data_sems[sem_id] = {}
self.data_sems[sem_id]["formsemestre"] = formsemestre
nt = res_sem.load_formsemestre_results(formsemestre)
self.data_sems[sem_id]["nt"] = nt
def load_formsemestre(self, etud, session):
for sem in session.sems:
if sem["formation"].formation_code == self.formation_code:
sem_id = sem["id"]
formsemestre: FormSemestre = FormSemestre.get_formsemestre(sem_id)
if sem_id not in self.data_sems:
self.load_formsemestre_data(formsemestre)
if session.prev_formsemestre:
prev_id = session.prev_formsemestre.id
prev_session = sco_cursus.get_situation_etud_cursus(
etud, prev_id
)
self.load_formsemestre(etud, prev_session)
semestre_id = formsemestre.semestre_id
parcours = self.data_sems[sem_id]["nt"].etuds_parcour_id[etud.id]
if parcours is None or parcours == self.nt.etuds_parcour_id[etud.id]:
self.data_etud[etud.id]["sems"][semestre_id] = formsemestre
else:
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):
self.load_parcours()
for etud in self.etuds:
self.data_etud[etud.id] = {}
self.data_etud[etud.id]["etud"] = etud
self.data_etud[etud.id]["sems"] = {}
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)
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):
"""Feuille excel pour préparation des jurys classiques.
Non adaptée pour le BUT.
"""
formsemestre = FormSemestre.query.get_or_404(formsemestre_id)
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
breakpoint()
etuds: list[Identite] = nt.get_inscrits(order_by="moy") # tri par moy gen
sem = sco_formsemestre.get_formsemestre(formsemestre_id)
"""Feuille excel pour préparation des jurys classiques."""
export = Export(formsemestre_id)
etud_groups = sco_groups.formsemestre_get_etud_groupnames(formsemestre_id)
main_partition_id = sco_groups.formsemestre_get_main_partition(formsemestre_id)[
"partition_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 = {}
breakpoint()
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)
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] = "sco_prepajury_lille:132" # Se.get_parcours_descr()
# groupe principal (td)
groupestd[etud.id] = ""
for s in Se.etud.formsemestre_inscriptions:
if s.formsemestre_id == formsemestre_id:
groupestd[etud.id] = etud_groups.get(etud.id, {}).get(
main_partition_id, ""
)
# absences:
_, e_nbabsjust, e_nbabs = sco_assiduites.get_assiduites_count(etud.id, sem)
nbabs[etud.id] = e_nbabs
nbabsjust[etud.id] = e_nbabs - e_nbabsjust
# 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}")
sheet = sco_excel.ScoExcelSheet(sheet_name=f"Prepation Jury")
# génération des styles
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")
@ -177,10 +570,11 @@ def feuille_preparation_lille(formsemestre_id):
)
# Première ligne
sheet.append_single_cell_row(
"Feuille préparation Jury %s" % scu.unescape_html(sem["titreannee"]), style_bold
)
# sheet.append_single_cell_row(
# "Feuille préparation Jury %s" % scu.unescape_html(sem["titreannee"]), style_bold
# )
sheet.append_blank_row()
export.write_header(sheet)
# Ligne de titre
titles = ["Rang"]
@ -188,154 +582,138 @@ def feuille_preparation_lille(formsemestre_id):
titles.append("NIP")
if sco_preferences.get_preference("prepa_jury_ine"):
titles.append("INE")
titles += [
"etudid",
"Civ.",
"Nom",
"Prénom",
"Naissance",
"Bac",
"Spe",
"Rg Adm",
"Parcours",
"Groupe",
]
if prev_moy: # si qq chose dans precedent
titles += [prev_ue_acro[x][1] for x in ue_prev_codes] + [
f"Moy {sp}",
f"Décision {sp}",
]
titles += [ue_acro[x][1] for x in ue_codes] + [f"Moy {sn}"]
if moy_inter:
titles += [f"Moy {sp}-{sn}"]
titles += ["Abs", "Abs Injust."]
if code:
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))
admission = etud.admission
cells += sheet.make_row(
[
etud.id,
etud.civilite_str,
sco_etud.format_nom(etud.nom),
sco_etud.format_prenom(etud.prenom),
etud.date_naissance,
admission.bac,
admission.specialite,
admission.classement,
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(str(nbabs.get(etud.id, "")), style_center))
cells.append(sheet.make_cell(str(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
# if prev_moy: # si qq chose dans precedent
# titles += [prev_ue_acro[x][1] for x in ue_prev_codes] + [
# f"Moy {sp}",
# f"Décision {sp}",
# ]
# titles += [ue_acro[x][1] for x in ue_codes] + [f"Moy {sn}"]
# if moy_inter:
# titles += [f"Moy {sp}-{sn}"]
# titles += ["Abs", "Abs Injust."]
# if code:
# titles.append("Proposit. {sn}")
# if autorisations:
# titles.append("Autorisations")
# # titles.append('Assidu')
# sheet.append_row(sheet.make_row(titles, style_boldcenter))
# def fmt(x):
# "reduit les notes a deux chiffres"
# x = scu.fmt_note(x, keep_numeric=False)
# try:
# return float(x)
# except:
# return x
#
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",
]
)
)
# 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()
# # 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
sheet.append_blank_row()
sheet.append_single_cell_row("Titre des UE")
if prev_moy:
for ue in ntp.get_ues_stat_dict(filter_sport=True):
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(
"Préparé par %s le %s sur %s pour %s"
% (
sco_version.SCONAME,
time.strftime("%d/%m/%Y"),
request.url_root,
current_user,
)
)
# sheet.append_single_cell_row("Titre des UE")
# if prev_moy:
# for ue in ntp.get_ues_stat_dict(filter_sport=True):
# 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(
# "Préparé par %s le %s sur %s pour %s"
# % (
# sco_version.SCONAME,
# time.strftime(scu.DATE_FMT),
# request.url_root,
# current_user,
# )
# )
xls = sheet.generate()
flash("Feuille préparation jury générée")
return scu.send_file(
xls,
f"PrepaJury{sn}",
f"PrepaJury",
scu.XLSX_SUFFIX,
mime=scu.XLSX_MIMETYPE,
)