Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
from flask import Flask, render_template, request, send_file
|
2 |
import os
|
3 |
-
import
|
4 |
from docx import Document
|
5 |
from docx.shared import Pt, Cm, RGBColor
|
6 |
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
@@ -27,7 +27,7 @@ class EvaluationGymnique:
|
|
27 |
self.session = "2025"
|
28 |
self.nom_candidat = "Candidat"
|
29 |
|
30 |
-
# Liste vide pour les éléments techniques
|
31 |
self.elements_techniques = []
|
32 |
self.appreciations = ["M", "PM", "NM", "NR"]
|
33 |
|
@@ -105,7 +105,6 @@ class EvaluationGymnique:
|
|
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
|
@@ -142,9 +141,8 @@ class EvaluationGymnique:
|
|
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
|
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,7 +150,6 @@ class EvaluationGymnique:
|
|
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,7 +158,6 @@ class EvaluationGymnique:
|
|
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,8 +165,7 @@ class EvaluationGymnique:
|
|
169 |
run.bold = True
|
170 |
run.font.size = Pt(9)
|
171 |
run.italic = True
|
172 |
-
|
173 |
-
|
174 |
def ajouter_note_jury(self):
|
175 |
para = self.document.add_paragraph()
|
176 |
para.space_before = Pt(4)
|
@@ -338,7 +333,7 @@ app = Flask(__name__)
|
|
338 |
@app.route("/", methods=["GET", "POST"])
|
339 |
def index():
|
340 |
if request.method == "POST":
|
341 |
-
# Récupération des informations
|
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,7 +341,7 @@ def index():
|
|
346 |
session_value = request.form.get("session", "2025")
|
347 |
nom_candidat = request.form.get("nom_candidat", "Candidat")
|
348 |
|
349 |
-
# Création
|
350 |
evaluation = EvaluationGymnique()
|
351 |
evaluation.modifier_centre_examen(centre_examen)
|
352 |
evaluation.modifier_type_examen(type_examen)
|
@@ -355,7 +350,7 @@ def index():
|
|
355 |
evaluation.modifier_session(session_value)
|
356 |
evaluation.modifier_candidat(nom_candidat)
|
357 |
|
358 |
-
# Récupération
|
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")
|
@@ -363,12 +358,28 @@ def index():
|
|
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 |
-
#
|
371 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
|
373 |
return render_template("index.html")
|
374 |
|
|
|
1 |
from flask import Flask, render_template, request, send_file
|
2 |
import os
|
3 |
+
import subprocess
|
4 |
from docx import Document
|
5 |
from docx.shared import Pt, Cm, RGBColor
|
6 |
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
|
|
27 |
self.session = "2025"
|
28 |
self.nom_candidat = "Candidat"
|
29 |
|
30 |
+
# Liste vide pour les éléments techniques
|
31 |
self.elements_techniques = []
|
32 |
self.appreciations = ["M", "PM", "NM", "NR"]
|
33 |
|
|
|
105 |
self.document.add_paragraph().space_after = Pt(4)
|
106 |
|
107 |
def creer_tableau_elements(self):
|
|
|
108 |
table = self.document.add_table(rows=len(self.elements_techniques) + 1, cols=5)
|
109 |
table.style = 'Table Grid'
|
110 |
table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
|
|
141 |
run.font.color.rgb = RGBColor(0, 32, 96)
|
142 |
table.cell(0, 1).merge(table.cell(0, 2))
|
143 |
|
144 |
+
# Ajout des éléments techniques
|
145 |
for i, element in enumerate(self.elements_techniques, 1):
|
|
|
146 |
element_cell = table.cell(i, 0)
|
147 |
element_cell.text = element["nom"]
|
148 |
element_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
|
|
|
150 |
run.bold = True
|
151 |
run.font.size = Pt(9)
|
152 |
|
|
|
153 |
categorie_cell = table.cell(i, 1)
|
154 |
categorie_cell.text = element["categorie"]
|
155 |
categorie_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
|
|
158 |
run.font.size = Pt(9)
|
159 |
run.italic = True
|
160 |
|
|
|
161 |
points_cell = table.cell(i, 2)
|
162 |
points_cell.text = str(element["points"])
|
163 |
points_cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
|
|
165 |
run.bold = True
|
166 |
run.font.size = Pt(9)
|
167 |
run.italic = True
|
168 |
+
|
|
|
169 |
def ajouter_note_jury(self):
|
170 |
para = self.document.add_paragraph()
|
171 |
para.space_before = Pt(4)
|
|
|
333 |
@app.route("/", methods=["GET", "POST"])
|
334 |
def index():
|
335 |
if request.method == "POST":
|
336 |
+
# Récupération des informations depuis le formulaire
|
337 |
centre_examen = request.form.get("centre_examen", "Centre d'examen")
|
338 |
type_examen = request.form.get("type_examen", "Bac Général")
|
339 |
serie = request.form.get("serie", "Série")
|
|
|
341 |
session_value = request.form.get("session", "2025")
|
342 |
nom_candidat = request.form.get("nom_candidat", "Candidat")
|
343 |
|
344 |
+
# Création et configuration du document
|
345 |
evaluation = EvaluationGymnique()
|
346 |
evaluation.modifier_centre_examen(centre_examen)
|
347 |
evaluation.modifier_type_examen(type_examen)
|
|
|
350 |
evaluation.modifier_session(session_value)
|
351 |
evaluation.modifier_candidat(nom_candidat)
|
352 |
|
353 |
+
# Récupération des éléments techniques ajoutés dynamiquement
|
354 |
element_names = request.form.getlist("new_element_name")
|
355 |
element_categories = request.form.getlist("new_element_categorie")
|
356 |
element_points = request.form.getlist("new_element_points")
|
|
|
358 |
if name and cat and pts:
|
359 |
evaluation.ajouter_element(name, cat, pts)
|
360 |
|
361 |
+
# Génération du document DOCX
|
362 |
filename = "evaluation_gymnastique.docx"
|
363 |
evaluation.generer_document(filename)
|
364 |
|
365 |
+
# Vérification du format de sortie demandé
|
366 |
+
output_format = request.form.get("format", "docx")
|
367 |
+
if output_format == "pdf":
|
368 |
+
pdf_filename = "evaluation_gymnastique.pdf"
|
369 |
+
# Conversion en PDF via LibreOffice en mode headless
|
370 |
+
command = [
|
371 |
+
"libreoffice",
|
372 |
+
"--headless",
|
373 |
+
"--convert-to",
|
374 |
+
"pdf",
|
375 |
+
filename,
|
376 |
+
"--outdir",
|
377 |
+
"."
|
378 |
+
]
|
379 |
+
subprocess.run(command, check=True)
|
380 |
+
return send_file(pdf_filename, as_attachment=True)
|
381 |
+
else:
|
382 |
+
return send_file(filename, as_attachment=True)
|
383 |
|
384 |
return render_template("index.html")
|
385 |
|