Docfile commited on
Commit
cf3dc49
·
verified ·
1 Parent(s): c236e57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -41
app.py CHANGED
@@ -2,9 +2,9 @@ from flask import Flask, render_template, request, send_file
2
  import os
3
  import docx
4
  from docx import Document
5
- from docx.shared import Pt, Inches, Cm, RGBColor
6
- from docx.enum.text import WD_ALIGN_PARAGRAPH, WD_COLOR_INDEX
7
- from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT, WD_TABLE_ALIGNMENT
8
  from docx.oxml.ns import nsdecls
9
  from docx.oxml import parse_xml
10
 
@@ -19,26 +19,16 @@ class EvaluationGymnique:
19
  self.document.sections[0].top_margin = Cm(1)
20
  self.document.sections[0].bottom_margin = Cm(1)
21
 
22
- # Données par défaut
23
  self.centre_examen = "Centre d'examen"
24
  self.type_examen = "Bac Général"
25
  self.serie = "Série"
26
  self.etablissement = "Établissement"
27
  self.session = "2025"
28
  self.nom_candidat = "Candidat"
29
- self.elements_techniques = [
30
- {"nom": "Salutation", "categorie": "A", "points": 1},
31
- {"nom": "Roulade avant élevée", "categorie": "B", "points": 1.5},
32
- {"nom": "Croix de Saint André, Sursaut préparatoire", "categorie": "A", "points": 1},
33
- {"nom": "Roue à 2 mains, ¾ tour", "categorie": "A", "points": 1},
34
- {"nom": "Roulade arrière arrivée jambes écartées", "categorie": "B", "points": 1.5},
35
- {"nom": "Planche écrasée", "categorie": "A", "points": 1},
36
- {"nom": "Chandelle sans pose des mains", "categorie": "B", "points": 1.5},
37
- {"nom": "Roulade arrière arrivée jambes tendues et serrées", "categorie": "B", "points": 1.5},
38
- {"nom": "Planche costale", "categorie": "C", "points": 2},
39
- {"nom": "Elan couru, 2 roues enchainées", "categorie": "C", "points": 2},
40
- {"nom": "Rondade saut carpé jambes écarts Salutation", "categorie": "C", "points": 2}
41
- ]
42
  self.appreciations = ["M", "PM", "NM", "NR"]
43
 
44
  def ajouter_entete_colore(self):
@@ -115,10 +105,12 @@ class EvaluationGymnique:
115
  self.document.add_paragraph().space_after = Pt(4)
116
 
117
  def creer_tableau_elements(self):
 
118
  table = self.document.add_table(rows=len(self.elements_techniques) + 1, cols=5)
119
  table.style = 'Table Grid'
120
  table.alignment = WD_TABLE_ALIGNMENT.CENTER
121
 
 
122
  for cell in table.columns[0].cells:
123
  cell.width = Cm(8)
124
  for cell in table.columns[1].cells:
@@ -133,6 +125,7 @@ class EvaluationGymnique:
133
  for row in table.rows:
134
  row.height = Cm(1)
135
 
 
136
  header_row = table.rows[0]
137
  for cell in header_row.cells:
138
  shading_elm = parse_xml(f'<w:shd {nsdecls("w")} w:fill="BDD7EE"/>')
@@ -149,7 +142,9 @@ class EvaluationGymnique:
149
  run.font.color.rgb = RGBColor(0, 32, 96)
150
  table.cell(0, 1).merge(table.cell(0, 2))
151
 
 
152
  for i, element in enumerate(self.elements_techniques, 1):
 
153
  element_cell = table.cell(i, 0)
154
  element_cell.text = element["nom"]
155
  element_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
@@ -157,6 +152,7 @@ class EvaluationGymnique:
157
  run.bold = True
158
  run.font.size = Pt(9)
159
 
 
160
  categorie_cell = table.cell(i, 1)
161
  categorie_cell.text = element["categorie"]
162
  categorie_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
@@ -165,6 +161,7 @@ class EvaluationGymnique:
165
  run.font.size = Pt(9)
166
  run.italic = True
167
 
 
168
  points_cell = table.cell(i, 2)
169
  points_cell.text = str(element["points"])
