From f54e2ed14553bee6fe9f9d40e72fa860e562f8c3 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 8 Feb 2020 15:08:55 +0100 Subject: [PATCH] Aliases were missing --- apps/api/note/serializers.py | 13 ++++++++++++- apps/api/note/urls.py | 5 +++-- apps/api/note/views.py | 14 ++++++++++++-- apps/api/urls.py | 6 ++++-- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/apps/api/note/serializers.py b/apps/api/note/serializers.py index ddb800fa..34a1f368 100644 --- a/apps/api/note/serializers.py +++ b/apps/api/note/serializers.py @@ -2,7 +2,7 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from note.models.notes import Note, NoteClub, NoteSpecial, NoteUser +from note.models.notes import Note, NoteClub, NoteSpecial, NoteUser, Alias from note.models.transactions import TransactionTemplate, Transaction, MembershipTransaction from rest_framework import serializers from rest_polymorphic.serializers import PolymorphicSerializer @@ -50,6 +50,17 @@ class NoteUserSerializer(serializers.ModelSerializer): model = NoteUser fields = '__all__' + +class AliasSerializer(serializers.ModelSerializer): + """ + REST API Serializer for Aliases. + The djangorestframework plugin will analyse the model `Alias` and parse all fields in the API. + """ + class Meta: + model = Alias + fields = '__all__' + + class NotePolymorphicSerializer(PolymorphicSerializer): model_serializer_mapping = { Note: NoteSerializer, diff --git a/apps/api/note/urls.py b/apps/api/note/urls.py index 2bc56aa6..0c25785d 100644 --- a/apps/api/note/urls.py +++ b/apps/api/note/urls.py @@ -2,7 +2,7 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from .views import NoteViewSet, NotePolymorphicViewSet, NoteClubViewSet, NoteUserViewSet, NoteSpecialViewSet, \ +from .views import NoteViewSet, NotePolymorphicViewSet, NoteClubViewSet, NoteUserViewSet, NoteSpecialViewSet, AliasViewSet, \ TransactionViewSet, TransactionTemplateViewSet, MembershipTransactionViewSet @@ -10,7 +10,8 @@ def register_note_urls(router, path): """ Configure router for Note REST API. """ - router.register(path + '', NotePolymorphicViewSet) + router.register(path + '/note', NotePolymorphicViewSet) + router.register(path + '/alias', AliasViewSet) router.register(path + '/transaction/transaction', TransactionViewSet) router.register(path + '/transaction/template', TransactionTemplateViewSet) diff --git a/apps/api/note/views.py b/apps/api/note/views.py index 90a7dd29..c6aa7689 100644 --- a/apps/api/note/views.py +++ b/apps/api/note/views.py @@ -2,9 +2,9 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from note.models.notes import Note, NoteClub, NoteSpecial, NoteUser +from note.models.notes import Note, NoteClub, NoteSpecial, NoteUser, Alias from note.models.transactions import TransactionTemplate, Transaction, MembershipTransaction -from .serializers import NoteSerializer, NotePolymorphicSerializer, NoteClubSerializer, NoteSpecialSerializer, NoteUserSerializer, \ +from .serializers import NoteSerializer, NotePolymorphicSerializer, NoteClubSerializer, NoteSpecialSerializer, NoteUserSerializer, AliasSerializer, \ TransactionTemplateSerializer, TransactionSerializer, MembershipTransactionSerializer from rest_framework import viewsets @@ -59,6 +59,16 @@ class NotePolymorphicViewSet(viewsets.ModelViewSet): serializer_class = NotePolymorphicSerializer +class AliasViewSet(viewsets.ModelViewSet): + """ + REST API View set. + The djangorestframework plugin will get all `Alias` objects, serialize it to JSON with the given serializer, + then render it on /api/aliases/ + """ + queryset = Alias.objects.all() + serializer_class = AliasSerializer + + class TransactionTemplateViewSet(viewsets.ModelViewSet): """ REST API View set. diff --git a/apps/api/urls.py b/apps/api/urls.py index 03db1382..3c5f6c78 100644 --- a/apps/api/urls.py +++ b/apps/api/urls.py @@ -5,6 +5,8 @@ from django.conf.urls import url, include from django.contrib.auth.models import User from rest_framework import routers, serializers, viewsets + +from note.models import Alias from .activity.urls import register_activity_urls from .members.urls import register_members_urls from .note.urls import register_note_urls @@ -16,7 +18,7 @@ class UserSerializer(serializers.ModelSerializer): """ class Meta: model = User - fields = ('username', 'first_name', 'last_name', 'email', 'is_staff',) + fields = '__all__' class UserViewSet(viewsets.ModelViewSet): """ @@ -29,7 +31,7 @@ class UserViewSet(viewsets.ModelViewSet): # Routers provide an easy way of automatically determining the URL conf. router = routers.DefaultRouter() -router.register(r'users', UserViewSet) +router.register('user', UserViewSet) # Routers for members app register_members_urls(router, r'members')