From 9ff449e662e6238afda12453617018de494ffe5d Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Tue, 18 Apr 2023 10:20:09 +0200 Subject: [PATCH] WIP: start working on #25 --- apis_bibsonomy/api_views.py | 15 +++++++++++++++ apis_bibsonomy/serializers.py | 7 +++++++ apis_bibsonomy/urls.py | 8 ++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 apis_bibsonomy/serializers.py diff --git a/apis_bibsonomy/api_views.py b/apis_bibsonomy/api_views.py index 16bca63..de5ce0c 100644 --- a/apis_bibsonomy/api_views.py +++ b/apis_bibsonomy/api_views.py @@ -8,9 +8,24 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView +from rest_framework import viewsets from .models import Reference from .utils import BibsonomyEntry +from .serializers import ReferenceSerializer + +class ReferencesViewSet(viewsets.ReadOnlyModelViewSet): + """ + API endpoint that allows references to be viewed. + """ + queryset = Reference.objects.all() + serializer_class = ReferenceSerializer + permission_classes = [IsAuthenticated] + + def get_queryset(self): + ct = self.kwargs['ct'] + pk = self.kwargs['pk'] + return Reference.objects.filter(content_type = ct, object_id = pk) class SaveBibsonomyEntry(APIView): diff --git a/apis_bibsonomy/serializers.py b/apis_bibsonomy/serializers.py new file mode 100644 index 0000000..d6d17fb --- /dev/null +++ b/apis_bibsonomy/serializers.py @@ -0,0 +1,7 @@ +from .models import Reference +from rest_framework import serializers + + +class ReferenceSerializer(serializers.ModelSerializer): + class Meta: + model = Reference diff --git a/apis_bibsonomy/urls.py b/apis_bibsonomy/urls.py index 38bc236..0972021 100644 --- a/apis_bibsonomy/urls.py +++ b/apis_bibsonomy/urls.py @@ -1,11 +1,15 @@ +from rest_framework.routers import DefaultRouter from django.urls import path from . import api_views from . import autocompletes app_name = 'apis_bibsonomy' +router = DefaultRouter() +router.register(r'references', api_views.ReferencesViewSet, basename='references') + urlpatterns = [ path('save_get/', api_views.SaveBibsonomyEntry.as_view(), name='savegetbibsonomyentry'), - path('autocomplete/', autocompletes.BibsonomyAutocomplete.as_view(), name='bibsonomyautocomplete') + path('autocomplete/', autocompletes.BibsonomyAutocomplete.as_view(), name='bibsonomyautocomplete'), ] - +urlpatterns.append(router.urls)