diff --git a/main/templates/resultat_appreciations.html b/main/templates/resultat_appreciations.html index 08b9a8f..b5e442a 100644 --- a/main/templates/resultat_appreciations.html +++ b/main/templates/resultat_appreciations.html @@ -7,69 +7,87 @@ @@ -108,7 +126,7 @@ body, .bg-light {
- +
diff --git a/main/urls.py b/main/urls.py index a838c73..c700fc7 100644 --- a/main/urls.py +++ b/main/urls.py @@ -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 = [ 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'), ] \ No newline at end of file diff --git a/main/views.py b/main/views.py index c83ffd9..c429da7 100644 --- a/main/views.py +++ b/main/views.py @@ -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): 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')