headers sans formet

This commit is contained in:
Jean-Marie Place 2023-05-07 08:02:26 +02:00
parent ee1bb3cc27
commit 646173c9ac
2 changed files with 124 additions and 32 deletions

View File

@ -65,6 +65,61 @@ from app.scodoc.sco_excel import ScoExcelBook, ScoExcelSheet
listeAnnees = ["BUT1", "BUT2", "BUT3"] 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: class _Bilan:
def __init__(self): def __init__(self):
self.note = 0 self.note = 0
@ -89,9 +144,9 @@ class _Niveau:
class _Annee: class _Annee:
def __init__(self, etudiant, anneeDesc): def __init__(self, etudiant, annee_desc):
self.etudiant = etudiant self.etudiant = etudiant
self.anneeDesc = anneeDesc self.anneeDesc = annee_desc
self.bilan: _Bilan = None self.bilan: _Bilan = None
self.niveaux = {} self.niveaux = {}
@ -121,12 +176,34 @@ class _Semestre:
# ) # )
def parite(semestre_idx):
return (semestre_idx + 1) % 2
class _NiveauDesc: class _NiveauDesc:
def __init__(self, scodocNiveau): def __init__(self, scodocNiveau):
self.fromScodoc = scodocNiveau self.fromScodoc = scodocNiveau
self.ues = {} self.ues = {}
self.ue = [None, None]
for scodocUe in scodocNiveau.ues: for scodocUe in scodocNiveau.ues:
self.ues[(scodocUe.formation_id, scodocUe.semestre_idx)] = scodocUe 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): def get_ues(self, etudiant):
"""get list of candidates UEs for Niveau""" """get list of candidates UEs for Niveau"""
@ -167,6 +244,23 @@ class _AnneeDesc:
for niveau in niveaux: for niveau in niveaux:
self.niveaux[niveau.fromScodoc.id] = niveau 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: class _ParcoursDesc:
def __init__(self, formation, scodocParcour: ApcParcours = None): def __init__(self, formation, scodocParcour: ApcParcours = None):
@ -193,7 +287,6 @@ class _ParcoursDesc:
for competence_id, competence in self.competences.items(): for competence_id, competence in self.competences.items():
anneeDesc.addNiveau(competence.getNiveaux(codeAnnee)) anneeDesc.addNiveau(competence.getNiveaux(codeAnnee))
self.annees[codeAnnee] = anneeDesc self.annees[codeAnnee] = anneeDesc
breakpoint()
def add_etudiant(self, etudiant): def add_etudiant(self, etudiant):
if not etudiant in self.etudiants: if not etudiant in self.etudiants:
@ -209,39 +302,40 @@ class _ParcoursDesc:
data.append(etudiant.getData()) data.append(etudiant.getData())
return data return data
def generate_title(self, worksheet: ScoExcelSheet): def append_title_column(self, worksheet, cells, val1, val2, val3, val4):
worksheet.append_blank_row() cells1, cells2, cells3, cells4 = cells
cells1 = [ cells1.append(worksheet.make_cell(val1))
worksheet.make_cell(title) cells2.append(worksheet.make_cell(val2))
for title in [ cells3.append(worksheet.make_cell(val3))
"etudid", cells4.append(worksheet.make_cell(val4))
"nip",
"Civ",
"nom",
"prenom",
"parcours",
"cursus",
"absences",
"abs. non just.",
]
]
cells2 = [ len(title) * '' ]
cells3 = [ len(title) * '' ]
cells4 = [ len(title) * '' ]
worksheet.append_row(cells1)
worksheet.append_row(cells2)
worksheet.append_row(cells3)
worksheet.append_row(cells4)
for codeAnnee in listeAnnees:
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): def generate(self, workbook: ScoExcelBook):
if self.fromScodoc: if self.fromScodoc:
sheet_name = self.fromScodoc.code sheet_name = self.fromScodoc.code
else: else:
sheet_name = "TC" sheet_name = "TC"
worksheet = ScoExcelSheet = workbook.create_sheet(sheet_name) worksheet: ScoExcelSheet = workbook.create_sheet(sheet_name)
self.generate_title(worksheet) header: _Header = _Header()
self.generate_header(header).write(worksheet)
class _Etudiant: class _Etudiant:
@ -327,7 +421,6 @@ class _Compilation:
self.parcours[parcourCode] = parcoursDesc self.parcours[parcourCode] = parcoursDesc
parcoursDesc.add_etudiant(etudiant) parcoursDesc.add_etudiant(etudiant)
etudiant.fill_in(parcoursDesc, self.semestres) etudiant.fill_in(parcoursDesc, self.semestres)
breakpoint()
pass pass
def add_semestre(self, formsemestre_id, semestre: _Semestre = None): def add_semestre(self, formsemestre_id, semestre: _Semestre = None):

View File

@ -42,7 +42,7 @@ from flask_login import current_user
from app import db from app import db
from app import models from app import models
from app.auth.models import User from app.auth.models import User
from app.but import apc_edit_ue from app.but import apc_edit_ue, sco_prepajury_but
from app.but import jury_but, jury_but_validation_auto from app.but import jury_but, jury_but_validation_auto
from app.but.forms import jury_but_forms from app.but.forms import jury_but_forms
from app.but import jury_but_pv from app.but import jury_but_pv
@ -60,7 +60,6 @@ from app.models.moduleimpls import ModuleImpl
from app.models.modules import Module from app.models.modules import Module
from app.models.ues import DispenseUE, UniteEns from app.models.ues import DispenseUE, UniteEns
from app.scodoc.sco_exceptions import ScoFormationConflict, ScoPermissionDenied from app.scodoc.sco_exceptions import ScoFormationConflict, ScoPermissionDenied
from app.tables import jury_recap
from app.views import notes_bp as bp from app.views import notes_bp as bp
from app.decorators import ( from app.decorators import (
@ -73,7 +72,7 @@ from app.decorators import (
# --------------- # ---------------
from app.scodoc import sco_bulletins_json, sco_utils as scu, sco_prepajury_but from app.scodoc import sco_bulletins_json, sco_utils as scu
from app.scodoc import notesdb as ndb from app.scodoc import notesdb as ndb
from app import log, send_scodoc_alarm from app import log, send_scodoc_alarm