Browse Source

Gestion de l'affichage des appréciations individuelles dans le tableau de bord

main
scayac 6 months ago
parent
commit
563f466360
  1. 146
      main/templates/resultat_appreciations.html
  2. 3
      main/urls.py
  3. 20
      main/views.py

146
main/templates/resultat_appreciations.html

@ -7,14 +7,14 @@ @@ -7,14 +7,14 @@
<link href="https://cdn.jsdelivr.net/npm/startbootstrap-sb-admin@7.0.6/dist/css/styles.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
:root {
:root {
color-scheme: light dark;
}
body, .bg-light {
}
body, .bg-light {
background-color: #f8f9fa;
color: #212529;
}
@media (prefers-color-scheme: dark) {
}
@media (prefers-color-scheme: dark) {
html, body, .bg-light {
background-color: #181a1b !important;
color: #f8f9fa !important;
@ -69,7 +69,25 @@ body, .bg-light { @@ -69,7 +69,25 @@ body, .bg-light {
color: #23272b !important;
border: 1px solid #444c56 !important;
}
}
.btn-outline-primary, .btn-outline-primary:focus, .btn-outline-primary:active, .btn-outline-primary:hover {
color: #23272b !important;
background-color: #ffe082 !important;
border-color: #ffe082 !important;
box-shadow: none !important;
}
.btn-outline-primary:disabled, .btn-outline-primary.disabled {
color: #bdbdbd !important;
background-color: #444c56 !important;
border-color: #444c56 !important;
}
}
#bulletinModal .modal-content, #bulletinModal .modal-body, #bulletinModal .modal-header {
background-color: #fff !important;
color: #23272b !important;
}
#bulletinModal .modal-title {
color: #23272b !important;
}
</style>
</head>
<body class="bg-light">
@ -108,7 +126,7 @@ body, .bg-light { @@ -108,7 +126,7 @@ body, .bg-light {
</div>
<div class="mb-3 d-flex gap-2">
<button id="generation-toggle" class="btn btn-primary mb-3">Lancer la génération</button>
<button id="export-pdf" class="btn btn-secondary mb-3" type="button" onclick="exportTableToPDF()">Exporter en PDF</button>
<button id="export-pdf" class="btn btn-primary mb-3" type="button" onclick="exportTableToPDF()">Exporter en PDF</button>
</div>
<div id="credit-alert" class="alert alert-danger d-none" role="alert">
Vous n'avez plus de crédits pour générer des appréciations.
@ -127,7 +145,12 @@ body, .bg-light { @@ -127,7 +145,12 @@ body, .bg-light {
<tr>
<td class="eleve" style="width:1%; white-space:nowrap;">{{ appreciation.eleve }}</td>
<td class="appreciation"></td>
<td style="width:1%; text-align:center;"><button class="btn btn-outline-primary btn-sm action-generate" type="button">Générer</button></td>
<td style="width:1%; text-align:center; vertical-align:middle;">
<div class="d-flex justify-content-center gap-2">
<button class="btn btn-outline-primary btn-sm action-generate w-100" type="button">Générer</button>
<button class="btn btn-outline-primary btn-sm action-bulletin w-100" type="button" data-eleve="{{ appreciation.eleve }}">Bulletin</button>
</div>
</td>
</tr>
{% endfor %}
{% else %}
@ -137,11 +160,28 @@ body, .bg-light { @@ -137,11 +160,28 @@ body, .bg-light {
{% endif %}
</tbody>
</table>
<!-- Injection des appréciations dans une variable JS globale pour accès rapide -->
<script id="appreciations-data" type="application/json">
{{ appreciations_json|safe }}
</script>
<script>
window.allAppreciations = {};
try {
const appreciationsList = JSON.parse(document.getElementById('appreciations-data').textContent);
appreciationsList.forEach(eleve => {
let appreciations = eleve.appreciations;
if (typeof appreciations === 'string') {
try { appreciations = JSON.parse(appreciations); } catch (e) { appreciations = []; }
}
window.allAppreciations[eleve.eleve] = appreciations;
});
} catch (e) { window.allAppreciations = {}; }
</script>
<script>
let stopGeneration = false;
let enCours = false;
let stopGeneration = false;
let enCours = false;
function updateActionButtons() {
function updateActionButtons() {
const rows = document.querySelectorAll('#appreciations-table tbody tr');
rows.forEach(row => {
const appreciationCell = row.querySelector('.appreciation');
@ -154,13 +194,13 @@ function updateActionButtons() { @@ -154,13 +194,13 @@ function updateActionButtons() {
}
btn.disabled = enCours;
});
}
}
function getRowsSansAppreciation() {
function getRowsSansAppreciation() {
return Array.from(document.querySelectorAll('#appreciations-table tbody tr')).filter(row => !row.querySelector('.appreciation').textContent.trim());
}
}
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('DOMContentLoaded', function() {
const btnToggle = document.getElementById('generation-toggle');
const selectModele = document.getElementById('modele-select');
const creditRestant = document.getElementById('credit-restant');
@ -282,13 +322,51 @@ document.addEventListener('DOMContentLoaded', function() { @@ -282,13 +322,51 @@ document.addEventListener('DOMContentLoaded', function() {
});
});
// Action individuelle sur bouton Bulletin
document.querySelectorAll('.action-bulletin').forEach(btn => {
btn.addEventListener('click', function() {
const eleve = btn.getAttribute('data-eleve');
fetch("{% url 'get_bulletin_eleve' %}", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
},
body: JSON.stringify({eleve: eleve})
})
.then(response => response.json())
.then(data => {
// Mettre le titre dans le header du modal
const modalTitle = document.getElementById('bulletinModalLabel');
if (modalTitle) {
modalTitle.textContent = `Bulletin de l'élève ${eleve}`;
}
// Mettre uniquement les appréciations dans le body
let message = '';
if (Array.isArray(data.appreciations) && data.appreciations.length > 0) {
message += data.appreciations.map(app => `<div style='margin-bottom:8px;'><strong>${app.matiere} :</strong><br>${app.appreciation}</div>`).join('');
} else {
message += '<em>Aucune appréciation trouvée dans le bulletin.</em>';
}
showBulletinModal(message);
})
.catch(() => {
const modalTitle = document.getElementById('bulletinModalLabel');
if (modalTitle) {
modalTitle.textContent = `Bulletin`;
}
showBulletinModal('<em>Erreur lors de la récupération du bulletin.</em>');
});
});
});
setButtonState('lancer');
updateActionButtons();
});
</script>
});
</script>
<script>
// CDN jsPDF + autoTable pour export PDF
document.addEventListener('DOMContentLoaded', function() {
// CDN jsPDF + autoTable pour export PDF
document.addEventListener('DOMContentLoaded', function() {
if (!window.jspdfLoaded) {
const script1 = document.createElement('script');
script1.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js';
@ -300,9 +378,9 @@ document.addEventListener('DOMContentLoaded', function() { @@ -300,9 +378,9 @@ document.addEventListener('DOMContentLoaded', function() {
};
document.body.appendChild(script1);
}
});
});
function exportTableToPDF() {
function exportTableToPDF() {
const doc = new window.jspdf.jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
doc.text('Tableau des appréciations', 40, 40);
// Couleurs fixes mode clair
@ -333,8 +411,30 @@ function exportTableToPDF() { @@ -333,8 +411,30 @@ function exportTableToPDF() {
pageBreak: 'auto',
});
doc.save('appreciations.pdf');
}
</script>
}
</script>
<script>
function showBulletinModal(html) {
const modalBody = document.getElementById('bulletinModalBody');
if (modalBody) {
modalBody.innerHTML = html;
const modal = new bootstrap.Modal(document.getElementById('bulletinModal'));
modal.show();
}
}
</script>
<!-- Modal Bulletin -->
<div class="modal fade" id="bulletinModal" tabindex="-1" aria-labelledby="bulletinModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" style="max-width:80vw; width:80vw;">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="bulletinModalLabel">Bulletin</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fermer"></button>
</div>
<div class="modal-body" id="bulletinModalBody" style="font-size:1.1rem; line-height:1.5; word-break:break-word;"></div>
</div>
</div>
</div>
</div>
</div>
</div>

3
main/urls.py

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
from django.urls import path
from .views import login_view, generation, resultat_appreciations, logout_view, generer_appreciation_ajax
from .views import login_view, generation, resultat_appreciations, logout_view, generer_appreciation_ajax, get_bulletin_eleve
urlpatterns = [
path('login/', login_view, name='login'),
@ -7,4 +7,5 @@ urlpatterns = [ @@ -7,4 +7,5 @@ urlpatterns = [
path('resultat/', resultat_appreciations, name='resultat_appreciations'),
path('logout/', logout_view, name='logout'),
path('generer_appreciation_ajax/', generer_appreciation_ajax, name='generer_appreciation_ajax'),
path('get_bulletin_eleve/', get_bulletin_eleve, name='get_bulletin_eleve'),
]

20
main/views.py

@ -10,6 +10,7 @@ from main.models import UserCredit, Modele @@ -10,6 +10,7 @@ from main.models import UserCredit, Modele
import os
import uuid
import json
from django.views.decorators.csrf import csrf_exempt
def login_view(request):
if request.method == 'POST':
@ -76,6 +77,25 @@ def generer_appreciation_ajax(request): @@ -76,6 +77,25 @@ def generer_appreciation_ajax(request):
return JsonResponse({'appreciation': 'Crédit épuisé', 'credit': 0, 'stop': True})
return JsonResponse({'error': 'Méthode non autorisée'}, status=405)
@login_required(login_url='/login/')
def get_bulletin_eleve(request):
if request.method == 'POST':
data = json.loads(request.body)
eleve_nom = data.get('eleve')
appreciations_json = request.session.get('appreciations_json', [])
appreciations = []
for eleve in appreciations_json:
if eleve.get('eleve') == eleve_nom:
appreciations = eleve.get('appreciations', [])
if isinstance(appreciations, str):
try:
appreciations = json.loads(appreciations)
except Exception:
appreciations = []
break
return JsonResponse({'appreciations': appreciations})
return JsonResponse({'error': 'Méthode non autorisée'}, status=405)
def logout_view(request):
logout(request)
return redirect('login')

Loading…
Cancel
Save