Commit 35b4d517 authored by Hamza Dely's avatar Hamza Dely
Browse files

[comptes/serializers] Fusionne AdherentListSerializer et AdherentSerializer

parent d05a0da8
......@@ -171,18 +171,6 @@ class AdherentCreationSerializer(serializers.ModelSerializer):
)
return adh
class AdherentListSerializer(serializers.ModelSerializer):
"""
Sérialiseur pour le modèle Adhérent.
Permet de lister les différentes instances
"""
aliases = AliasSerializer(many=True, read_only=True)
adhesion = AdhesionSerializer(source='last_adhesion', read_only=True)
class Meta:
model = Adherent
fields = ['id', 'pseudo', 'nom', 'prenom', 'type', 'aliases', 'adhesion']
read_only_fields = fields
class AdherentSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
"""
Sérialiseur pour le modèle Adhérent
......@@ -190,7 +178,13 @@ class AdherentSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
accreditations = AccreditationSerializer(many=True, read_only=True, fields=['droit', 'meta'])
aliases = AliasSerializer(many=True, read_only=True)
adhesions = AdhesionSerializer(many=True, read_only=True)
last_adhesion = AdhesionSerializer(read_only=True)
class Meta:
model = Adherent
fields = Adherent.CHAMPS_VISIBLES[Acl.TOTAL]
fields = [
'id', 'pseudo', 'nom', 'prenom', 'email', 'sexe',
'type', 'telephone', 'adresse', 'remunere', 'pbsante', 'remarque',
'supprime', 'is_staff', 'is_active', 'aliases', 'adhesions', 'last_adhesion',
'accreditations',
]
read_only_fields = ['id']
......@@ -100,7 +100,7 @@ var adherent_result_generator = [
(result) => result.pseudo,
(result) => result.type.capitalize(),
(result) => extractFromDictList(result.aliases, 'alias').remove(result.pseudo).join(', '),
(result) => extractFromDictList(extractFromDictList([result.adhesion], 'section'), 'nom').join(', '),
(result) => extractFromDictList(extractFromDictList([result.last_adhesion], 'section'), 'nom').join(', '),
];
function adherentLookup(event) {
......
......@@ -46,7 +46,7 @@ from comptes.forms import (
)
from comptes.filters import AdherentRechercheFilter
from comptes.serializers import (
AdherentCreationSerializer, AdherentListSerializer, AdherentSerializer, AliasSerializer,
AdherentCreationSerializer, AdherentSerializer, AliasSerializer,
AccreditationSerializer,
)
......@@ -489,6 +489,7 @@ class AdherentViewSet(viewsets.GenericViewSet):
La liste des paramètres utilisables est disponible avec une requête OPTIONS.
"""
user = request.user
fields = ['id', 'pseudo', 'nom', 'prenom', 'type', 'aliases', 'last_adhesion']
if not user.has_perm("comptes.adherent_chercher", Acl.BASIQUE):
raise PermissionDenied
......@@ -601,7 +602,9 @@ class AdherentViewSet(viewsets.GenericViewSet):
)
try:
if qs.exists():
return Response(AdherentListSerializer(qs, many=True).data)
return Response(
self.get_serializer(qs, many=True, read_only=True, fields=fields).data
)
else:
return Response(
{'detail' : 'Aucun résultat'},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment