From e57b0c1702c8cfc1c7ce1ce94924e58b5d16d51c Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Tue, 13 Jul 2021 16:20:01 +0200 Subject: [PATCH] Add preliminary DRF viewset for SemanticQuery model (#486) --- backend/items/views.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/items/views.py b/backend/items/views.py index 2bc8dede..39ac4fba 100644 --- a/backend/items/views.py +++ b/backend/items/views.py @@ -9,6 +9,8 @@ from rest_framework.response import Response from rest_framework.status import * from rest_framework.exceptions import ValidationError, NotFound, PermissionDenied +from rest_framework.viewsets import GenericViewSet +from rest_framework.mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin from rdflib import Graph, URIRef, BNode, Literal from rdflib.query import ResultException @@ -24,8 +26,9 @@ from sources import namespace as source from . import namespace as my from .graph import graph, history -from .models import ItemCounter, EditCounter +from .models import ItemCounter, EditCounter, SemanticQuery from .permissions import * +from .serializers import SemanticQuerySerializer MUST_SINGLE_BLANK_400 = 'POST requires exactly one subject which must be a blank node.' MUST_EQUAL_IDENTIFIER_400 = 'PUT must affect exactly the resource URI.' @@ -304,3 +307,11 @@ def get_graph(self, request, category, **kwargs): break [user_items.add(triple) for triple in items.triples((s, None, None))] return user_items + + +class SemanticQueryViewSet( + CreateModelMixin, ListModelMixin, RetrieveModelMixin, + GenericViewSet, +): + queryset = SemanticQuery.objects.all() + serializer_class = SemanticQuerySerializer