forked from ScoDoc/ScoDoc
construction of styles WIP
This commit is contained in:
parent
646173c9ac
commit
cfe74da499
230
app/but/prepajury_but.py
Normal file
230
app/but/prepajury_but.py
Normal file
@ -0,0 +1,230 @@
|
||||
# -*- mode: python -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gestion scolarite IUT
|
||||
#
|
||||
# Copyright (c) 1999 - 2023 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
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
"""Feuille excel pour préparation des jurys classiques (non BUT)
|
||||
"""
|
||||
import collections
|
||||
import time
|
||||
|
||||
from flask import flash, abort
|
||||
|
||||
from app.but.cursus_but import EtudCursusBUT
|
||||
from app.but.prepajury_cells import Cell
|
||||
from app.but.prepajury_desc import ParcoursDesc
|
||||
from app.comp import res_sem
|
||||
from app.comp.res_but import ResultatsSemestreBUT
|
||||
from app.models import (
|
||||
FormSemestre,
|
||||
Identite,
|
||||
ScolarAutorisationInscription,
|
||||
ApcParcours,
|
||||
Formation,
|
||||
ApcCompetence,
|
||||
)
|
||||
import app.scodoc.sco_utils as scu
|
||||
from app.scodoc.sco_excel import ScoExcelBook, ScoExcelSheet
|
||||
|
||||
|
||||
class _Bilan:
|
||||
def __init__(self):
|
||||
self.note = 0
|
||||
self.resultat = 0
|
||||
self.format = 0
|
||||
|
||||
|
||||
class _UE:
|
||||
def __init__(self):
|
||||
self.bilan = None
|
||||
|
||||
|
||||
class _Niveau:
|
||||
def __init__(self, etudiant, niveauDesc, semestres):
|
||||
self.bilan = None
|
||||
self.etudiant = etudiant
|
||||
self.candidates = niveauDesc.get_ues(etudiant)
|
||||
self.ues = collections.defaultdict(list)
|
||||
|
||||
def add_ue_status(self, semestre_idx, status):
|
||||
self.ues[semestre_idx].append(status)
|
||||
|
||||
|
||||
class _Annee:
|
||||
def __init__(self, etudiant, annee_desc):
|
||||
self.etudiant = etudiant
|
||||
self.anneeDesc = annee_desc
|
||||
self.bilan: _Bilan = None
|
||||
self.niveaux = {}
|
||||
|
||||
|
||||
class _Competence:
|
||||
def __init__(self, etudiant, competenceDesc, semestres):
|
||||
self.descr = competenceDesc
|
||||
self.etudiant = etudiant
|
||||
self.niveaux = {}
|
||||
for niveau_id, niveauDesc in competenceDesc.niveaux.items():
|
||||
self.niveaux[niveau_id] = _Niveau(etudiant, niveauDesc, semestres)
|
||||
|
||||
def getNiveau(self, niveau_id):
|
||||
return self.niveaux[niveau_id]
|
||||
|
||||
|
||||
class _Semestre:
|
||||
def __init__(self, formsemestre_id, formsemestre=None):
|
||||
if formsemestre is None:
|
||||
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
||||
self.formsemestre = formsemestre
|
||||
self.resultatsSemestreBUT: ResultatsSemestreBUT = (
|
||||
res_sem.load_formsemestre_results(formsemestre)
|
||||
)
|
||||
# self.etuds_ues = (
|
||||
# self.resultatsSemestreBUT.load_ues_inscr_parcours()
|
||||
# )
|
||||
|
||||
|
||||
class _Etudiant:
|
||||
def __init__(self, ident, formation):
|
||||
self.ident = ident
|
||||
self.cursus: EtudCursusBUT = EtudCursusBUT(ident, formation)
|
||||
self.formsemestres = []
|
||||
self.parcour = self.cursus.inscriptions[-1].parcour
|
||||
self.history = []
|
||||
self.competences = {}
|
||||
self.annees = []
|
||||
for inscription in self.cursus.inscriptions:
|
||||
formsemestre = inscription.formsemestre
|
||||
self.formsemestres.append(inscription.formsemestre.id)
|
||||
Sx = f"S{formsemestre.semestre_id}"
|
||||
etat = inscription.etat
|
||||
if etat != "I":
|
||||
Sx += "(Dem)" if etat == "D" else f"({etat})"
|
||||
self.history.append(Sx)
|
||||
|
||||
def fill_in(self, parcourDescr, semestres):
|
||||
self.annees = {
|
||||
codeAnnee: _Annee(self, anneeDesc)
|
||||
for codeAnnee, anneeDesc in parcourDescr.annees.items()
|
||||
}
|
||||
for (competence_id, competenceDesc) in parcourDescr.competences.items():
|
||||
self.competences[competence_id] = _Competence(
|
||||
self, competenceDesc, semestres
|
||||
)
|
||||
for formsemestre_id in self.formsemestres:
|
||||
semestre: _Semestre = semestres[formsemestre_id]
|
||||
ues = semestre.resultatsSemestreBUT.etud_ues(self.ident.etudid)
|
||||
for ue in ues:
|
||||
niveau_id = ue.niveau_competence_id
|
||||
competence_id = ue.niveau_competence.competence_id
|
||||
semestre_idx = ue.semestre_idx
|
||||
niveau = self.competences[competence_id].getNiveau(niveau_id)
|
||||
status = semestre.resultatsSemestreBUT.get_etud_ue_status(
|
||||
self.ident.etudid, ue.id
|
||||
)
|
||||
niveau.add_ue_status(semestre_idx, status)
|
||||
|
||||
def getData(self):
|
||||
result = [
|
||||
self.ident.id,
|
||||
self.ident.code_nip,
|
||||
self.ident.civilite,
|
||||
self.ident.nom,
|
||||
self.ident.prenom,
|
||||
self.ident.etat_civil_pv(with_paragraph=False),
|
||||
self.parcour.code,
|
||||
", ".join(self.history),
|
||||
]
|
||||
return result
|
||||
|
||||
|
||||
class _Compilation:
|
||||
def __init__(self, formsemestre: FormSemestre):
|
||||
self.semestres = {}
|
||||
self.parcours = {}
|
||||
formsemestre_id = formsemestre.formsemestre_id
|
||||
self.semestre: _Semestre = _Semestre(formsemestre_id, formsemestre)
|
||||
self.formation: Formation = formsemestre.formation
|
||||
self.add_semestre(formsemestre_id, self.semestre)
|
||||
for ident in self.semestre.resultatsSemestreBUT.get_inscrits(order_by="moy"):
|
||||
etudiant: _Etudiant = _Etudiant(ident, self.formation)
|
||||
for inscription in etudiant.cursus.inscriptions:
|
||||
formsemestre = inscription.formsemestre
|
||||
if (
|
||||
formsemestre.formation.referentiel_competence
|
||||
== self.formation.referentiel_competence
|
||||
):
|
||||
self.add_semestre(formsemestre.id)
|
||||
scodocParcour = etudiant.parcour
|
||||
if scodocParcour is None:
|
||||
parcourCode = "TC"
|
||||
else:
|
||||
parcourCode = scodocParcour.code
|
||||
if parcourCode in self.parcours:
|
||||
parcoursDesc = self.parcours[parcourCode]
|
||||
else:
|
||||
parcoursDesc = ParcoursDesc(self.formation, scodocParcour)
|
||||
self.parcours[parcourCode] = parcoursDesc
|
||||
parcoursDesc.add_etudiant(etudiant)
|
||||
# etudiant.fill_in(parcoursDesc, self.semestres)
|
||||
pass
|
||||
|
||||
def add_semestre(self, formsemestre_id, semestre: _Semestre = None):
|
||||
if not formsemestre_id in self.semestres:
|
||||
if semestre is None:
|
||||
semestre = _Semestre(formsemestre_id)
|
||||
self.semestres[formsemestre_id] = _Semestre(formsemestre_id)
|
||||
|
||||
def add_parcours(self, scodocParcour: ApcParcours, etudiant: _Etudiant):
|
||||
parcour_code = scodocParcour.get("code", "TC")
|
||||
if not parcour_code in self.parcours:
|
||||
self.parcours[parcour_code] = ParcoursDesc(self.formation, scodocParcour)
|
||||
self.parcours[parcour_code].add(etudiant)
|
||||
|
||||
def computes_decision(self):
|
||||
pass
|
||||
|
||||
def make_excel(self, filename: str):
|
||||
workbook = ScoExcelBook()
|
||||
for parcoursCode, parcours in self.parcours.items():
|
||||
parcours.generate(workbook)
|
||||
|
||||
mime, suffix = scu.get_mime_suffix("xlsx")
|
||||
xls = workbook.generate()
|
||||
return scu.send_file(xls, filename=filename, mime=mime, suffix=suffix)
|
||||
|
||||
|
||||
def feuille_preparation_jury_but(formsemestre_id):
|
||||
if not isinstance(formsemestre_id, int):
|
||||
abort(404)
|
||||
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
||||
# res: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
||||
breakpoint()
|
||||
"""Feuille excel pour préparation des jurys adaptée pour le BUT."""
|
||||
compilation = _Compilation(formsemestre)
|
||||
compilation.computes_decision()
|
||||
filename = scu.sanitize_filename(
|
||||
f"""{'jury'}-{formsemestre.titre_num()}-{time.strftime("%Y-%m-%d")}"""
|
||||
)
|
||||
return compilation.make_excel(filename)
|
26
app/but/prepajury_cells.py
Normal file
26
app/but/prepajury_cells.py
Normal file
@ -0,0 +1,26 @@
|
||||
from enum import Enum
|
||||
from app.but.prepajury_xl import ScoExcelSheet, excel_make_style
|
||||
|
||||
base_style = excel_make_style()
|
||||
|
||||
class BG(Enum):
|
||||
|
||||
NONE = 0,
|
||||
BLACK = 1,
|
||||
GREY = 2,
|
||||
BUT1
|
||||
|
||||
class Cell:
|
||||
def __init__(self, text: str = None, style: int = None, comment: str = None):
|
||||
self.text = text
|
||||
self.style = style or base_style
|
||||
self.comment = comment
|
||||
|
||||
@staticmethod
|
||||
def get_style():
|
||||
return base_style
|
||||
|
||||
def make_cell(self, worksheet: ScoExcelSheet):
|
||||
style = self.get_style()
|
||||
cell = worksheet.make_cell(self.text or "", style=style)
|
||||
return cell
|
241
app/but/prepajury_desc.py
Normal file
241
app/but/prepajury_desc.py
Normal file
@ -0,0 +1,241 @@
|
||||
from app.but.prepajury_cells import Cell, base_style
|
||||
from app.but.prepajury_xl import excel_make_style
|
||||
from app.models import ApcCompetence, ApcParcours
|
||||
from app.scodoc.sco_excel import ScoExcelBook, ScoExcelSheet
|
||||
|
||||
|
||||
def parite(semestre_idx):
|
||||
return (semestre_idx + 1) % 2
|
||||
|
||||
|
||||
listeAnnees = ["BUT1", "BUT2", "BUT3"]
|
||||
|
||||
|
||||
class _Header:
|
||||
def __init__(self):
|
||||
self.lines: list[list[Cell]] = []
|
||||
self.presets = [None, None, None, None]
|
||||
self.styles = [None, None, None, None]
|
||||
|
||||
def setLabelOnce(self, rang: int, label: str):
|
||||
self.presets[rang] = label
|
||||
|
||||
def setStyles(self, rangs: list[int], style):
|
||||
for rang in rangs:
|
||||
self.styles[rang] = style
|
||||
|
||||
def add_column(
|
||||
self,
|
||||
label0=None,
|
||||
label1=None,
|
||||
label2=None,
|
||||
label3=None,
|
||||
labels: list[str] = None,
|
||||
):
|
||||
if labels is None:
|
||||
labels = [label0, label1, label2, label3]
|
||||
cells: list(Cell) = [
|
||||
Cell(preset or label, style=style)
|
||||
for label, preset, style in zip(labels, self.presets, self.styles)
|
||||
]
|
||||
self.presets = [None, None, None, None]
|
||||
self.lines.append(cells)
|
||||
|
||||
def extend(self, header):
|
||||
self.lines.extend(header.lines)
|
||||
|
||||
def write(self, worksheet: ScoExcelSheet):
|
||||
row1 = []
|
||||
row2 = []
|
||||
row3 = []
|
||||
row4 = []
|
||||
for items in self.lines:
|
||||
row1.append(items[0].make_cell(worksheet))
|
||||
row2.append(items[1].make_cell(worksheet))
|
||||
row3.append(items[2].make_cell(worksheet))
|
||||
row4.append(items[3].make_cell(worksheet))
|
||||
worksheet.append_row(row1)
|
||||
worksheet.append_row(row2)
|
||||
worksheet.append_row(row3)
|
||||
worksheet.append_row(row4)
|
||||
|
||||
|
||||
class NiveauDesc:
|
||||
def __init__(self, scodocNiveau):
|
||||
self.fromScodoc = scodocNiveau
|
||||
self.ues = {}
|
||||
self.ue = [None, None]
|
||||
for scodocUe in scodocNiveau.ues:
|
||||
self.ues[(scodocUe.formation_id, scodocUe.semestre_idx)] = scodocUe
|
||||
if not scodocUe.is_external:
|
||||
self.ue[parite(scodocUe.semestre_idx)] = scodocUe
|
||||
|
||||
def generate_header(self, header):
|
||||
header.setLabelOnce(1, self.fromScodoc.competence.titre)
|
||||
rcue_style = excel_make_style(base_style)
|
||||
ue_style = excel_make_style(base_style)
|
||||
header.setStyles([1, 2, 3], rcue_style)
|
||||
header.setStyles([2, 3], ue_style)
|
||||
for ue in self.ue:
|
||||
if ue is None:
|
||||
header.setLabelOnce(2, "XXX")
|
||||
header.add_column(label3="Note")
|
||||
header.add_column(label3="Res.")
|
||||
else:
|
||||
header.setLabelOnce(2, ue.acronyme)
|
||||
header.add_column(label3="Note")
|
||||
header.add_column(label3="Res.")
|
||||
header.setStyles([1, 2, 3], rcue_style)
|
||||
header.add_column(label2="RCUE", label3="Note")
|
||||
header.add_column(label3="Res.")
|
||||
return header
|
||||
|
||||
def get_ues(self, etudiant):
|
||||
"""get list of candidates UEs for Niveau"""
|
||||
ues = [None, None]
|
||||
for inscription in etudiant.cursus.inscriptions:
|
||||
formation_id = inscription.formsemestre.formation_id
|
||||
semestre_idx = inscription.formsemestre.semestre_id
|
||||
if (formation_id, semestre_idx) in self.ues:
|
||||
# identifier les ues cocernées
|
||||
ues[semestre_idx % 2] = inscription.formsemestre
|
||||
return ues
|
||||
|
||||
|
||||
class CompetenceDesc:
|
||||
def __init__(self, scodocCompetence):
|
||||
self.fromScodoc: ApcCompetence = scodocCompetence
|
||||
self.niveaux = {}
|
||||
for scodocNiveau in scodocCompetence.niveaux.all():
|
||||
self.niveaux[scodocNiveau.id] = NiveauDesc(scodocNiveau)
|
||||
|
||||
def getNiveauDesc(self, niveau_id):
|
||||
return self.niveaux[niveau_id]
|
||||
|
||||
def getNiveaux(self, codeAnnee):
|
||||
niveaux = []
|
||||
for niveau_id, niveauDesc in self.niveaux.items():
|
||||
if codeAnnee == niveauDesc.fromScodoc.annee:
|
||||
niveaux.append(niveauDesc)
|
||||
return niveaux
|
||||
|
||||
|
||||
class AnneeDesc:
|
||||
def __init__(self, codeAnnee):
|
||||
self.codeAnnee = codeAnnee
|
||||
self.niveaux = {}
|
||||
|
||||
def addNiveau(self, niveaux):
|
||||
for niveau in niveaux:
|
||||
self.niveaux[niveau.fromScodoc.id] = niveau
|
||||
|
||||
def generate_blank_niveau(self, header):
|
||||
header.setlabel(1, "-")
|
||||
for _ in range(3):
|
||||
header.add_column()
|
||||
|
||||
def generate_header(self, header):
|
||||
but_style = excel_make_style(base_style)
|
||||
header.setStyles([0], but_style)
|
||||
for niveau in self.niveaux.values():
|
||||
niveau.generate_header(header)
|
||||
for i in range(len(self.niveaux), 6):
|
||||
self.generate_blank_niveau(header)
|
||||
header.add_column(label1="Année", label2="Nb", label3="RCUE")
|
||||
header.add_column(label3="Rés.")
|
||||
if self.codeAnnee == "BUT2":
|
||||
header.add_column(label1="DUT", label3="Rés.")
|
||||
if self.codeAnnee == "BUT3":
|
||||
header.add_column(label1="BUT", label3="Rés.")
|
||||
|
||||
|
||||
class ParcoursDesc:
|
||||
def __init__(self, formation, scodocParcour: ApcParcours = None):
|
||||
self.fromScodoc: ApcParcours = scodocParcour # None pour le tronc commun 'TC'
|
||||
self.etudiants = []
|
||||
self.competences = {}
|
||||
self.annees = {}
|
||||
if scodocParcour is None:
|
||||
for (
|
||||
scodocCompetence
|
||||
) in formation.referentiel_competence.get_competences_tronc_commun():
|
||||
self.competences[scodocCompetence.id] = CompetenceDesc(scodocCompetence)
|
||||
else:
|
||||
query = formation.query_competences_parcour(scodocParcour)
|
||||
if not query is None:
|
||||
for scodocCompetence in query.all():
|
||||
self.competences[scodocCompetence.id] = CompetenceDesc(
|
||||
scodocCompetence
|
||||
)
|
||||
for codeAnnee in listeAnnees:
|
||||
anneeDesc = AnneeDesc(codeAnnee)
|
||||
for competence_id, competence in self.competences.items():
|
||||
anneeDesc.addNiveau(competence.getNiveaux(codeAnnee))
|
||||
self.annees[codeAnnee] = anneeDesc
|
||||
|
||||
def add_etudiant(self, etudiant):
|
||||
if not etudiant in self.etudiants:
|
||||
self.etudiants.append(etudiant)
|
||||
|
||||
def getNiveauDesc(self, competence_id, niveau_id):
|
||||
return self.competences[competence_id].getNiveauDesc(niveau_id)
|
||||
|
||||
def getData(self):
|
||||
data = []
|
||||
for etudiant in self.etudiants:
|
||||
data.append(etudiant.getData())
|
||||
return data
|
||||
|
||||
def append_title_column(self, worksheet, cells, val1, val2, val3, val4):
|
||||
cells1, cells2, cells3, cells4 = cells
|
||||
cells1.append(worksheet.make_cell(val1))
|
||||
cells2.append(worksheet.make_cell(val2))
|
||||
cells3.append(worksheet.make_cell(val3))
|
||||
cells4.append(worksheet.make_cell(val4))
|
||||
|
||||
def handle_description(self, header, description, level):
|
||||
title, content_list = description
|
||||
header.setLabelOnce(level, title)
|
||||
if content_list is None:
|
||||
header.add_column()
|
||||
else:
|
||||
for content in content_list:
|
||||
self.handle_description(header, content, level + 1)
|
||||
|
||||
def generate_etudiant_header(self, header):
|
||||
titles = (
|
||||
"ETUDIANT",
|
||||
[
|
||||
("id", None),
|
||||
("nip", None),
|
||||
("Civ", None),
|
||||
("nom", None),
|
||||
("prenom", None),
|
||||
("parcours", None),
|
||||
("cursus", None),
|
||||
(
|
||||
"absences",
|
||||
[
|
||||
("Tot.", None),
|
||||
("Non", [("Just.", None)]),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
self.handle_description(header, titles, 0)
|
||||
|
||||
def generate_header(self, header) -> _Header:
|
||||
self.generate_etudiant_header(header)
|
||||
for codeAnnee in listeAnnees:
|
||||
header.setLabelOnce(0, codeAnnee)
|
||||
self.annees[codeAnnee].generate_header(header)
|
||||
return header
|
||||
|
||||
def generate(self, workbook: ScoExcelBook):
|
||||
header = _Header()
|
||||
if self.fromScodoc:
|
||||
sheet_name = self.fromScodoc.code
|
||||
else:
|
||||
sheet_name = "TC"
|
||||
worksheet: ScoExcelSheet = workbook.create_sheet(sheet_name)
|
||||
self.generate_header(header).write(worksheet)
|
393
app/but/prepajury_xl.py
Normal file
393
app/but/prepajury_xl.py
Normal file
@ -0,0 +1,393 @@
|
||||
# -*- mode: python -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gestion scolarite IUT
|
||||
#
|
||||
# Copyright (c) 1999 - 2023 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
|
||||
"""
|
||||
import datetime
|
||||
import io
|
||||
import time
|
||||
from enum import Enum
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
import openpyxl.utils.datetime
|
||||
from openpyxl.styles.numbers import FORMAT_NUMBER_00, FORMAT_GENERAL, FORMAT_DATE_DDMMYY
|
||||
from openpyxl.comments import Comment
|
||||
from openpyxl import Workbook, load_workbook
|
||||
from openpyxl.cell import WriteOnlyCell
|
||||
from openpyxl.styles import Font, Border, Side, Alignment, PatternFill
|
||||
from openpyxl.worksheet.worksheet import Worksheet
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
from app import log
|
||||
from app.scodoc.sco_exceptions import ScoValueError
|
||||
from app.scodoc import notesdb, sco_preferences
|
||||
|
||||
|
||||
class COLORS(Enum):
|
||||
BLACK = "FF000000"
|
||||
WHITE = "FFFFFFFF"
|
||||
RED = "FFFF0000"
|
||||
BROWN = "FF993300"
|
||||
PURPLE = "FF993366"
|
||||
BLUE = "FF0000FF"
|
||||
ORANGE = "FFFF3300"
|
||||
LIGHT_YELLOW = "FFFFFF99"
|
||||
|
||||
|
||||
# Un style est enregistré comme un dictionnaire qui précise la valeur d'un attribut dans la liste suivante:
|
||||
# font, border, number_format, fill,...
|
||||
# (cf https://openpyxl.readthedocs.io/en/stable/styles.html#working-with-styles)
|
||||
|
||||
|
||||
def xldate_as_datetime(xldate, datemode=0):
|
||||
"""Conversion d'une date Excel en datetime python
|
||||
Deux formats de chaîne acceptés:
|
||||
* JJ/MM/YYYY (chaîne naïve)
|
||||
* Date ISO (valeur de type date lue dans la feuille)
|
||||
Peut lever une ValueError
|
||||
"""
|
||||
try:
|
||||
return datetime.datetime.strptime(xldate, "%d/%m/%Y")
|
||||
except:
|
||||
return openpyxl.utils.datetime.from_ISO8601(xldate)
|
||||
|
||||
|
||||
def adjust_sheetname(sheet_name):
|
||||
"""Renvoie un nom convenable pour une feuille excel: < 31 cars, sans caractères spéciaux
|
||||
Le / n'est pas autorisé par exemple.
|
||||
Voir https://xlsxwriter.readthedocs.io/workbook.html#add_worksheet
|
||||
"""
|
||||
sheet_name = scu.make_filename(sheet_name)
|
||||
# Le nom de la feuille ne peut faire plus de 31 caractères.
|
||||
# si la taille du nom de feuille est > 31 on tronque (on pourrait remplacer par 'feuille' ?)
|
||||
return sheet_name[:31]
|
||||
|
||||
|
||||
class ScoExcelBook:
|
||||
"""Permet la génération d'un classeur xlsx composé de plusieurs feuilles.
|
||||
usage:
|
||||
wb = ScoExcelBook()
|
||||
ws0 = wb.create_sheet('sheet name 0')
|
||||
ws1 = wb.create_sheet('sheet name 1')
|
||||
...
|
||||
steam = wb.generate()
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.sheets = [] # list of sheets
|
||||
self.wb = Workbook(write_only=True)
|
||||
|
||||
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_name = adjust_sheetname(sheet_name)
|
||||
ws = self.wb.create_sheet(sheet_name)
|
||||
sheet = ScoExcelSheet(sheet_name, default_style, ws)
|
||||
self.sheets.append(sheet)
|
||||
return sheet
|
||||
|
||||
def generate(self):
|
||||
"""génération d'un stream binaire représentant la totalité du classeur.
|
||||
retourne le flux
|
||||
"""
|
||||
for sheet in self.sheets:
|
||||
sheet.prepare()
|
||||
# construction d'un flux
|
||||
# (https://openpyxl.readthedocs.io/en/stable/tutorial.html#saving-as-a-stream)
|
||||
with NamedTemporaryFile() as tmp:
|
||||
self.wb.save(tmp.name)
|
||||
tmp.seek(0)
|
||||
return tmp.read()
|
||||
|
||||
|
||||
def excel_make_style(
|
||||
fromStyle=None,
|
||||
bold=False,
|
||||
italic=False,
|
||||
outline=False,
|
||||
color: COLORS = COLORS.BLACK,
|
||||
bgcolor: COLORS = None,
|
||||
halign=None,
|
||||
valign=None,
|
||||
number_format=None,
|
||||
font_name="Arial",
|
||||
size=10,
|
||||
):
|
||||
"""Contruit un style.
|
||||
Les couleurs peuvent être spécfiées soit par une valeur de COLORS,
|
||||
soit par une chaine argb (exple "FF00FF00" pour le vert)
|
||||
color -- La couleur du texte
|
||||
bgcolor -- la couleur de fond
|
||||
halign -- alignement horizontal ("left", "right", "center")
|
||||
valign -- alignement vertical ("top", "bottom", "center")
|
||||
number_format -- formattage du contenu ("General", "@", ...)
|
||||
font_name -- police
|
||||
size -- taille de police
|
||||
"""
|
||||
style = {}
|
||||
if fromStyle is not None:
|
||||
for item in fromStyle:
|
||||
style[item] = fromStyle[item]
|
||||
font = Font(
|
||||
name=font_name,
|
||||
bold=bold,
|
||||
italic=italic,
|
||||
outline=outline,
|
||||
color=color.value,
|
||||
size=size,
|
||||
)
|
||||
style["font"] = font
|
||||
if bgcolor:
|
||||
style["fill"] = PatternFill(fill_type="solid", fgColor=bgcolor.value)
|
||||
if halign or valign:
|
||||
al = Alignment()
|
||||
if halign:
|
||||
al.horizontal = {
|
||||
"left": "left",
|
||||
"right": "right",
|
||||
"center": "center",
|
||||
}[halign]
|
||||
if valign:
|
||||
al.vertical = {
|
||||
"top": "top",
|
||||
"bottom": "bottom",
|
||||
"center": "center",
|
||||
}[valign]
|
||||
style["alignment"] = al
|
||||
if number_format is None:
|
||||
style["number_format"] = FORMAT_GENERAL
|
||||
else:
|
||||
style["number_format"] = number_format
|
||||
return style
|
||||
|
||||
|
||||
class ScoExcelSheet:
|
||||
"""Représente une feuille qui peut être indépendante ou intégrée dans un ScoExcelBook.
|
||||
En application des directives de la bibliothèque sur l'écriture optimisée, l'ordre des opérations
|
||||
est imposé:
|
||||
* instructions globales (largeur/maquage des colonnes et ligne, ...)
|
||||
* construction et ajout des cellules et ligne selon le sens de lecture (occidental)
|
||||
ligne de haut en bas et cellules de gauche à droite (i.e. A1, A2, .. B1, B2, ..)
|
||||
* pour finir appel de la méthode de génération
|
||||
"""
|
||||
|
||||
def __init__(self, sheet_name="feuille", default_style=None, wb: Workbook = None):
|
||||
"""Création de la feuille. sheet_name
|
||||
-- le nom de la feuille default_style
|
||||
-- le style par défaut des cellules ws
|
||||
-- None si la feuille est autonome (dans ce cas elle crée son propre wb), sinon c'est la worksheet
|
||||
créée par le workbook propriétaire un workbook est créé et associé à cette feuille.
|
||||
"""
|
||||
# Le nom de la feuille ne peut faire plus de 31 caractères.
|
||||
# si la taille du nom de feuille est > 31 on tronque (on pourrait remplacer par 'feuille' ?)
|
||||
self.sheet_name = adjust_sheetname(sheet_name)
|
||||
if default_style is None:
|
||||
default_style = excel_make_style()
|
||||
self.default_style = default_style
|
||||
if wb is None:
|
||||
self.wb = Workbook()
|
||||
self.ws = self.wb.active
|
||||
self.ws.title = self.sheet_name
|
||||
else:
|
||||
self.wb = None
|
||||
self.ws = wb
|
||||
# internal data
|
||||
self.rows = [] # list of list of cells
|
||||
self.column_dimensions = {}
|
||||
self.row_dimensions = {}
|
||||
|
||||
def excel_make_composite_style(
|
||||
self,
|
||||
alignment=None,
|
||||
border=None,
|
||||
fill=None,
|
||||
number_format=None,
|
||||
font=None,
|
||||
):
|
||||
style = {}
|
||||
if font is not None:
|
||||
style["font"] = font
|
||||
if alignment is not None:
|
||||
style["alignment"] = alignment
|
||||
if border is not None:
|
||||
style["border"] = border
|
||||
if fill is not None:
|
||||
style["fill"] = fill
|
||||
if number_format is None:
|
||||
style["number_format"] = FORMAT_GENERAL
|
||||
else:
|
||||
style["number_format"] = number_format
|
||||
return style
|
||||
|
||||
@staticmethod
|
||||
def i2col(idx):
|
||||
if idx < 26: # one letter key
|
||||
return chr(idx + 65)
|
||||
else: # two letters AA..ZZ
|
||||
first = (idx // 26) + 66
|
||||
second = (idx % 26) + 65
|
||||
return "" + chr(first) + chr(second)
|
||||
|
||||
def set_column_dimension_width(self, cle=None, value=21):
|
||||
"""Détermine la largeur d'une colonne. cle -- identifie la colonne ("A" "B", ... ou 0, 1, 2, ...) si None,
|
||||
value donne la liste des largeurs de colonnes depuis A, B, C, ... value -- la dimension (unité : 7 pixels
|
||||
comme affiché dans Excel)
|
||||
"""
|
||||
if cle is None:
|
||||
for i, val in enumerate(value):
|
||||
self.ws.column_dimensions[self.i2col(i)].width = val
|
||||
# No keys: value is a list of widths
|
||||
elif isinstance(cle, str): # accepts set_column_with("D", ...)
|
||||
self.ws.column_dimensions[cle].width = value
|
||||
else:
|
||||
self.ws.column_dimensions[self.i2col(cle)].width = value
|
||||
|
||||
def set_row_dimension_height(self, cle=None, value=21):
|
||||
"""Détermine la hauteur d'une ligne. cle -- identifie la ligne (1, 2, ...) si None,
|
||||
value donne la liste des hauteurs de colonnes depuis 1, 2, 3, ... value -- la dimension
|
||||
"""
|
||||
if cle is None:
|
||||
for i, val in enumerate(value, start=1):
|
||||
self.ws.row_dimensions[i].height = val
|
||||
# No keys: value is a list of widths
|
||||
else:
|
||||
self.ws.row_dimensions[cle].height = value
|
||||
|
||||
def set_row_dimension_hidden(self, cle, value):
|
||||
"""Masque ou affiche une ligne.
|
||||
cle -- identifie la colonne (1...)
|
||||
value -- boolean (vrai = colonne cachée)
|
||||
"""
|
||||
self.ws.row_dimensions[cle].hidden = value
|
||||
|
||||
def make_cell(self, value: any = None, style=None, comment=None):
|
||||
"""Construit une cellule.
|
||||
value -- contenu de la cellule (texte, numérique, booléen ou date)
|
||||
style -- style par défaut (dictionnaire cf. excel_make_style) de la feuille si non spécifié
|
||||
"""
|
||||
# adaptation des valeurs si nécessaire
|
||||
if value is None:
|
||||
value = ""
|
||||
elif value is True:
|
||||
value = 1
|
||||
elif value is False:
|
||||
value = 0
|
||||
elif isinstance(value, datetime.datetime):
|
||||
value = value.replace(
|
||||
tzinfo=None
|
||||
) # make date naive (cf https://openpyxl.readthedocs.io/en/latest/datetime.html#timezones)
|
||||
|
||||
# création de la cellule
|
||||
cell = WriteOnlyCell(self.ws, value)
|
||||
|
||||
# recopie des styles
|
||||
if style is None:
|
||||
style = self.default_style
|
||||
if "font" in style:
|
||||
cell.font = style["font"]
|
||||
if "alignment" in style:
|
||||
cell.alignment = style["alignment"]
|
||||
if "border" in style:
|
||||
cell.border = style["border"]
|
||||
if "fill" in style:
|
||||
cell.fill = style["fill"]
|
||||
if "number_format" in style:
|
||||
cell.number_format = style["number_format"]
|
||||
if "fill" in style:
|
||||
cell.fill = style["fill"]
|
||||
if "alignment" in style:
|
||||
cell.alignment = style["alignment"]
|
||||
if not comment is None:
|
||||
cell.comment = Comment(comment, "scodoc")
|
||||
lines = comment.splitlines()
|
||||
cell.comment.width = 7 * max([len(line) for line in lines]) if lines else 7
|
||||
cell.comment.height = 20 * len(lines) if lines else 20
|
||||
|
||||
# test datatype to overwrite datetime format
|
||||
if isinstance(value, datetime.date):
|
||||
cell.data_type = "d"
|
||||
cell.number_format = FORMAT_DATE_DDMMYY
|
||||
elif isinstance(value, int) or isinstance(value, float):
|
||||
cell.data_type = "n"
|
||||
else:
|
||||
cell.data_type = "s"
|
||||
|
||||
return cell
|
||||
|
||||
def make_row(self, values: list, style=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)
|
||||
]
|
||||
|
||||
def append_single_cell_row(self, value: any, style=None):
|
||||
"""construit une ligne composée d'une seule cellule et l'ajoute à la feuille.
|
||||
mêmes paramètres que make_cell:
|
||||
value -- contenu de la cellule (texte ou numérique)
|
||||
style -- style par défaut de la feuille si non spécifié
|
||||
"""
|
||||
self.append_row([self.make_cell(value, style)])
|
||||
|
||||
def append_blank_row(self):
|
||||
"""construit une ligne vide et l'ajoute à la feuille."""
|
||||
self.append_row([None])
|
||||
|
||||
def append_row(self, row):
|
||||
"""ajoute une ligne déjà construite à la feuille."""
|
||||
self.rows.append(row)
|
||||
|
||||
def prepare(self):
|
||||
"""génére un flux décrivant la feuille.
|
||||
Ce flux pourra ensuite être repris dans send_excel_file (classeur mono feille)
|
||||
ou pour la génération d'un classeur multi-feuilles
|
||||
"""
|
||||
for row in self.column_dimensions.keys():
|
||||
self.ws.column_dimensions[row] = self.column_dimensions[row]
|
||||
for row in self.row_dimensions.keys():
|
||||
self.ws.row_dimensions[row] = self.row_dimensions[row]
|
||||
for row in self.rows:
|
||||
self.ws.append(row)
|
||||
|
||||
def generate(self):
|
||||
"""génération d'un classeur mono-feuille"""
|
||||
# this method makes sense only if it is a standalone worksheet (else call workbook.generate()
|
||||
if self.wb is None: # embeded sheet
|
||||
raise ScoValueError("can't generate a single sheet from a ScoWorkbook")
|
||||
|
||||
# construction d'un flux (https://openpyxl.readthedocs.io/en/stable/tutorial.html#saving-as-a-stream)
|
||||
self.prepare()
|
||||
with NamedTemporaryFile() as tmp:
|
||||
self.wb.save(tmp.name)
|
||||
tmp.seek(0)
|
||||
return tmp.read()
|
@ -1,463 +0,0 @@
|
||||
# -*- mode: python -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gestion scolarite IUT
|
||||
#
|
||||
# Copyright (c) 1999 - 2023 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
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
"""Feuille excel pour préparation des jurys classiques (non BUT)
|
||||
"""
|
||||
import collections
|
||||
import time
|
||||
|
||||
from openpyxl.cell import Cell
|
||||
from openpyxl.styles.numbers import FORMAT_NUMBER_00
|
||||
|
||||
from flask import flash, abort
|
||||
from flask import request
|
||||
from flask_login import current_user
|
||||
|
||||
from app.but.cursus_but import EtudCursusBUT
|
||||
from app.comp import res_sem
|
||||
from app.comp.res_but import ResultatsSemestreBUT
|
||||
from app.comp.res_common import ResultatsSemestre
|
||||
from app.comp.res_compat import NotesTableCompat
|
||||
from app.models import (
|
||||
FormSemestre,
|
||||
Identite,
|
||||
ScolarAutorisationInscription,
|
||||
ApcParcours,
|
||||
Formation,
|
||||
ApcCompetence,
|
||||
)
|
||||
from app.scodoc import sco_abs
|
||||
from app.scodoc import codes_cursus
|
||||
from app.scodoc import sco_groups
|
||||
from app.scodoc import sco_etud
|
||||
from app.scodoc import sco_excel
|
||||
from app.scodoc import sco_formsemestre
|
||||
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 ScoExcelBook, ScoExcelSheet
|
||||
|
||||
listeAnnees = ["BUT1", "BUT2", "BUT3"]
|
||||
|
||||
|
||||
class _Cell:
|
||||
def __init__(self, text=None, format=None, comment=None):
|
||||
self.text = text
|
||||
self.format = format
|
||||
self.comment = comment
|
||||
|
||||
def make_cell(self, worksheet: ScoExcelSheet):
|
||||
cell = worksheet.make_cell(self.text or "")
|
||||
return cell
|
||||
|
||||
|
||||
class _Header:
|
||||
def __init__(self):
|
||||
self.lines = []
|
||||
self.labels = [None, None, None, None]
|
||||
|
||||
@staticmethod
|
||||
def _process_item(item):
|
||||
if item is None:
|
||||
return _Cell("")
|
||||
if isinstance(item, _Cell):
|
||||
return item
|
||||
else:
|
||||
return _Cell(item)
|
||||
|
||||
def setLabel(self, rang, label):
|
||||
self.labels[rang] = self._process_item(label)
|
||||
|
||||
def add_column(self, item0=None, item1=None, item2=None, item3=None):
|
||||
items = list(map(lambda x: self._process_item(x), [item0, item1, item2, item3]))
|
||||
for rang, label in enumerate(self.labels):
|
||||
if not label is None:
|
||||
items[rang] = label
|
||||
self.labels[rang] = None
|
||||
self.lines.append(items)
|
||||
|
||||
def extend(self, header):
|
||||
self.lines.extend(header.lines)
|
||||
|
||||
def write(self, worksheet: ScoExcelSheet):
|
||||
row1 = []
|
||||
row2 = []
|
||||
row3 = []
|
||||
row4 = []
|
||||
for items in self.lines:
|
||||
row1.append(items[0].make_cell(worksheet))
|
||||
row2.append(items[1].make_cell(worksheet))
|
||||
row3.append(items[2].make_cell(worksheet))
|
||||
row4.append(items[3].make_cell(worksheet))
|
||||
worksheet.append_row(row1)
|
||||
worksheet.append_row(row2)
|
||||
worksheet.append_row(row3)
|
||||
worksheet.append_row(row4)
|
||||
|
||||
|
||||
class _Bilan:
|
||||
def __init__(self):
|
||||
self.note = 0
|
||||
self.resultat = 0
|
||||
self.format = 0
|
||||
|
||||
|
||||
class _UE:
|
||||
def __init__(self):
|
||||
self.bilan = None
|
||||
|
||||
|
||||
class _Niveau:
|
||||
def __init__(self, etudiant, niveauDesc, semestres):
|
||||
self.bilan = None
|
||||
self.etudiant = etudiant
|
||||
self.candidates = niveauDesc.get_ues(etudiant)
|
||||
self.ues = collections.defaultdict(list)
|
||||
|
||||
def add_ue_status(self, semestre_idx, status):
|
||||
self.ues[semestre_idx].append(status)
|
||||
|
||||
|
||||
class _Annee:
|
||||
def __init__(self, etudiant, annee_desc):
|
||||
self.etudiant = etudiant
|
||||
self.anneeDesc = annee_desc
|
||||
self.bilan: _Bilan = None
|
||||
self.niveaux = {}
|
||||
|
||||
|
||||
class _Competence:
|
||||
def __init__(self, etudiant, competenceDesc, semestres):
|
||||
self.descr = competenceDesc
|
||||
self.etudiant = etudiant
|
||||
self.niveaux = {}
|
||||
for niveau_id, niveauDesc in competenceDesc.niveaux.items():
|
||||
self.niveaux[niveau_id] = _Niveau(etudiant, niveauDesc, semestres)
|
||||
|
||||
def getNiveau(self, niveau_id):
|
||||
return self.niveaux[niveau_id]
|
||||
|
||||
|
||||
class _Semestre:
|
||||
def __init__(self, formsemestre_id, formsemestre=None):
|
||||
if formsemestre is None:
|
||||
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
||||
self.formsemestre = formsemestre
|
||||
self.resultatsSemestreBUT: ResultatsSemestreBUT = (
|
||||
res_sem.load_formsemestre_results(formsemestre)
|
||||
)
|
||||
# self.etuds_ues = (
|
||||
# self.resultatsSemestreBUT.load_ues_inscr_parcours()
|
||||
# )
|
||||
|
||||
|
||||
def parite(semestre_idx):
|
||||
return (semestre_idx + 1) % 2
|
||||
|
||||
|
||||
class _NiveauDesc:
|
||||
def __init__(self, scodocNiveau):
|
||||
self.fromScodoc = scodocNiveau
|
||||
self.ues = {}
|
||||
self.ue = [None, None]
|
||||
for scodocUe in scodocNiveau.ues:
|
||||
self.ues[(scodocUe.formation_id, scodocUe.semestre_idx)] = scodocUe
|
||||
if not scodocUe.is_external:
|
||||
self.ue[parite(scodocUe.semestre_idx)] = scodocUe
|
||||
|
||||
def generate_header(self, header):
|
||||
header.setLabel(1, self.fromScodoc.competence.titre)
|
||||
for ue in self.ue:
|
||||
if ue is None:
|
||||
header.setLabel(2, "XXX")
|
||||
header.add_column(item3="Note")
|
||||
header.add_column(item3="Res.")
|
||||
else:
|
||||
header.setLabel(2, ue.acronyme)
|
||||
header.add_column(item3="Note")
|
||||
header.add_column(item3="Res.")
|
||||
header.add_column(item2="RCUE", item3="Note")
|
||||
header.add_column(item3="Res.")
|
||||
return header
|
||||
|
||||
def get_ues(self, etudiant):
|
||||
"""get list of candidates UEs for Niveau"""
|
||||
ues = [None, None]
|
||||
for inscription in etudiant.cursus.inscriptions:
|
||||
formation_id = inscription.formsemestre.formation_id
|
||||
semestre_idx = inscription.formsemestre.semestre_id
|
||||
if (formation_id, semestre_idx) in self.ues:
|
||||
# identifier les ues cocernées
|
||||
ues[semestre_idx % 2] = inscription.formsemestre
|
||||
return ues
|
||||
|
||||
|
||||
class _CompetenceDesc:
|
||||
def __init__(self, scodocCompetence):
|
||||
self.fromScodoc: ApcCompetence = scodocCompetence
|
||||
self.niveaux = {}
|
||||
for scodocNiveau in scodocCompetence.niveaux.all():
|
||||
self.niveaux[scodocNiveau.id] = _NiveauDesc(scodocNiveau)
|
||||
|
||||
def getNiveauDesc(self, niveau_id):
|
||||
return self.niveaux[niveau_id]
|
||||
|
||||
def getNiveaux(self, codeAnnee):
|
||||
niveaux = []
|
||||
for niveau_id, niveauDesc in self.niveaux.items():
|
||||
if codeAnnee == niveauDesc.fromScodoc.annee:
|
||||
niveaux.append(niveauDesc)
|
||||
return niveaux
|
||||
|
||||
|
||||
class _AnneeDesc:
|
||||
def __init__(self, codeAnnee):
|
||||
self.codeAnnee = codeAnnee
|
||||
self.niveaux = {}
|
||||
|
||||
def addNiveau(self, niveaux):
|
||||
for niveau in niveaux:
|
||||
self.niveaux[niveau.fromScodoc.id] = niveau
|
||||
|
||||
def generate_blank_niveau(self, header):
|
||||
header.setlabel(1, "-")
|
||||
for _ in range(3):
|
||||
header.add_column()
|
||||
|
||||
def generate_header(self, header):
|
||||
for niveau in self.niveaux.values():
|
||||
niveau.generate_header(header)
|
||||
for i in range(len(self.niveaux), 6):
|
||||
self.generate_blank_niveau(header)
|
||||
header.add_column(item1="Année", item2="Nb", item3="RCUE")
|
||||
header.add_column(item2="Res.")
|
||||
if self.codeAnnee == "BUT2":
|
||||
header.add_column(item1="DUT", item3="Rés.")
|
||||
if self.codeAnnee == "BUT3":
|
||||
header.add_column(item1="BUT", item3="Rés.")
|
||||
|
||||
|
||||
class _ParcoursDesc:
|
||||
def __init__(self, formation, scodocParcour: ApcParcours = None):
|
||||
self.fromScodoc: ApcParcours = scodocParcour # None pour le tronc commun 'TC'
|
||||
self.etudiants = []
|
||||
self.competences = {}
|
||||
self.annees = {}
|
||||
if scodocParcour is None:
|
||||
for (
|
||||
scodocCompetence
|
||||
) in formation.referentiel_competence.get_competences_tronc_commun():
|
||||
self.competences[scodocCompetence.id] = _CompetenceDesc(
|
||||
scodocCompetence
|
||||
)
|
||||
else:
|
||||
query = formation.query_competences_parcour(scodocParcour)
|
||||
if not query is None:
|
||||
for scodocCompetence in query.all():
|
||||
self.competences[scodocCompetence.id] = _CompetenceDesc(
|
||||
scodocCompetence
|
||||
)
|
||||
for codeAnnee in listeAnnees:
|
||||
anneeDesc = _AnneeDesc(codeAnnee)
|
||||
for competence_id, competence in self.competences.items():
|
||||
anneeDesc.addNiveau(competence.getNiveaux(codeAnnee))
|
||||
self.annees[codeAnnee] = anneeDesc
|
||||
|
||||
def add_etudiant(self, etudiant):
|
||||
if not etudiant in self.etudiants:
|
||||
self.etudiants.append(etudiant)
|
||||
|
||||
def getNiveauDesc(self, competence_id, niveau_id):
|
||||
return self.competences[competence_id].getNiveauDesc(niveau_id)
|
||||
|
||||
def getData(self):
|
||||
data = []
|
||||
etudiant: _Etudiant
|
||||
for etudiant in self.etudiants:
|
||||
data.append(etudiant.getData())
|
||||
return data
|
||||
|
||||
def append_title_column(self, worksheet, cells, val1, val2, val3, val4):
|
||||
cells1, cells2, cells3, cells4 = cells
|
||||
cells1.append(worksheet.make_cell(val1))
|
||||
cells2.append(worksheet.make_cell(val2))
|
||||
cells3.append(worksheet.make_cell(val3))
|
||||
cells4.append(worksheet.make_cell(val4))
|
||||
|
||||
def generate_header(self, header):
|
||||
titles_strings = [
|
||||
"etudid",
|
||||
"nip",
|
||||
"Civ",
|
||||
"nom",
|
||||
"prenom",
|
||||
"parcours",
|
||||
"cursus",
|
||||
"absences",
|
||||
"abs. non just.",
|
||||
]
|
||||
for title in titles_strings:
|
||||
header.add_column(item0=title)
|
||||
for codeAnnee in listeAnnees:
|
||||
header.setLabel(0, codeAnnee)
|
||||
self.annees[codeAnnee].generate_header(header)
|
||||
return header
|
||||
|
||||
def generate(self, workbook: ScoExcelBook):
|
||||
if self.fromScodoc:
|
||||
sheet_name = self.fromScodoc.code
|
||||
else:
|
||||
sheet_name = "TC"
|
||||
worksheet: ScoExcelSheet = workbook.create_sheet(sheet_name)
|
||||
header: _Header = _Header()
|
||||
self.generate_header(header).write(worksheet)
|
||||
|
||||
|
||||
class _Etudiant:
|
||||
def __init__(self, ident, formation):
|
||||
self.ident = ident
|
||||
self.cursus: EtudCursusBUT = EtudCursusBUT(ident, formation)
|
||||
self.formsemestres = []
|
||||
self.parcour = self.cursus.inscriptions[-1].parcour
|
||||
self.history = []
|
||||
self.competences = {}
|
||||
self.annees = []
|
||||
for inscription in self.cursus.inscriptions:
|
||||
formsemestre = inscription.formsemestre
|
||||
self.formsemestres.append(inscription.formsemestre.id)
|
||||
Sx = f"S{formsemestre.semestre_id}"
|
||||
etat = inscription.etat
|
||||
if etat != "I":
|
||||
Sx += "(Dem)" if etat == "D" else f"({etat})"
|
||||
self.history.append(Sx)
|
||||
|
||||
def fill_in(self, parcourDescr, semestres):
|
||||
self.annees = {
|
||||
codeAnnee: _Annee(self, anneeDesc)
|
||||
for codeAnnee, anneeDesc in parcourDescr.annees.items()
|
||||
}
|
||||
for (competence_id, competenceDesc) in parcourDescr.competences.items():
|
||||
self.competences[competence_id] = _Competence(
|
||||
self, competenceDesc, semestres
|
||||
)
|
||||
for formsemestre_id in self.formsemestres:
|
||||
semestre: _Semestre = semestres[formsemestre_id]
|
||||
ues = semestre.resultatsSemestreBUT.etud_ues(self.ident.etudid)
|
||||
for ue in ues:
|
||||
niveau_id = ue.niveau_competence_id
|
||||
competence_id = ue.niveau_competence.competence_id
|
||||
semestre_idx = ue.semestre_idx
|
||||
niveau = self.competences[competence_id].getNiveau(niveau_id)
|
||||
status = semestre.resultatsSemestreBUT.get_etud_ue_status(
|
||||
self.ident.etudid, ue.id
|
||||
)
|
||||
niveau.add_ue_status(semestre_idx, status)
|
||||
|
||||
def getData(self):
|
||||
result = [
|
||||
self.ident.id,
|
||||
self.ident.code_nip,
|
||||
self.ident.civilite,
|
||||
self.ident.nom,
|
||||
self.ident.prenom,
|
||||
self.ident.etat_civil_pv(with_paragraph=False),
|
||||
self.parcour.code,
|
||||
", ".join(self.history),
|
||||
]
|
||||
return result
|
||||
|
||||
|
||||
class _Compilation:
|
||||
def __init__(self, formsemestre: FormSemestre):
|
||||
self.semestres = {}
|
||||
self.parcours = {}
|
||||
formsemestre_id = formsemestre.formsemestre_id
|
||||
self.semestre: _Semestre = _Semestre(formsemestre_id, formsemestre)
|
||||
self.formation: Formation = formsemestre.formation
|
||||
self.add_semestre(formsemestre_id, self.semestre)
|
||||
for ident in self.semestre.resultatsSemestreBUT.get_inscrits(order_by="moy"):
|
||||
etudiant: _Etudiant = _Etudiant(ident, self.formation)
|
||||
for inscription in etudiant.cursus.inscriptions:
|
||||
formsemestre = inscription.formsemestre
|
||||
if (
|
||||
formsemestre.formation.referentiel_competence
|
||||
== self.formation.referentiel_competence
|
||||
):
|
||||
self.add_semestre(formsemestre.id)
|
||||
scodocParcour = etudiant.parcour
|
||||
if scodocParcour is None:
|
||||
parcourCode = "TC"
|
||||
else:
|
||||
parcourCode = scodocParcour.code
|
||||
if parcourCode in self.parcours:
|
||||
parcoursDesc = self.parcours[parcourCode]
|
||||
else:
|
||||
parcoursDesc = _ParcoursDesc(self.formation, scodocParcour)
|
||||
self.parcours[parcourCode] = parcoursDesc
|
||||
parcoursDesc.add_etudiant(etudiant)
|
||||
etudiant.fill_in(parcoursDesc, self.semestres)
|
||||
pass
|
||||
|
||||
def add_semestre(self, formsemestre_id, semestre: _Semestre = None):
|
||||
if not formsemestre_id in self.semestres:
|
||||
if semestre is None:
|
||||
semestre = _Semestre(formsemestre_id)
|
||||
self.semestres[formsemestre_id] = _Semestre(formsemestre_id)
|
||||
|
||||
def add_parcours(self, scodocParcour: ApcParcours, etudiant: _Etudiant):
|
||||
parcour_code = scodocParcour.get("code", "TC")
|
||||
if not parcour_code in self.parcours:
|
||||
self.parcours[parcour_code] = _ParcoursDesc(self.formation, scodocParcour)
|
||||
self.parcours[parcour_code].add(etudiant)
|
||||
|
||||
def computes_decision(self):
|
||||
pass
|
||||
|
||||
def make_excel(self, filename: str):
|
||||
workbook = ScoExcelBook()
|
||||
for parcoursCode, parcours in self.parcours.items():
|
||||
parcours.generate(workbook)
|
||||
|
||||
mime, suffix = scu.get_mime_suffix("xlsx")
|
||||
xls = workbook.generate()
|
||||
return scu.send_file(xls, filename=filename, mime=mime, suffix=suffix)
|
||||
|
||||
|
||||
def feuille_preparation_jury_but(formsemestre_id):
|
||||
if not isinstance(formsemestre_id, int):
|
||||
abort(404)
|
||||
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
||||
# res: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
||||
breakpoint()
|
||||
"""Feuille excel pour préparation des jurys adaptée pour le BUT."""
|
||||
compilation = _Compilation(formsemestre)
|
||||
compilation.computes_decision()
|
||||
filename = scu.sanitize_filename(
|
||||
f"""{'jury'}-{formsemestre.titre_num()}-{time.strftime("%Y-%m-%d")}"""
|
||||
)
|
||||
return compilation.make_excel(filename)
|
@ -42,7 +42,7 @@ from flask_login import current_user
|
||||
from app import db
|
||||
from app import models
|
||||
from app.auth.models import User
|
||||
from app.but import apc_edit_ue, sco_prepajury_but
|
||||
from app.but import apc_edit_ue, prepajury_but
|
||||
from app.but import jury_but, jury_but_validation_auto
|
||||
from app.but.forms import jury_but_forms
|
||||
from app.but import jury_but_pv
|
||||
@ -2913,7 +2913,7 @@ sco_publish(
|
||||
)
|
||||
sco_publish(
|
||||
"/feuille_preparation_jury_but",
|
||||
sco_prepajury_but.feuille_preparation_jury_but,
|
||||
prepajury_but.feuille_preparation_jury_but,
|
||||
Permission.ScoView,
|
||||
)
|
||||
sco_publish(
|
||||
|
Loading…
x
Reference in New Issue
Block a user