From c68e36edd0d2440d6b55b9bcba289db948960b4d 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 | 20 +++++++++++++++++++ apis_bibsonomy/serializers.py | 12 +++++++++++ .../apis_bibsonomy/reference_list.html | 11 ++++++++++ apis_bibsonomy/templates/base.html | 9 +++++++++ apis_bibsonomy/urls.py | 7 ++++--- apis_bibsonomy/views.py | 13 ++++++++++++ 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 apis_bibsonomy/serializers.py create mode 100644 apis_bibsonomy/templates/apis_bibsonomy/reference_list.html create mode 100644 apis_bibsonomy/templates/base.html create mode 100644 apis_bibsonomy/views.py diff --git a/apis_bibsonomy/api_views.py b/apis_bibsonomy/api_views.py index 16bca63..2b4cbc0 100644 --- a/apis_bibsonomy/api_views.py +++ b/apis_bibsonomy/api_views.py @@ -8,9 +8,29 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView +from rest_framework import viewsets, generics from .models import Reference from .utils import BibsonomyEntry +from .serializers import ReferenceSerializer, ReferenceQuerySerializer + +class ReferenceList(APIView): + """ + API endpoint that allows references to be viewed. + """ + authentication_classes = [] + permission_classes = [] + + def post(self, request, format=None): + serializer = ReferenceQuerySerializer(data=request.data, many=True) + references = [] + if serializer.is_valid(): + for item in serializer.validated_data: + print(item) + references.extend(list(Reference.objects.filter(**item))) + print(references) + reference_data = ReferenceSerializer(references, many=True).data + return Response(reference_data) class SaveBibsonomyEntry(APIView): diff --git a/apis_bibsonomy/serializers.py b/apis_bibsonomy/serializers.py new file mode 100644 index 0000000..86a91d3 --- /dev/null +++ b/apis_bibsonomy/serializers.py @@ -0,0 +1,12 @@ +from .models import Reference +from rest_framework import serializers + + +class ReferenceSerializer(serializers.ModelSerializer): + class Meta: + model = Reference + fields = '__all__' + +class ReferenceQuerySerializer(serializers.Serializer): + content_type_id = serializers.IntegerField() + object_id = serializers.IntegerField() diff --git a/apis_bibsonomy/templates/apis_bibsonomy/reference_list.html b/apis_bibsonomy/templates/apis_bibsonomy/reference_list.html new file mode 100644 index 0000000..6280cfc --- /dev/null +++ b/apis_bibsonomy/templates/apis_bibsonomy/reference_list.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} + +{% block content %} + +{% endblock content %} diff --git a/apis_bibsonomy/templates/base.html b/apis_bibsonomy/templates/base.html new file mode 100644 index 0000000..c8e90d9 --- /dev/null +++ b/apis_bibsonomy/templates/base.html @@ -0,0 +1,9 @@ + + + + Bibsonomy + + + {% block content %}{% endblock content %} + + diff --git a/apis_bibsonomy/urls.py b/apis_bibsonomy/urls.py index 38bc236..7558ed6 100644 --- a/apis_bibsonomy/urls.py +++ b/apis_bibsonomy/urls.py @@ -1,11 +1,12 @@ +from rest_framework.routers import DefaultRouter from django.urls import path -from . import api_views +from . import api_views, views from . import autocompletes app_name = 'apis_bibsonomy' 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'), + path('references//', views.ReferenceListView.as_view(), name='referenceslist'), ] - diff --git a/apis_bibsonomy/views.py b/apis_bibsonomy/views.py new file mode 100644 index 0000000..ebb4e5a --- /dev/null +++ b/apis_bibsonomy/views.py @@ -0,0 +1,13 @@ +from django.views.generic.list import ListView + +from .models import Reference + + +class ReferenceListView(ListView): + def get_queryset(self): + object_id = self.request.GET.get('object_id') + content_type_id = self.request.GET.get('content_type_id') + print(object_id, content_type_id) + refs = Reference.objects.filter(object_id=object_id, content_type__id = content_type_id) + print(refs) + return refs