mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Gestion de la création d'un nouveau guardian, de l'association
avec un guardian dumême établissement, et de l'association avec un guardian d'un autre établissement
This commit is contained in:
@ -16,7 +16,24 @@ class ProfileSerializer(serializers.ModelSerializer):
|
||||
|
||||
def get_roles(self, obj):
|
||||
roles = ProfileRole.objects.filter(profile=obj)
|
||||
return [{'role_type': role.role_type, 'establishment': role.establishment.id, 'establishment_name': role.establishment.name, 'is_active': role.is_active} for role in roles]
|
||||
roles_data = []
|
||||
for role in roles:
|
||||
# Récupérer l'ID de l'associated_person en fonction du type de rôle
|
||||
if role.role_type == ProfileRole.RoleType.PROFIL_PARENT:
|
||||
guardian = Guardian.objects.filter(profile_role=role).first()
|
||||
id_associated_person = guardian.id if guardian else None
|
||||
else:
|
||||
teacher = Teacher.objects.filter(profile_role=role).first()
|
||||
id_associated_person = teacher.id if teacher else None
|
||||
|
||||
roles_data.append({
|
||||
'id_associated_person': id_associated_person,
|
||||
'role_type': role.role_type,
|
||||
'establishment': role.establishment.id,
|
||||
'establishment_name': role.establishment.name,
|
||||
'is_active': role.is_active,
|
||||
})
|
||||
return roles_data
|
||||
|
||||
def create(self, validated_data):
|
||||
user = Profile(
|
||||
@ -107,6 +124,7 @@ class ProfileRoleSerializer(serializers.ModelSerializer):
|
||||
"registration_status": registration_status
|
||||
})
|
||||
return {
|
||||
"id": guardian.id,
|
||||
"guardian_name": f"{guardian.last_name} {guardian.first_name}",
|
||||
"students": students_list
|
||||
}
|
||||
@ -118,6 +136,7 @@ class ProfileRoleSerializer(serializers.ModelSerializer):
|
||||
specialities = teacher.specialities.all()
|
||||
specialities_list = [{"name": speciality.name, "color_code": speciality.color_code} for speciality in specialities]
|
||||
return {
|
||||
"id": teacher.id,
|
||||
"teacher_name": f"{teacher.last_name} {teacher.first_name}",
|
||||
"classes": classes_list,
|
||||
"specialities": specialities_list
|
||||
|
||||
@ -4,7 +4,6 @@ from django.http.response import JsonResponse
|
||||
from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt, csrf_protect
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.cache import cache
|
||||
from django.middleware.csrf import get_token
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.parsers import JSONParser
|
||||
@ -24,7 +23,6 @@ from rest_framework.decorators import action, api_view
|
||||
|
||||
from Auth.serializers import ProfileSerializer, ProfileRoleSerializer
|
||||
from Subscriptions.models import RegistrationForm
|
||||
from Subscriptions.signals import clear_cache
|
||||
import Subscriptions.mailManager as mailer
|
||||
import Subscriptions.util as util
|
||||
import logging
|
||||
@ -204,7 +202,6 @@ class LoginView(APIView):
|
||||
|
||||
login(request, user)
|
||||
user.save()
|
||||
clear_cache()
|
||||
retour = ''
|
||||
|
||||
# Récupérer tous les rôles de l'utilisateur avec le type spécifié
|
||||
@ -423,7 +420,6 @@ class SubscribeView(APIView):
|
||||
else:
|
||||
return JsonResponse(role_serializer.errors, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
clear_cache()
|
||||
retour = error.returnMessage[error.MESSAGE_ACTIVATION_PROFILE]
|
||||
retourErreur = ''
|
||||
return JsonResponse({'message': retour, 'errorMessage': retourErreur, "errorFields": errorFields, "id": profil.id}, safe=False)
|
||||
@ -473,7 +469,6 @@ class NewPasswordView(APIView):
|
||||
profil.code = util.genereRandomCode(12)
|
||||
profil.datePeremption = util.calculeDatePeremption(util._now(), settings.EXPIRATION_URL_NB_DAYS)
|
||||
profil.save()
|
||||
clear_cache()
|
||||
retourErreur = ''
|
||||
retour = error.returnMessage[error.MESSAGE_REINIT_PASSWORD] % (newProfilConnection.get('email'))
|
||||
mailer.envoieReinitMotDePasse(newProfilConnection.get('email'), profil.code)
|
||||
@ -527,7 +522,6 @@ class ResetPasswordView(APIView):
|
||||
profil.code = ''
|
||||
profil.datePeremption = ''
|
||||
profil.save()
|
||||
clear_cache()
|
||||
retourErreur = ''
|
||||
|
||||
return JsonResponse({'message': retour, "errorMessage": retourErreur, "errorFields": errorFields}, safe=False)
|
||||
|
||||
@ -5,6 +5,3 @@ class GestioninscriptionsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'Subscriptions'
|
||||
|
||||
def ready(self):
|
||||
from Subscriptions.signals import clear_cache
|
||||
clear_cache()
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
# state_machine.py
|
||||
import json
|
||||
from Subscriptions.models import RegistrationForm
|
||||
from Subscriptions.signals import clear_cache
|
||||
|
||||
state_mapping = {
|
||||
"ABSENT": RegistrationForm.RegistrationFormStatus.RF_ABSENT,
|
||||
@ -31,7 +30,6 @@ def updateStateMachine(rf, transition) :
|
||||
if state_machine.trigger(transition, automateModel):
|
||||
rf.status = state_machine.state
|
||||
rf.save()
|
||||
clear_cache()
|
||||
|
||||
class Automate_RF_Register:
|
||||
def __init__(self, initial_state):
|
||||
|
||||
@ -110,6 +110,9 @@ class StudentSerializer(serializers.ModelSerializer):
|
||||
profile_role = guardian_data.pop('profile_role', None)
|
||||
|
||||
if profile_role_data:
|
||||
# Vérifiez si 'profile' est un objet ou une clé primaire
|
||||
if isinstance(profile_role_data.get('profile'), Profile):
|
||||
profile_role_data['profile'] = profile_role_data['profile'].id
|
||||
establishment_id = profile_role_data.pop('establishment').id
|
||||
profile_role_data['establishment'] = establishment_id
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
from django.db.models.signals import post_save, post_delete, m2m_changed
|
||||
from django.dispatch import receiver
|
||||
from django.core.cache import cache
|
||||
from .models import RegistrationForm, Student, Guardian
|
||||
from Auth.models import Profile
|
||||
from N3wtSchool import settings
|
||||
@ -8,23 +7,6 @@ from N3wtSchool.redis_client import redis_client
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def clear_cache():
|
||||
# Préfixes des clés à supprimer
|
||||
prefixes = ['N3WT_']
|
||||
|
||||
for prefix in prefixes:
|
||||
# Utiliser le motif pour obtenir les clés correspondant au préfixe
|
||||
pattern = f'*{prefix}*'
|
||||
logger.debug(f'pattern : {pattern}')
|
||||
for key in redis_client.scan_iter(pattern):
|
||||
redis_client.delete(key)
|
||||
logger.debug(f'deleting : {key}')
|
||||
|
||||
@receiver(post_save, sender=RegistrationForm)
|
||||
@receiver(post_delete, sender=RegistrationForm)
|
||||
def clear_cache_after_change(sender, instance, **kwargs):
|
||||
clear_cache()
|
||||
|
||||
@receiver(m2m_changed, sender=Student.guardians.through)
|
||||
def check_orphan_reponsables(sender, **kwargs):
|
||||
action = kwargs.pop('action', None)
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
from django.http.response import JsonResponse
|
||||
from django.views.decorators.csrf import ensure_csrf_cookie, csrf_protect
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.core.cache import cache
|
||||
from rest_framework.parsers import JSONParser
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.decorators import action, api_view
|
||||
@ -18,7 +17,6 @@ import Subscriptions.util as util
|
||||
|
||||
from Subscriptions.serializers import RegistrationFormSerializer
|
||||
from Subscriptions.pagination import CustomPagination
|
||||
from Subscriptions.signals import clear_cache
|
||||
from Subscriptions.models import Student, Guardian, RegistrationForm, RegistrationTemplate, RegistrationFileGroup
|
||||
from Subscriptions.automate import updateStateMachine
|
||||
|
||||
@ -88,13 +86,6 @@ class RegisterFormView(APIView):
|
||||
except ValueError:
|
||||
page_size = settings.NB_RESULT_PER_PAGE
|
||||
|
||||
# Définir le cache_key en fonction du filtre
|
||||
page_number = request.GET.get('page', 1)
|
||||
cache_key = f'N3WT_ficheInscriptions_{establishment_id}_{filter}_page_{page_number}_search_{search if filter == "pending" else ""}'
|
||||
cached_page = cache.get(cache_key)
|
||||
if cached_page:
|
||||
return JsonResponse(cached_page, safe=False)
|
||||
|
||||
# Récupérer les dossier d'inscriptions en fonction du filtre
|
||||
registerForms_List = None
|
||||
if filter == 'pending':
|
||||
@ -120,7 +111,6 @@ class RegisterFormView(APIView):
|
||||
if page is not None:
|
||||
registerForms_serializer = RegistrationFormSerializer(page, many=True)
|
||||
response_data = paginator.get_paginated_response(registerForms_serializer.data)
|
||||
cache.set(cache_key, response_data, timeout=60 * 15)
|
||||
return JsonResponse(response_data, safe=False)
|
||||
|
||||
return JsonResponse({'error': 'aucune donnée trouvée', 'count': 0}, safe=False)
|
||||
@ -308,7 +298,6 @@ class RegisterFormWithIdView(APIView):
|
||||
student.profiles.clear()
|
||||
student.registration_files.clear()
|
||||
student.delete()
|
||||
clear_cache()
|
||||
|
||||
return JsonResponse("La suppression du dossier a été effectuée avec succès", safe=False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user