mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-23 19:06:37 +02:00
Wrapped apps
This commit is contained in:
0
apps/wrapped/api/__init__.py
Normal file
0
apps/wrapped/api/__init__.py
Normal file
28
apps/wrapped/api/serializers.py
Normal file
28
apps/wrapped/api/serializers.py
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
from ..models import Wrapped, Bde
|
||||
|
||||
|
||||
class WrappedSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
REST API Serializer for Wrapped.
|
||||
The djangorestframework plugin will analyse the model `Wrapped` and parse all fields in the API.
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Wrapped
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class BdeSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
REST API Serializer for Bde.
|
||||
The djangorestframework plugin will analyse the model `Bde` and parse all fields in the API.
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Bde
|
||||
fields = '__all__'
|
11
apps/wrapped/api/urls.py
Normal file
11
apps/wrapped/api/urls.py
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from .views import WrappedViewSet, BdeViewSet
|
||||
|
||||
def register_wrapped_urls(router, path):
|
||||
"""
|
||||
Configure router for Wrapped REST API.
|
||||
"""
|
||||
router.register(path + '/wrapped', WrappedViewSet)
|
||||
router.register(path + '/bde', BdeViewSet)
|
33
apps/wrapped/api/views.py
Normal file
33
apps/wrapped/api/views.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from api.viewsets import ReadProtectedModelViewSet
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework.filters import SearchFilter
|
||||
|
||||
from .serializers import WrappedSerializer, BdeSerializer
|
||||
from ..models import Wrapped, Bde
|
||||
|
||||
class WrappedViewSet(ReadProtectedModelViewSet):
|
||||
"""
|
||||
REST API View set.
|
||||
The djangorestframework plugin will get all `Wrapped` objects, serialize it to JSON with the given
|
||||
serializer, then render it on /api/wrapped/wrapped/
|
||||
"""
|
||||
queryset = Wrapped.objects.order_by('id')
|
||||
serializer_class = WrappedSerializer
|
||||
filter_backends = [DjangoFilterBackend, SearchFilter]
|
||||
filterset_fields = ['note', 'bde', ]
|
||||
search_fields = ['$note', ]
|
||||
|
||||
class BdeViewSet(ReadProtectedModelViewSet):
|
||||
"""
|
||||
REST API View set.
|
||||
The djangorestframework plugin will get all `Bde` objects, serialize it to JSON with the given
|
||||
serializer, then render it on /api/wrapped/bde/
|
||||
"""
|
||||
queryset = Bde.objects.order_by('id')
|
||||
serializer_class = BdeSerializer
|
||||
filter_backends = [DjangoFilterBackend, SearchFilter]
|
||||
filterset_fields = ['name', ]
|
||||
search_fields = ['$name', ]
|
Reference in New Issue
Block a user