Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from docx.enum.text import WD_ALIGN_PARAGRAPH
|
|
| 7 |
from docx.enum.table import WD_TABLE_ALIGNMENT
|
| 8 |
from docx.oxml.ns import nsdecls
|
| 9 |
from docx.oxml import parse_xml
|
|
|
|
| 10 |
|
| 11 |
# Configuration des identifiants ConvertAPI
|
| 12 |
convertapi.api_credentials = 'secret_8wCI6pgOP9AxLVJG'
|
|
@@ -33,22 +34,89 @@ class EvaluationGymnique:
|
|
| 33 |
# Liste vide pour les éléments techniques
|
| 34 |
self.elements_techniques = []
|
| 35 |
self.appreciations = ["M", "PM", "NM", "NR"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def ajouter_entete_colore(self):
|
| 38 |
header_paragraph = self.document.add_paragraph()
|
| 39 |
header_paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 40 |
-
header_paragraph.space_after = Pt(6)
|
| 41 |
header_run = header_paragraph.add_run("ÉVALUATION GYMNASTIQUE")
|
| 42 |
header_run.bold = True
|
| 43 |
-
header_run.font.size = Pt(
|
| 44 |
header_run.font.color.rgb = RGBColor(0, 32, 96)
|
| 45 |
|
| 46 |
header_table = self.document.add_table(rows=3, cols=2)
|
| 47 |
header_table.style = 'Table Grid'
|
| 48 |
header_table.autofit = False
|
| 49 |
|
|
|
|
|
|
|
| 50 |
for row in header_table.rows:
|
| 51 |
-
row.height =
|
|
|
|
| 52 |
for row in header_table.rows:
|
| 53 |
for cell in row.cells:
|
| 54 |
shading_elm = parse_xml(f'<w:shd {nsdecls("w")} w:fill="D9E2F3"/>')
|
|
@@ -59,73 +127,72 @@ class EvaluationGymnique:
|
|
| 59 |
paragraph = cell.paragraphs[0]
|
| 60 |
run = paragraph.add_run("Centre d'examen: ")
|
| 61 |
run.bold = True
|
| 62 |
-
run.font.size = Pt(
|
| 63 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 64 |
-
paragraph.add_run(self.centre_examen).font.size = Pt(
|
| 65 |
|
| 66 |
cell = header_table.cell(0, 1)
|
| 67 |
paragraph = cell.paragraphs[0]
|
| 68 |
run = paragraph.add_run("Examen: ")
|
| 69 |
run.bold = True
|
| 70 |
-
run.font.size = Pt(
|
| 71 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 72 |
-
paragraph.add_run(self.type_examen).font.size = Pt(
|
| 73 |
|
| 74 |
# Deuxième ligne
|
| 75 |
cell = header_table.cell(1, 0)
|
| 76 |
paragraph = cell.paragraphs[0]
|
| 77 |
run = paragraph.add_run("Série: ")
|
| 78 |
run.bold = True
|
| 79 |
-
run.font.size = Pt(
|
| 80 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 81 |
-
paragraph.add_run(self.serie).font.size = Pt(
|
| 82 |
|
| 83 |
cell = header_table.cell(1, 1)
|
| 84 |
paragraph = cell.paragraphs[0]
|
| 85 |
run = paragraph.add_run("Établissement: ")
|
| 86 |
run.bold = True
|
| 87 |
-
run.font.size = Pt(
|
| 88 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 89 |
-
paragraph.add_run(self.etablissement).font.size = Pt(
|
| 90 |
|
| 91 |
# Troisième ligne
|
| 92 |
cell = header_table.cell(2, 0)
|
| 93 |
paragraph = cell.paragraphs[0]
|
| 94 |
run = paragraph.add_run("Session: ")
|
| 95 |
run.bold = True
|
| 96 |
-
run.font.size = Pt(
|
| 97 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 98 |
-
paragraph.add_run(self.session).font.size = Pt(
|
| 99 |
|
| 100 |
cell = header_table.cell(2, 1)
|
| 101 |
paragraph = cell.paragraphs[0]
|
| 102 |
run = paragraph.add_run("Candidat: ")
|
| 103 |
run.bold = True
|
| 104 |
-
run.font.size = Pt(
|
| 105 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 106 |
-
paragraph.add_run(self.nom_candidat).font.size = Pt(
|
| 107 |
|
| 108 |
-
|
|
|
|
| 109 |
|
| 110 |
def creer_tableau_elements(self):
|
| 111 |
table = self.document.add_table(rows=len(self.elements_techniques) + 1, cols=5)
|
| 112 |
table.style = 'Table Grid'
|
| 113 |
table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
| 114 |
|
|
|
|
|
|
|
|
|
|
| 115 |
# Configuration des largeurs de colonnes
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
for cell in table.columns[2].cells:
|
| 121 |
-
cell.width = Cm(2)
|
| 122 |
-
for cell in table.columns[3].cells:
|
| 123 |
-
cell.width = Cm(2.5)
|
| 124 |
-
for cell in table.columns[4].cells:
|
| 125 |
-
cell.width = Cm(2.5)
|
| 126 |
|
|
|
|
| 127 |
for row in table.rows:
|
| 128 |
-
row.height = Cm(
|
| 129 |
|
| 130 |
# En-tête du tableau
|
| 131 |
header_row = table.rows[0]
|
|
@@ -140,7 +207,7 @@ class EvaluationGymnique:
|
|
| 140 |
cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 141 |
run = cell.paragraphs[0].runs[0]
|
| 142 |
run.bold = True
|
| 143 |
-
run.font.size = Pt(
|
| 144 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 145 |
table.cell(0, 1).merge(table.cell(0, 2))
|
| 146 |
|
|
@@ -151,14 +218,14 @@ class EvaluationGymnique:
|
|
| 151 |
element_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
|
| 152 |
run = element_cell.paragraphs[0].runs[0]
|
| 153 |
run.bold = True
|
| 154 |
-
run.font.size = Pt(
|
| 155 |
|
| 156 |
categorie_cell = table.cell(i, 1)
|
| 157 |
categorie_cell.text = element["categorie"]
|
| 158 |
categorie_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 159 |
run = categorie_cell.paragraphs[0].runs[0]
|
| 160 |
run.bold = True
|
| 161 |
-
run.font.size = Pt(
|
| 162 |
run.italic = True
|
| 163 |
|
| 164 |
points_cell = table.cell(i, 2)
|
|
@@ -166,29 +233,34 @@ class EvaluationGymnique:
|
|
| 166 |
points_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 167 |
run = points_cell.paragraphs[0].runs[0]
|
| 168 |
run.bold = True
|
| 169 |
-
run.font.size = Pt(
|
| 170 |
run.italic = True
|
| 171 |
|
| 172 |
def ajouter_note_jury(self):
|
| 173 |
para = self.document.add_paragraph()
|
| 174 |
-
para.space_before = Pt(4)
|
| 175 |
-
para.space_after = Pt(4)
|
| 176 |
run = para.add_run("NB1 : Zone réservée aux membres du jury ! Le jury cochera le point correspondant au niveau de réalisation de l'élément gymnique par le candidat.")
|
| 177 |
run.bold = True
|
| 178 |
run.font.color.rgb = RGBColor(255, 0, 0)
|
| 179 |
-
run.font.size = Pt(
|
| 180 |
|
| 181 |
def creer_tableau_recapitulatif(self):
|
| 182 |
note_table = self.document.add_table(rows=3, cols=13)
|
| 183 |
note_table.style = 'Table Grid'
|
| 184 |
note_table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
| 185 |
|
|
|
|
| 186 |
for row in note_table.rows:
|
| 187 |
-
row.height = Cm(0.6)
|
|
|
|
| 188 |
for cell in note_table.rows[0].cells:
|
| 189 |
shading_elm = parse_xml(f'<w:shd {nsdecls("w")} w:fill="BDD7EE"/>')
|
| 190 |
cell._tc.get_or_add_tcPr().append(shading_elm)
|
| 191 |
|
|
|
|
|
|
|
|
|
|
| 192 |
for col, (type_lettre, points) in enumerate([("A", "1pt"), ("B", "1,5pt"), ("C", "2pts"), ("D", "2,5pts"), ("E", "3pts")]):
|
| 193 |
idx = col * 2
|
| 194 |
if idx + 1 < len(note_table.columns):
|
|
@@ -198,7 +270,7 @@ class EvaluationGymnique:
|
|
| 198 |
cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 199 |
for run in cell.paragraphs[0].runs:
|
| 200 |
run.bold = True
|
| 201 |
-
run.font.size = Pt(
|
| 202 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 203 |
|
| 204 |
for col, (titre, points) in enumerate([("ROV", "2pts"), ("Projet", "2pts"), ("Réalisation", "16pts")], 10):
|
|
@@ -208,7 +280,7 @@ class EvaluationGymnique:
|
|
| 208 |
cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 209 |
for run in cell.paragraphs[0].runs:
|
| 210 |
run.bold = True
|
| 211 |
-
run.font.size = Pt(
|
| 212 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 213 |
|
| 214 |
for col in range(5):
|
|
@@ -219,14 +291,14 @@ class EvaluationGymnique:
|
|
| 219 |
neg_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 220 |
for run in neg_cell.paragraphs[0].runs:
|
| 221 |
run.italic = True
|
| 222 |
-
run.font.size = Pt(
|
| 223 |
|
| 224 |
note_cell = note_table.cell(1, idx + 1)
|
| 225 |
note_cell.text = "Note"
|
| 226 |
note_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 227 |
for run in note_cell.paragraphs[0].runs:
|
| 228 |
run.italic = True
|
| 229 |
-
run.font.size = Pt(
|
| 230 |
|
| 231 |
for col in range(10, 13):
|
| 232 |
if col < len(note_table.columns):
|
|
@@ -235,14 +307,7 @@ class EvaluationGymnique:
|
|
| 235 |
cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 236 |
for run in cell.paragraphs[0].runs:
|
| 237 |
run.italic = True
|
| 238 |
-
run.font.size = Pt(
|
| 239 |
-
|
| 240 |
-
for col, type_lettre in enumerate(["A", "B", "C", "D", "E"]):
|
| 241 |
-
idx = col * 2
|
| 242 |
-
if idx < len(note_table.columns):
|
| 243 |
-
neg_cell = note_table.cell(2, idx)
|
| 244 |
-
neg_cell.text = ""
|
| 245 |
-
neg_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 246 |
|
| 247 |
def ajouter_note_candidat_avec_cadre(self):
|
| 248 |
note_table = self.document.add_table(rows=1, cols=1)
|
|
@@ -254,17 +319,21 @@ class EvaluationGymnique:
|
|
| 254 |
cell._tc.get_or_add_tcPr().append(shading_elm)
|
| 255 |
|
| 256 |
p = cell.paragraphs[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
run = p.add_run("NB2: Après le choix des catégories d'éléments gymniques par le candidat, ce dernier remplira la colonne de pointage selon l'orientation suivante: A (0.25; 0.5; 0.75; 1) B (0.25; 0.5; 0.75; 1; 1.25; 1.5) C (0.5; 0.75; 1; 1.25; 1.5; 2) D (0.75; 1; 1.25; 1.5; 2; 2.5) et E (0.75; 1; 1.5; 2; 2.5; 3) également, le candidat devra fournir 2 copies de son projet sur une page! (appréciations: NR, NM, PM, M).")
|
| 258 |
run.italic = True
|
| 259 |
-
run.font.size = Pt(
|
| 260 |
|
| 261 |
def ajouter_zone_note(self):
|
| 262 |
zone_note = self.document.add_table(rows=1, cols=2)
|
| 263 |
zone_note.style = 'Table Grid'
|
| 264 |
zone_note.alignment = WD_TABLE_ALIGNMENT.RIGHT
|
| 265 |
|
| 266 |
-
#
|
| 267 |
-
cell_width = Cm(1.5)
|
| 268 |
|
| 269 |
cell_libelle = zone_note.cell(0, 0)
|
| 270 |
cell_libelle.width = cell_width
|
|
@@ -272,7 +341,7 @@ class EvaluationGymnique:
|
|
| 272 |
cell_libelle.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.RIGHT
|
| 273 |
run = cell_libelle.paragraphs[0].runs[0]
|
| 274 |
run.bold = True
|
| 275 |
-
run.font.size = Pt(
|
| 276 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 277 |
|
| 278 |
cell_saisie = zone_note.cell(0, 1)
|
|
@@ -284,23 +353,34 @@ class EvaluationGymnique:
|
|
| 284 |
cell_saisie.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 285 |
run = cell_saisie.paragraphs[0].runs[0]
|
| 286 |
run.bold = True
|
| 287 |
-
run.font.size = Pt(
|
| 288 |
-
|
| 289 |
-
# Ajouter plus d'espace avant la liste des correcteurs
|
| 290 |
-
self.document.add_paragraph().space_after = Pt(5)
|
| 291 |
-
self.document.add_paragraph().space_after = Pt(5)
|
| 292 |
|
| 293 |
def ajouter_lignes_correcteurs(self):
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
for role in ["Projet", "principal", "ROV"]:
|
| 298 |
para = self.document.add_paragraph()
|
| 299 |
-
para.space_before = Pt(2)
|
| 300 |
-
para.space_after = Pt(2)
|
| 301 |
-
run = para.add_run(
|
| 302 |
run.bold = True
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
# Méthodes de modification des données
|
| 306 |
def modifier_centre_examen(self, nom):
|
|
@@ -329,13 +409,30 @@ class EvaluationGymnique:
|
|
| 329 |
})
|
| 330 |
|
| 331 |
def generer_document(self, nom_fichier="evaluation_gymnastique.docx"):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
self.ajouter_entete_colore()
|
| 333 |
self.creer_tableau_elements()
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
self.
|
| 337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
self.ajouter_note_candidat_avec_cadre()
|
|
|
|
| 339 |
self.document.save(nom_fichier)
|
| 340 |
return nom_fichier
|
| 341 |
|
|
|
|
| 7 |
from docx.enum.table import WD_TABLE_ALIGNMENT
|
| 8 |
from docx.oxml.ns import nsdecls
|
| 9 |
from docx.oxml import parse_xml
|
| 10 |
+
import math
|
| 11 |
|
| 12 |
# Configuration des identifiants ConvertAPI
|
| 13 |
convertapi.api_credentials = 'secret_8wCI6pgOP9AxLVJG'
|
|
|
|
| 34 |
# Liste vide pour les éléments techniques
|
| 35 |
self.elements_techniques = []
|
| 36 |
self.appreciations = ["M", "PM", "NM", "NR"]
|
| 37 |
+
|
| 38 |
+
# Paramètres dynamiques pour la mise en page
|
| 39 |
+
self.base_font_size = 10 # Taille de base pour les polices
|
| 40 |
+
self.base_header_font_size = 14 # Taille de base pour l'en-tête
|
| 41 |
+
self.base_row_height = 1 # Hauteur de base pour les lignes en cm
|
| 42 |
+
self.table_font_size = 9 # Taille de base pour les tableaux
|
| 43 |
+
|
| 44 |
+
# Espace disponible sur une page A4 (en cm)
|
| 45 |
+
self.available_height = 27.7 # 29.7 - marges
|
| 46 |
+
|
| 47 |
+
# Estimation de l'espace fixe occupé par les éléments autres que le tableau principal
|
| 48 |
+
self.fixed_elements_height = 14 # Estimation en cm
|
| 49 |
+
|
| 50 |
+
def calculate_dynamic_sizing(self):
|
| 51 |
+
"""Calcule les tailles dynamiques en fonction du nombre d'éléments techniques"""
|
| 52 |
+
# Nombre d'éléments techniques
|
| 53 |
+
num_elements = len(self.elements_techniques)
|
| 54 |
+
|
| 55 |
+
# Calcul de l'espace nécessaire pour le tableau principal
|
| 56 |
+
# Chaque élément nécessite une ligne + une ligne d'en-tête
|
| 57 |
+
required_table_height = (num_elements + 1) * self.base_row_height
|
| 58 |
+
|
| 59 |
+
# Espace disponible pour le tableau principal
|
| 60 |
+
available_space = self.available_height - self.fixed_elements_height
|
| 61 |
+
|
| 62 |
+
# Facteur d'ajustement
|
| 63 |
+
if required_table_height > available_space and num_elements > 0:
|
| 64 |
+
adjustment_factor = available_space / required_table_height
|
| 65 |
+
# Ajuster les tailles en fonction du nombre d'éléments
|
| 66 |
+
if num_elements <= 5:
|
| 67 |
+
# Ajustements mineurs pour peu d'éléments
|
| 68 |
+
self.dynamic_font_size = max(self.base_font_size - 1, 7)
|
| 69 |
+
self.dynamic_header_font_size = max(self.base_header_font_size - 1, 12)
|
| 70 |
+
self.dynamic_table_font_size = max(self.table_font_size - 1, 7)
|
| 71 |
+
self.dynamic_row_height = self.base_row_height * 0.9
|
| 72 |
+
self.spacing_factor = 0.9
|
| 73 |
+
elif num_elements <= 10:
|
| 74 |
+
# Ajustements moyens
|
| 75 |
+
self.dynamic_font_size = max(self.base_font_size - 2, 6.5)
|
| 76 |
+
self.dynamic_header_font_size = max(self.base_header_font_size - 2, 11)
|
| 77 |
+
self.dynamic_table_font_size = max(self.table_font_size - 2, 6.5)
|
| 78 |
+
self.dynamic_row_height = self.base_row_height * 0.75
|
| 79 |
+
self.spacing_factor = 0.7
|
| 80 |
+
elif num_elements <= 15:
|
| 81 |
+
# Ajustements significatifs
|
| 82 |
+
self.dynamic_font_size = max(self.base_font_size - 3, 6)
|
| 83 |
+
self.dynamic_header_font_size = max(self.base_header_font_size - 3, 10)
|
| 84 |
+
self.dynamic_table_font_size = max(self.table_font_size - 3, 6)
|
| 85 |
+
self.dynamic_row_height = self.base_row_height * 0.6
|
| 86 |
+
self.spacing_factor = 0.5
|
| 87 |
+
else:
|
| 88 |
+
# Ajustements maximaux pour beaucoup d'éléments
|
| 89 |
+
self.dynamic_font_size = max(self.base_font_size - 4, 5.5)
|
| 90 |
+
self.dynamic_header_font_size = max(self.base_header_font_size - 4, 9)
|
| 91 |
+
self.dynamic_table_font_size = max(self.table_font_size - 4, 5.5)
|
| 92 |
+
self.dynamic_row_height = max(self.base_row_height * 0.5, 0.4) # Minimum 0.4 cm
|
| 93 |
+
self.spacing_factor = 0.3
|
| 94 |
+
else:
|
| 95 |
+
# Aucun ajustement nécessaire
|
| 96 |
+
self.dynamic_font_size = self.base_font_size
|
| 97 |
+
self.dynamic_header_font_size = self.base_header_font_size
|
| 98 |
+
self.dynamic_table_font_size = self.table_font_size
|
| 99 |
+
self.dynamic_row_height = self.base_row_height
|
| 100 |
+
self.spacing_factor = 1.0
|
| 101 |
|
| 102 |
def ajouter_entete_colore(self):
|
| 103 |
header_paragraph = self.document.add_paragraph()
|
| 104 |
header_paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 105 |
+
header_paragraph.space_after = Pt(6 * self.spacing_factor)
|
| 106 |
header_run = header_paragraph.add_run("ÉVALUATION GYMNASTIQUE")
|
| 107 |
header_run.bold = True
|
| 108 |
+
header_run.font.size = Pt(self.dynamic_header_font_size)
|
| 109 |
header_run.font.color.rgb = RGBColor(0, 32, 96)
|
| 110 |
|
| 111 |
header_table = self.document.add_table(rows=3, cols=2)
|
| 112 |
header_table.style = 'Table Grid'
|
| 113 |
header_table.autofit = False
|
| 114 |
|
| 115 |
+
# Ajustement dynamique de la hauteur des lignes
|
| 116 |
+
row_height = Cm(0.8 * (self.dynamic_row_height / self.base_row_height))
|
| 117 |
for row in header_table.rows:
|
| 118 |
+
row.height = row_height
|
| 119 |
+
|
| 120 |
for row in header_table.rows:
|
| 121 |
for cell in row.cells:
|
| 122 |
shading_elm = parse_xml(f'<w:shd {nsdecls("w")} w:fill="D9E2F3"/>')
|
|
|
|
| 127 |
paragraph = cell.paragraphs[0]
|
| 128 |
run = paragraph.add_run("Centre d'examen: ")
|
| 129 |
run.bold = True
|
| 130 |
+
run.font.size = Pt(self.dynamic_font_size)
|
| 131 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 132 |
+
paragraph.add_run(self.centre_examen).font.size = Pt(self.dynamic_font_size)
|
| 133 |
|
| 134 |
cell = header_table.cell(0, 1)
|
| 135 |
paragraph = cell.paragraphs[0]
|
| 136 |
run = paragraph.add_run("Examen: ")
|
| 137 |
run.bold = True
|
| 138 |
+
run.font.size = Pt(self.dynamic_font_size)
|
| 139 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 140 |
+
paragraph.add_run(self.type_examen).font.size = Pt(self.dynamic_font_size)
|
| 141 |
|
| 142 |
# Deuxième ligne
|
| 143 |
cell = header_table.cell(1, 0)
|
| 144 |
paragraph = cell.paragraphs[0]
|
| 145 |
run = paragraph.add_run("Série: ")
|
| 146 |
run.bold = True
|
| 147 |
+
run.font.size = Pt(self.dynamic_font_size)
|
| 148 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 149 |
+
paragraph.add_run(self.serie).font.size = Pt(self.dynamic_font_size)
|
| 150 |
|
| 151 |
cell = header_table.cell(1, 1)
|
| 152 |
paragraph = cell.paragraphs[0]
|
| 153 |
run = paragraph.add_run("Établissement: ")
|
| 154 |
run.bold = True
|
| 155 |
+
run.font.size = Pt(self.dynamic_font_size)
|
| 156 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 157 |
+
paragraph.add_run(self.etablissement).font.size = Pt(self.dynamic_font_size)
|
| 158 |
|
| 159 |
# Troisième ligne
|
| 160 |
cell = header_table.cell(2, 0)
|
| 161 |
paragraph = cell.paragraphs[0]
|
| 162 |
run = paragraph.add_run("Session: ")
|
| 163 |
run.bold = True
|
| 164 |
+
run.font.size = Pt(self.dynamic_font_size)
|
| 165 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 166 |
+
paragraph.add_run(self.session).font.size = Pt(self.dynamic_font_size)
|
| 167 |
|
| 168 |
cell = header_table.cell(2, 1)
|
| 169 |
paragraph = cell.paragraphs[0]
|
| 170 |
run = paragraph.add_run("Candidat: ")
|
| 171 |
run.bold = True
|
| 172 |
+
run.font.size = Pt(self.dynamic_font_size)
|
| 173 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 174 |
+
paragraph.add_run(self.nom_candidat).font.size = Pt(self.dynamic_font_size)
|
| 175 |
|
| 176 |
+
# Espace après l'en-tête ajusté dynamiquement
|
| 177 |
+
self.document.add_paragraph().space_after = Pt(4 * self.spacing_factor)
|
| 178 |
|
| 179 |
def creer_tableau_elements(self):
|
| 180 |
table = self.document.add_table(rows=len(self.elements_techniques) + 1, cols=5)
|
| 181 |
table.style = 'Table Grid'
|
| 182 |
table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
| 183 |
|
| 184 |
+
# Configuration des largeurs de colonnes (proportionnelle)
|
| 185 |
+
total_width = 18 # Largeur totale approximative en cm
|
| 186 |
+
|
| 187 |
# Configuration des largeurs de colonnes
|
| 188 |
+
col_widths = [8, 3, 2, 2.5, 2.5] # Largeurs originales
|
| 189 |
+
for i, width in enumerate(col_widths):
|
| 190 |
+
for cell in table.columns[i].cells:
|
| 191 |
+
cell.width = Cm(width)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
+
# Ajustement dynamique de la hauteur des lignes
|
| 194 |
for row in table.rows:
|
| 195 |
+
row.height = Cm(self.dynamic_row_height)
|
| 196 |
|
| 197 |
# En-tête du tableau
|
| 198 |
header_row = table.rows[0]
|
|
|
|
| 207 |
cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 208 |
run = cell.paragraphs[0].runs[0]
|
| 209 |
run.bold = True
|
| 210 |
+
run.font.size = Pt(self.dynamic_table_font_size)
|
| 211 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 212 |
table.cell(0, 1).merge(table.cell(0, 2))
|
| 213 |
|
|
|
|
| 218 |
element_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
|
| 219 |
run = element_cell.paragraphs[0].runs[0]
|
| 220 |
run.bold = True
|
| 221 |
+
run.font.size = Pt(self.dynamic_table_font_size)
|
| 222 |
|
| 223 |
categorie_cell = table.cell(i, 1)
|
| 224 |
categorie_cell.text = element["categorie"]
|
| 225 |
categorie_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 226 |
run = categorie_cell.paragraphs[0].runs[0]
|
| 227 |
run.bold = True
|
| 228 |
+
run.font.size = Pt(self.dynamic_table_font_size)
|
| 229 |
run.italic = True
|
| 230 |
|
| 231 |
points_cell = table.cell(i, 2)
|
|
|
|
| 233 |
points_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 234 |
run = points_cell.paragraphs[0].runs[0]
|
| 235 |
run.bold = True
|
| 236 |
+
run.font.size = Pt(self.dynamic_table_font_size)
|
| 237 |
run.italic = True
|
| 238 |
|
| 239 |
def ajouter_note_jury(self):
|
| 240 |
para = self.document.add_paragraph()
|
| 241 |
+
para.space_before = Pt(4 * self.spacing_factor)
|
| 242 |
+
para.space_after = Pt(4 * self.spacing_factor)
|
| 243 |
run = para.add_run("NB1 : Zone réservée aux membres du jury ! Le jury cochera le point correspondant au niveau de réalisation de l'élément gymnique par le candidat.")
|
| 244 |
run.bold = True
|
| 245 |
run.font.color.rgb = RGBColor(255, 0, 0)
|
| 246 |
+
run.font.size = Pt(max(self.dynamic_font_size - 2, 5.5)) # Minimum 5.5pt
|
| 247 |
|
| 248 |
def creer_tableau_recapitulatif(self):
|
| 249 |
note_table = self.document.add_table(rows=3, cols=13)
|
| 250 |
note_table.style = 'Table Grid'
|
| 251 |
note_table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
| 252 |
|
| 253 |
+
# Ajuster la hauteur des lignes
|
| 254 |
for row in note_table.rows:
|
| 255 |
+
row.height = Cm(0.6 * (self.dynamic_row_height / self.base_row_height))
|
| 256 |
+
|
| 257 |
for cell in note_table.rows[0].cells:
|
| 258 |
shading_elm = parse_xml(f'<w:shd {nsdecls("w")} w:fill="BDD7EE"/>')
|
| 259 |
cell._tc.get_or_add_tcPr().append(shading_elm)
|
| 260 |
|
| 261 |
+
# Taille de police pour le tableau récapitulatif (légèrement plus petite)
|
| 262 |
+
recap_font_size = max(self.dynamic_table_font_size - 1, 5)
|
| 263 |
+
|
| 264 |
for col, (type_lettre, points) in enumerate([("A", "1pt"), ("B", "1,5pt"), ("C", "2pts"), ("D", "2,5pts"), ("E", "3pts")]):
|
| 265 |
idx = col * 2
|
| 266 |
if idx + 1 < len(note_table.columns):
|
|
|
|
| 270 |
cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 271 |
for run in cell.paragraphs[0].runs:
|
| 272 |
run.bold = True
|
| 273 |
+
run.font.size = Pt(recap_font_size)
|
| 274 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 275 |
|
| 276 |
for col, (titre, points) in enumerate([("ROV", "2pts"), ("Projet", "2pts"), ("Réalisation", "16pts")], 10):
|
|
|
|
| 280 |
cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 281 |
for run in cell.paragraphs[0].runs:
|
| 282 |
run.bold = True
|
| 283 |
+
run.font.size = Pt(recap_font_size)
|
| 284 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 285 |
|
| 286 |
for col in range(5):
|
|
|
|
| 291 |
neg_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 292 |
for run in neg_cell.paragraphs[0].runs:
|
| 293 |
run.italic = True
|
| 294 |
+
run.font.size = Pt(recap_font_size)
|
| 295 |
|
| 296 |
note_cell = note_table.cell(1, idx + 1)
|
| 297 |
note_cell.text = "Note"
|
| 298 |
note_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 299 |
for run in note_cell.paragraphs[0].runs:
|
| 300 |
run.italic = True
|
| 301 |
+
run.font.size = Pt(recap_font_size)
|
| 302 |
|
| 303 |
for col in range(10, 13):
|
| 304 |
if col < len(note_table.columns):
|
|
|
|
| 307 |
cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 308 |
for run in cell.paragraphs[0].runs:
|
| 309 |
run.italic = True
|
| 310 |
+
run.font.size = Pt(recap_font_size)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
def ajouter_note_candidat_avec_cadre(self):
|
| 313 |
note_table = self.document.add_table(rows=1, cols=1)
|
|
|
|
| 319 |
cell._tc.get_or_add_tcPr().append(shading_elm)
|
| 320 |
|
| 321 |
p = cell.paragraphs[0]
|
| 322 |
+
|
| 323 |
+
# Pour les notes de bas, on adapte encore plus la taille si nécessaire
|
| 324 |
+
font_size = max(6 * self.spacing_factor, 5)
|
| 325 |
+
|
| 326 |
run = p.add_run("NB2: Après le choix des catégories d'éléments gymniques par le candidat, ce dernier remplira la colonne de pointage selon l'orientation suivante: A (0.25; 0.5; 0.75; 1) B (0.25; 0.5; 0.75; 1; 1.25; 1.5) C (0.5; 0.75; 1; 1.25; 1.5; 2) D (0.75; 1; 1.25; 1.5; 2; 2.5) et E (0.75; 1; 1.5; 2; 2.5; 3) également, le candidat devra fournir 2 copies de son projet sur une page! (appréciations: NR, NM, PM, M).")
|
| 327 |
run.italic = True
|
| 328 |
+
run.font.size = Pt(font_size)
|
| 329 |
|
| 330 |
def ajouter_zone_note(self):
|
| 331 |
zone_note = self.document.add_table(rows=1, cols=2)
|
| 332 |
zone_note.style = 'Table Grid'
|
| 333 |
zone_note.alignment = WD_TABLE_ALIGNMENT.RIGHT
|
| 334 |
|
| 335 |
+
# Ajuster la taille selon le nombre d'éléments
|
| 336 |
+
cell_width = Cm(1.5 * self.spacing_factor)
|
| 337 |
|
| 338 |
cell_libelle = zone_note.cell(0, 0)
|
| 339 |
cell_libelle.width = cell_width
|
|
|
|
| 341 |
cell_libelle.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.RIGHT
|
| 342 |
run = cell_libelle.paragraphs[0].runs[0]
|
| 343 |
run.bold = True
|
| 344 |
+
run.font.size = Pt(self.dynamic_table_font_size)
|
| 345 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
| 346 |
|
| 347 |
cell_saisie = zone_note.cell(0, 1)
|
|
|
|
| 353 |
cell_saisie.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 354 |
run = cell_saisie.paragraphs[0].runs[0]
|
| 355 |
run.bold = True
|
| 356 |
+
run.font.size = Pt(self.dynamic_table_font_size)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
|
| 358 |
def ajouter_lignes_correcteurs(self):
|
| 359 |
+
# Si beaucoup d'éléments, fusionner tous les correcteurs sur une seule ligne
|
| 360 |
+
if len(self.elements_techniques) > 12:
|
|
|
|
|
|
|
| 361 |
para = self.document.add_paragraph()
|
| 362 |
+
para.space_before = Pt(2 * self.spacing_factor)
|
| 363 |
+
para.space_after = Pt(2 * self.spacing_factor)
|
| 364 |
+
run = para.add_run("Correcteurs: ")
|
| 365 |
run.bold = True
|
| 366 |
+
run.font.size = Pt(self.dynamic_font_size)
|
| 367 |
+
para.add_run("Projet / Principal / ROV").font.size = Pt(self.dynamic_font_size)
|
| 368 |
+
else:
|
| 369 |
+
# Format standard avec une ligne par correcteur
|
| 370 |
+
para_intro = self.document.add_paragraph()
|
| 371 |
+
para_intro.space_before = Pt(2 * self.spacing_factor)
|
| 372 |
+
|
| 373 |
+
for role in ["Projet", "principal", "ROV"]:
|
| 374 |
+
para = self.document.add_paragraph()
|
| 375 |
+
para.space_before = Pt(2 * self.spacing_factor)
|
| 376 |
+
para.space_after = Pt(2 * self.spacing_factor)
|
| 377 |
+
run = para.add_run(f"Correcteur {role} : ")
|
| 378 |
+
run.bold = True
|
| 379 |
+
run.font.size = Pt(self.dynamic_font_size)
|
| 380 |
+
|
| 381 |
+
# Ajuster le nombre de points en fonction du nombre d'éléments
|
| 382 |
+
points_count = max(20, 50 - len(self.elements_techniques) * 2)
|
| 383 |
+
para.add_run("." * points_count).font.size = Pt(self.dynamic_font_size)
|
| 384 |
|
| 385 |
# Méthodes de modification des données
|
| 386 |
def modifier_centre_examen(self, nom):
|
|
|
|
| 409 |
})
|
| 410 |
|
| 411 |
def generer_document(self, nom_fichier="evaluation_gymnastique.docx"):
|
| 412 |
+
# Calculer les paramètres dynamiques en fonction du nombre d'éléments
|
| 413 |
+
self.calculate_dynamic_sizing()
|
| 414 |
+
|
| 415 |
+
# Générer le document avec les paramètres dynamiques
|
| 416 |
self.ajouter_entete_colore()
|
| 417 |
self.creer_tableau_elements()
|
| 418 |
+
|
| 419 |
+
# Pour les documents très chargés, réorganiser les éléments
|
| 420 |
+
if len(self.elements_techniques) > 15:
|
| 421 |
+
# Version simplifiée et compacte
|
| 422 |
+
self.ajouter_note_jury()
|
| 423 |
+
self.creer_tableau_recapitulatif()
|
| 424 |
+
self.ajouter_zone_note()
|
| 425 |
+
self.ajouter_lignes_correcteurs() # Version compacte des correcteurs
|
| 426 |
+
else:
|
| 427 |
+
# Version standard
|
| 428 |
+
self.ajouter_note_jury()
|
| 429 |
+
self.creer_tableau_recapitulatif()
|
| 430 |
+
self.ajouter_lignes_correcteurs()
|
| 431 |
+
self.ajouter_zone_note()
|
| 432 |
+
|
| 433 |
+
# Toujours inclure la note candidat
|
| 434 |
self.ajouter_note_candidat_avec_cadre()
|
| 435 |
+
|
| 436 |
self.document.save(nom_fichier)
|
| 437 |
return nom_fichier
|
| 438 |
|