170
  points_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
@@ -172,7 +169,7 @@ class EvaluationGymnique:
172
  run.bold = True
173
  run.font.size = Pt(9)
174
  run.italic = True
175
- # Colonnes "APPRECIATIONS" et "POINTS Accordés" laissées vides
176
 
177
  def ajouter_note_jury(self):
178
  para = self.document.add_paragraph()
@@ -259,7 +256,7 @@ class EvaluationGymnique:
259
  cell._tc.get_or_add_tcPr().append(shading_elm)
260
 
261
  p = cell.paragraphs[0]
262
- 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) aussi, il sera exigé au candidat 2 copies de son projet sur une page! appréciations:NR (non réalisation) NM (non maitrisé), PM (peu maitrisé) et M (maitrisé).")
263
  run.italic = True
264
  run.font.size = Pt(8)
265
 
@@ -324,19 +321,6 @@ class EvaluationGymnique:
324
  "points": float(points)
325
  })
326
 
327
- def supprimer_element(self, index):
328
- if 0 <= index < len(self.elements_techniques):
329
- del self.elements_techniques[index]
330
-
331
- def modifier_element(self, index, nom=None, categorie=None, points=None):
332
- if 0 <= index < len(self.elements_techniques):
333
- if nom:
334
- self.elements_techniques[index]["nom"] = nom
335
- if categorie:
336
- self.elements_techniques[index]["categorie"] = categorie
337
- if points:
338
- self.elements_techniques[index]["points"] = float(points)
339
-
340
  def generer_document(self, nom_fichier="evaluation_gymnastique.docx"):
341
  self.ajouter_entete_colore()
342
  self.creer_tableau_elements()
@@ -354,7 +338,7 @@ app = Flask(__name__)
354
  @app.route("/", methods=["GET", "POST"])
355
  def index():
356
  if request.method == "POST":
357
- # Récupération des données du formulaire
358
  centre_examen = request.form.get("centre_examen", "Centre d'examen")
359
  type_examen = request.form.get("type_examen", "Bac Général")
360
  serie = request.form.get("serie", "Série")
@@ -362,7 +346,7 @@ def index():
362
  session_value = request.form.get("session", "2025")
363
  nom_candidat = request.form.get("nom_candidat", "Candidat")
364
 
365
- # Création de l'instance et modification des données
366
  evaluation = EvaluationGymnique()
367
  evaluation.modifier_centre_examen(centre_examen)
368
  evaluation.modifier_type_examen(type_examen)
@@ -371,18 +355,19 @@ def index():
371
  evaluation.modifier_session(session_value)
372
  evaluation.modifier_candidat(nom_candidat)
373
 
374
- # Optionnel : ajout d'un nouvel élément technique si renseigné
375
- new_element_name = request.form.get("new_element_name")
376
- new_element_categorie = request.form.get("new_element_categorie")
377
- new_element_points = request.form.get("new_element_points")
378
- if new_element_name and new_element_categorie and new_element_points:
379
- evaluation.ajouter_element(new_element_name, new_element_categorie, new_element_points)
 
380
 
381
  # Génération du document
382
  filename = "evaluation_gymnastique.docx"
383
  evaluation.generer_document(filename)
384
 
385
- # Envoi du fichier généré en téléchargement
386
  return send_file(filename, as_attachment=True)
387
 
388
  return render_template("index.html")
 
2
  import os
3
  import docx
4
  from docx import Document
5
+ from docx.shared import Pt, Cm, RGBColor
6
+ 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
 
 
19
  self.document.sections[0].top_margin = Cm(1)
20
  self.document.sections[0].bottom_margin = Cm(1)
21
 
22
+ # Informations d'en-tête par défaut
23
  self.centre_examen = "Centre d'examen"
24
  self.type_examen = "Bac Général"
25
  self.serie = "Série"
26
  self.etablissement = "Établissement"
27
  self.session = "2025"
28
  self.nom_candidat = "Candidat"
29
+
30
+ # Liste vide pour les éléments techniques (ajoutés depuis le Frontend)
31
+ self.elements_techniques = []
 
 
 
 
 
 
 
 
 
 
32
  self.appreciations = ["M", "PM", "NM", "NR"]
