195 lines
6.7 KiB
Python
195 lines
6.7 KiB
Python
from datetime import date, timedelta
|
|
|
|
from colloscope.models import *
|
|
|
|
from fpdf import FPDF
|
|
from fpdf.fonts import FontFace
|
|
from fpdf.enums import TableCellFillMode
|
|
|
|
"""
|
|
etudiants = [
|
|
['Aboujaib', 'Alexandre', 4, 'A', '', ''],
|
|
['Ajan', 'George', 4, 'A', '', ''],
|
|
['Akrad', 'Lina', 1, 'SI', '', ''],
|
|
['Aubert', 'Nicolas', 1, 'SI', '', ''],
|
|
['Badr', 'Roman', 4, 'A', '', ''],
|
|
['Bazire', 'Aurélien', 5, 'A', '', ''],
|
|
['Boit', 'Arthur', 5, 'A', '', ''],
|
|
['Boubker', 'Youssef', 5, 'A', '', ''],
|
|
['Boudjema', 'Dylan', 1, 'SI', '', ''],
|
|
['Chiriac', 'Mihnea', 6, 'A', '', ''],
|
|
['Courier', 'Marine', 6, 'A', '', ''],
|
|
['Daguin', 'Joseph', 6, 'A', '', ''],
|
|
['Dauguen', 'Gabriel', 7, 'A', '', ''],
|
|
['De Weer', 'Matthias', 7, 'A', '', ''],
|
|
['Desbouis', 'Katell', 2, 'SI', '', ''],
|
|
['Dupouy', 'Jérémie', 7, 'A', '', ''],
|
|
['Hariri--Gautier-Picard', 'Grégoire', 8, 'A', '', ''],
|
|
['Juricevic', 'Matteo', 8, 'A', '', ''],
|
|
['Knanoua', 'Anas', 8, 'A', '', ''],
|
|
['Lesenne', 'Pierrick', 9, 'A', '', ''],
|
|
['Lin', 'Hao', 2, 'SI', '', ''],
|
|
['Masbatin', 'Lucas', 2, 'SI', '', ''],
|
|
['Mayuran', 'Mithushan', 9, 'A', '', ''],
|
|
['Messahli', 'Yassine', 9, 'A', '', ''],
|
|
['Moguérou', 'Valentin', 10, 'B', '', ''],
|
|
['Mohellebi', 'Mathéo', 10, 'B', '', ''],
|
|
['Mouisset--Ferrara', 'Maël', 10, 'B', '', ''],
|
|
['Ottavi', 'Corentin', 11, 'B', '', ''],
|
|
['Ponce', 'Alexian', 11, 'B', '', ''],
|
|
['Pujol', 'Raphaël', 11, 'B', '', ''],
|
|
['Pustetto', 'Mathis', 12, 'B', '', ''],
|
|
['Radice', 'Roman', 12, 'B', '', ''],
|
|
['Rat', 'Evelyn', 12, 'B', '', ''],
|
|
['Rousse', 'Louis', 3, 'SI', '', ''],
|
|
['Roux', 'Gaëtan', 3, 'SI', '', ''],
|
|
['Rouyre--Cros', 'Célian', 3, 'SI', '', ''],
|
|
['Sourbé', 'François-Gabriel', 13, 'B', '', ''],
|
|
['Stourbe', 'Simon', 13, 'B', '', ''],
|
|
['Thai', 'Dany', 13, 'B', '', ''],
|
|
['Théodore', 'Jonathan', 14, 'B', '', ''],
|
|
['Vandroux', 'Benoît', 14, 'B', '', ''],
|
|
['Veyssière', 'Thibaud', 14, 'B', '', ''],
|
|
['Vié', 'Adrien', 15, 'B', '', ''],
|
|
['Ye', 'Luan', 15, 'B', '', ''],
|
|
['Zarka', 'Amélie', 15, 'B', '', ''],
|
|
]
|
|
"""
|
|
|
|
creneaux = [
|
|
["Mathématiques", "vendredi", "17:00", "M. OUBAHA", "C382"],
|
|
["Anglais", "mercredi", "14:00", "Mme LE GOURIELLEC", "C393"],
|
|
["Mathématiques", "mercredi", "15:00", "M. BOULLY", "R004"],
|
|
["Physique", "mardi", "14:00", "Mme CHEVALIER", "R103"],
|
|
["Mathématiques", "mardi", "18:00", "M. RAPIN", "V152"],
|
|
["Anglais", "mardi", "14:00", "Mme BELAGGOUNE", "C4??"],
|
|
["pas de colle", "", "", "", ""],
|
|
["Physique", "mardi", "17:00", "M. COLIN", "C386"],
|
|
["Mathématiques", "mercredi", "13:30", "M. BOUVEROT", "??"],
|
|
["Anglais", "lundi", "13:00", "M. HERBAUT", "V052"],
|
|
]
|
|
|
|
semaines = list(range(24, 34))
|
|
|
|
rotations = [
|
|
# [semaine, groupe, creneau]
|
|
(24, 1, 1),
|
|
(24, 2, 2),
|
|
(24, 3, 3),
|
|
(27, 3, 3),
|
|
(28, 3, 3),
|
|
(31, 3, 3),
|
|
]
|
|
|
|
class PDF(FPDF):
|
|
def liste_eleves(self, periode):
|
|
classe = periode.classe
|
|
etudiants = Etudiant.objects.filter(classe=classe)
|
|
|
|
with self.table(
|
|
align="RIGHT",
|
|
col_widths=(4, 3, 1, 1, 1, 1),
|
|
width=80,
|
|
line_height=3) as table:
|
|
header = table.row()
|
|
for th in ("Nom", "Prénom", "Grp.", "TD", "LV1", "LV2"):
|
|
header.cell(th)
|
|
|
|
for etu in etudiants:
|
|
row = table.row()
|
|
row.cell(etu.nom.upper()) # Nom
|
|
row.cell(etu.prenom) # Prénom
|
|
row.cell(etu.groupe_de_colle(periode).libelle) # Groupe
|
|
row.cell("??")
|
|
#row.cell(etu.groupe_du_critere(periode, "TD")) # TD
|
|
row.cell("??") # LV1
|
|
row.cell("??") # LV2
|
|
|
|
|
|
def table_colloscope(self, periode, heading=True, est_colle=True):
|
|
semaines = periode.range_semaines()
|
|
lundis = [ periode.classe.date_debut_sem(n) for n in semaines ]
|
|
creneaux = Creneau.objects.filter(periode=periode, est_colle=est_colle)
|
|
jours = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"]
|
|
|
|
with self.table(
|
|
align="LEFT",
|
|
width=190,
|
|
line_height=3,
|
|
col_widths=(2, 1, 1, 3, 1, *(1,)*len(semaines)),
|
|
num_heading_rows=2 if heading else 0,
|
|
first_row_as_headings=heading) as table:
|
|
|
|
if heading:
|
|
header = table.row()
|
|
for th in ("Matière", "Jour", "Heure", "Colleur", "Salle"):
|
|
header.cell(th, align="CENTER", rowspan=2)
|
|
|
|
for sem in semaines:
|
|
header.cell(str(sem), align="CENTER")
|
|
|
|
header2 = table.row()
|
|
for lundi in lundis:
|
|
header2.cell(lundi.strftime("%d/%m/%y"), align="CENTER")
|
|
|
|
|
|
for i, c in enumerate(creneaux):
|
|
matiere = c.matiere
|
|
jour = c.jour
|
|
heure = c.heure
|
|
colleur = c.colleur
|
|
salle = c.salle
|
|
|
|
row = table.row()
|
|
row.cell(matiere.libelle)
|
|
row.cell(jours[jour])
|
|
row.cell(heure.strftime("%H:%M"))
|
|
row.cell("{} {}".format("M." if colleur.civilite=="M" else "Mme", colleur.nom.upper()))
|
|
row.cell(salle)
|
|
|
|
for s in semaines:
|
|
if Rotation.objects.filter(creneau=c, semaine=s).exists():
|
|
r = Rotation.objects.get(creneau=c, semaine=s)
|
|
groupes = r.groupes
|
|
content = ", ".join(g.libelle for g in groupes.all())
|
|
|
|
with self.local_context(fill_color=(255, 100, 100) if r.est_modifiee() else None):
|
|
row.cell(content, align="CENTER")
|
|
else:
|
|
row.cell()
|
|
|
|
def generate(periode):
|
|
classe = periode.classe
|
|
|
|
pdf = PDF(orientation="landscape", format="a4")
|
|
pdf.set_font("helvetica", size=6)
|
|
|
|
titre = f"Colloscope {classe.libelle} {periode.libelle}"
|
|
|
|
pdf.set_title(titre)
|
|
pdf.set_author("projet colloscope")
|
|
pdf.set_author("projet colloscope")
|
|
|
|
pdf.add_page()
|
|
pdf.cell(text=titre, center=True, border=1, h=5)
|
|
base_y = pdf.t_margin + 10
|
|
pdf.set_y(base_y)
|
|
pdf.liste_eleves(periode)
|
|
pdf.set_y(base_y)
|
|
pdf.table_colloscope(periode)
|
|
pdf.y += 3
|
|
pdf.table_colloscope(periode, heading=False, est_colle=False)
|
|
|
|
pdf.output("test.pdf")
|
|
|
|
return pdf
|
|
|
|
def main():
|
|
classe = Classe.objects.get(id=1)
|
|
periode = Periode.objects.get(classe=classe, libelle="Semestre 5/2")
|
|
|
|
return generate(periode)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|