33
 
34
  def ajouter_entete_colore(self):
 
105
  self.document.add_paragraph().space_after = Pt(4)
106
 
107
  def creer_tableau_elements(self):
108
+ # Création d'un tableau avec une ligne d'en-tête + une ligne par élément technique
109
  table = self.document.add_table(rows=len(self.elements_techniques) + 1, cols=5)
110
  table.style = 'Table Grid'
111
  table.alignment = WD_TABLE_ALIGNMENT.CENTER
112
 
113
+ # Configuration des largeurs de colonnes
114
  for cell in table.columns[0].cells:
115
  cell.width = Cm(8)
116
  for cell in table.columns[1].cells:
 
125
  for row in table.rows:
126
  row.height = Cm(1)
127
 
128
+ # En-tête du tableau
129
  header_row = table.rows[0]
130
  for cell in header_row.cells:
131
  shading_elm = parse_xml(f'<w:shd {nsdecls("w")} w:fill="BDD7EE"/>')
 
142
  run.font.color.rgb = RGBColor(0, 32, 96)
143
  table.cell(0, 1).merge(table.cell(0, 2))
144
 
145
+ # Ajout des éléments techniques envoyés depuis le frontend
146
  for i, element in enumerate(self.elements_techniques, 1):
147
+ # Nom de l'élément
148
  element_cell = table.cell(i, 0)
149
  element_cell.text = element["nom"]
150
  element_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
 
152
  run.bold = True
153
  run.font.size = Pt(9)
154
 
155
+ # Catégorie
156
  categorie_cell = table.cell(i, 1)
157
  categorie_cell.text = element["categorie"]
158
  categorie_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
 
161
  run.font.size = Pt(9)
162
  run.italic = True
163
 
164
+ # Points
165
  points_cell = table.cell(i, 2)
166
  points_cell.text = str(element["points"])
167
  points_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
 
169
  run.bold = True
170
  run.font.size = Pt(9)
171
  run.italic = True
172
+ # Colonnes "APPRECIATIONS" et "POINTS Accordés" restent vides
173
 
174
  def ajouter_note_jury(self):
175
  para = self.document.add_paragraph()
 
256
  cell._tc.get_or_add_tcPr().append(shading_elm)
257
 
258
  p = cell.paragraphs[0]
259
+ 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).")
260
  run.italic = True
261
  run.font.size = Pt(8)
262
 
 
321
  "points": float(points)
322
  })
323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  def generer_document(self, nom_fichier="evaluation_gymnastique.docx"):
325
  self.ajouter_entete_colore()
326
  self.creer_tableau_elements()
 
338
  @app.route("/", methods=["GET", "POST"])
339
  def index():
340
  if request.method == "POST":
341
+ # Récupération des informations d'en-tête
342
  centre_examen = request.form.get("centre_examen", "Centre d'examen")
343
  type_examen = request.form.get("type_examen", "Bac Général")
344
  serie = request.form.get("serie", "Série")
 
346
  session_value = request.form.get("session", "2025")
347
  nom_candidat = request.form.get("nom_candidat", "Candidat")
348
 
349
+ # Création de l'instance et modification des informations
350
  evaluation = EvaluationGymnique()
351
  evaluation.modifier_centre_examen(centre_examen)
352
  evaluation.modifier_type_examen(type_examen)
 
355
  evaluation.modifier_session(session_value)
356
  evaluation.modifier_candidat(nom_candidat)
357
 
358
+ # Récupération de la liste des nouveaux éléments techniques
359
+ element_names = request.form.getlist("new_element_name")
360
+ element_categories = request.form.getlist("new_element_categorie")
361
+ element_points = request.form.getlist("new_element_points")
362
+ for name, cat, pts in zip(element_names, element_categories, element_points):
363
+ if name and cat and pts:
364
+ evaluation.ajouter_element(name, cat, pts)
365
 
366
  # Génération du document
367
  filename = "evaluation_gymnastique.docx"
368
  evaluation.generer_document(filename)
369
 
370
+ # Renvoi du fichier généré pour téléchargement
371
  return send_file(filename, as_attachment=True)
372
 
373
  return render_template("index.html")